summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/drive/file_cache.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/chromeos/drive/file_cache.cc')
-rw-r--r--chrome/browser/chromeos/drive/file_cache.cc114
1 files changed, 6 insertions, 108 deletions
diff --git a/chrome/browser/chromeos/drive/file_cache.cc b/chrome/browser/chromeos/drive/file_cache.cc
index 094ea78e..4541952 100644
--- a/chrome/browser/chromeos/drive/file_cache.cc
+++ b/chrome/browser/chromeos/drive/file_cache.cc
@@ -27,8 +27,6 @@ namespace internal {
namespace {
const base::FilePath::CharType kFileCacheMetaDir[] = FILE_PATH_LITERAL("meta");
-const base::FilePath::CharType kFileCacheOutgoingDir[] =
- FILE_PATH_LITERAL("outgoing");
const base::FilePath::CharType kFileCachePersistentDir[] =
FILE_PATH_LITERAL("persistent");
const base::FilePath::CharType kFileCacheTmpDir[] = FILE_PATH_LITERAL("tmp");
@@ -75,29 +73,6 @@ void RemoveAllFiles(const base::FilePath& directory) {
}
}
-// Deletes the symlink.
-void DeleteSymlink(const base::FilePath& symlink_path) {
- // We try to save one file operation by not checking if link exists before
- // deleting it, so unlink may return error if link doesn't exist, but it
- // doesn't really matter to us.
- file_util::Delete(symlink_path, false);
-}
-
-// Creates a symlink.
-bool CreateSymlink(const base::FilePath& cache_file_path,
- const base::FilePath& symlink_path) {
- // Remove symlink because creating a link will not overwrite an existing one.
- DeleteSymlink(symlink_path);
-
- // Create new symlink to |cache_file_path|.
- if (!file_util::CreateSymbolicLink(cache_file_path, symlink_path)) {
- LOG(ERROR) << "Failed to create a symlink from " << symlink_path.value()
- << " to " << cache_file_path.value();
- return false;
- }
- return true;
-}
-
// Moves the file.
bool MoveFile(const base::FilePath& source_path,
const base::FilePath& dest_path) {
@@ -435,13 +410,13 @@ void FileCache::CommitDirtyOnUIThread(const std::string& resource_id,
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
- base::PostTaskAndReplyWithResult(
- blocking_task_runner_,
+ // TODO(hashimoto): Move logic around OnCommitDirty to FileSystem and remove
+ // this method.
+ base::MessageLoopProxy::current()->PostTask(
FROM_HERE,
- base::Bind(&FileCache::CommitDirty,
- base::Unretained(this), resource_id, md5),
base::Bind(&FileCache::OnCommitDirty,
- weak_ptr_factory_.GetWeakPtr(), resource_id, callback));
+ weak_ptr_factory_.GetWeakPtr(), resource_id, callback,
+ FILE_ERROR_OK));
}
void FileCache::ClearDirtyOnUIThread(const std::string& resource_id,
@@ -677,10 +652,6 @@ FileError FileCache::Store(const std::string& resource_id,
cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
cache_entry.set_is_dirty(origin == CACHED_FILE_LOCALLY_MODIFIED);
metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry);
-
- // If storing a local modification, commit it.
- if (origin == CACHED_FILE_LOCALLY_MODIFIED)
- CommitDirty(resource_id, md5);
}
return success ? FILE_ERROR_OK : FILE_ERROR_FAILED;
@@ -899,23 +870,9 @@ FileError FileCache::MarkDirty(const std::string& resource_id,
return FILE_ERROR_NOT_FOUND;
}
- // If a file is already dirty (i.e. MarkDirtyInCache was called before),
- // delete outgoing symlink if it exists.
- // TODO(benchan): We should only delete outgoing symlink if file is currently
- // not being uploaded. However, for now, cache doesn't know if uploading of a
- // file is in progress. Per zel, the upload process should be canceled before
- // MarkDirtyInCache is called again.
if (cache_entry.is_dirty()) {
// The file must be in persistent dir.
DCHECK(cache_entry.is_persistent());
-
- // Determine symlink path in outgoing dir, so as to remove it.
- base::FilePath symlink_path = GetCacheFilePath(resource_id,
- std::string(),
- CACHE_TYPE_OUTGOING,
- CACHED_FILE_FROM_SERVER);
- DeleteSymlink(symlink_path);
-
return FILE_ERROR_OK;
}
@@ -946,55 +903,6 @@ FileError FileCache::MarkDirty(const std::string& resource_id,
return FILE_ERROR_OK;
}
-FileError FileCache::CommitDirty(const std::string& resource_id,
- const std::string& md5) {
- AssertOnSequencedWorkerPool();
-
- // If file has already been marked dirty in previous instance of chrome, we
- // would have lost the md5 info during cache initialization, because the file
- // would have been renamed to .local extension.
- // So, search for entry in cache without comparing md5.
-
- // Committing a file dirty means its entry and actual file blob must exist in
- // cache.
- FileCacheEntry cache_entry;
- if (!GetCacheEntry(resource_id, std::string(), &cache_entry) ||
- !cache_entry.is_present()) {
- LOG(WARNING) << "Can't commit dirty a file that wasn't cached: res_id="
- << resource_id
- << ", md5=" << md5;
- return FILE_ERROR_NOT_FOUND;
- }
-
- // If a file is not dirty (it should have been marked dirty via
- // MarkDirtyInCache), committing it dirty is an invalid operation.
- if (!cache_entry.is_dirty()) {
- LOG(WARNING) << "Can't commit a non-dirty file: res_id="
- << resource_id
- << ", md5=" << md5;
- return FILE_ERROR_INVALID_OPERATION;
- }
-
- // Dirty files must be in persistent dir.
- DCHECK(cache_entry.is_persistent());
-
- // Create symlink in outgoing dir.
- base::FilePath symlink_path = GetCacheFilePath(resource_id,
- std::string(),
- CACHE_TYPE_OUTGOING,
- CACHED_FILE_FROM_SERVER);
-
- // Get target path of symlink i.e. current path of the file in cache.
- base::FilePath target_path = GetCacheFilePath(
- resource_id,
- md5,
- GetSubDirectoryType(cache_entry),
- CACHED_FILE_LOCALLY_MODIFIED);
-
- return CreateSymlink(target_path, symlink_path) ?
- FILE_ERROR_OK : FILE_ERROR_FAILED;
-}
-
FileError FileCache::ClearDirty(const std::string& resource_id,
const std::string& md5) {
AssertOnSequencedWorkerPool();
@@ -1045,13 +953,6 @@ FileError FileCache::ClearDirty(const std::string& resource_id,
if (!MoveFile(source_path, dest_path))
return FILE_ERROR_FAILED;
- // Delete symlink in outgoing dir.
- base::FilePath symlink_path = GetCacheFilePath(resource_id,
- std::string(),
- CACHE_TYPE_OUTGOING,
- CACHED_FILE_FROM_SERVER);
- DeleteSymlink(symlink_path);
-
// Now that file operations have completed, update metadata.
cache_entry.set_md5(md5);
cache_entry.set_is_dirty(false);
@@ -1095,9 +996,7 @@ FileError FileCache::Remove(const std::string& resource_id) {
CACHE_TYPE_TMP,
CACHED_FILE_FROM_SERVER));
- // Don't delete locally modified (i.e. dirty and possibly outgoing) files.
- // Since we're not deleting outgoing symlinks, we don't need to append
- // outgoing path to |paths_to_delete|.
+ // Don't delete locally modified files.
base::FilePath path_to_keep = GetCacheFilePath(resource_id,
std::string(),
CACHE_TYPE_PERSISTENT,
@@ -1199,7 +1098,6 @@ std::vector<base::FilePath> FileCache::GetCachePaths(
std::vector<base::FilePath> cache_paths;
// The order should match FileCache::CacheSubDirectoryType enum.
cache_paths.push_back(cache_root_path.Append(kFileCacheMetaDir));
- cache_paths.push_back(cache_root_path.Append(kFileCacheOutgoingDir));
cache_paths.push_back(cache_root_path.Append(kFileCachePersistentDir));
cache_paths.push_back(cache_root_path.Append(kFileCacheTmpDir));
cache_paths.push_back(cache_root_path.Append(kFileCacheTmpDownloadsDir));