Chromium Code Reviews| Index: chrome/browser/chromeos/gdata/gdata_file_system.cc |
| diff --git a/chrome/browser/chromeos/gdata/gdata_file_system.cc b/chrome/browser/chromeos/gdata/gdata_file_system.cc |
| index 95d8d15263c3e6253165bf3c07dfb90d1b857f8a..69dd579589f3ce702aee7106b150538796220ebb 100644 |
| --- a/chrome/browser/chromeos/gdata/gdata_file_system.cc |
| +++ b/chrome/browser/chromeos/gdata/gdata_file_system.cc |
| @@ -54,6 +54,7 @@ const FilePath::CharType kGDataRootDirectory[] = FILE_PATH_LITERAL("gdata"); |
| const char kFeedField[] = "feed"; |
| const char kWildCard[] = "*"; |
| const char kLocallyModifiedFileExtension[] = "local"; |
| +const char kMountedArchiveFileExtension[] = "mounted"; |
| const FilePath::CharType kGDataCacheVersionDir[] = FILE_PATH_LITERAL("v1"); |
| const FilePath::CharType kGDataCacheMetaDir[] = FILE_PATH_LITERAL("meta"); |
| @@ -1865,6 +1866,10 @@ bool GDataFileSystem::GetFileInfoFromPath( |
| return true; |
| } |
| +bool GDataFileSystem::IsUnderGDataCacheDirectory(const FilePath& path) const { |
| + return gdata_cache_path_ == path || gdata_cache_path_.IsParent(path); |
| +} |
| + |
| FilePath GDataFileSystem::GetGDataCacheTmpDirectory() const { |
| return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP]; |
| } |
| @@ -2013,6 +2018,71 @@ void GDataFileSystem::SetPinState(const FilePath& file_path, bool to_pin, |
| Unpin(resource_id, md5, cache_callback); |
| } |
| +void GDataFileSystem::SetMountedState(const FilePath& file_path, bool to_mount, |
| + const SetMountedStateCallback& callback) { |
|
kuan
2012/04/18 00:36:36
Any method that accesses cache files (i.e. in cach
hshi1
2012/04/18 01:29:05
(1) In terms of the complexity of the change, is t
kuan
2012/04/18 11:32:54
just call PostBlockingPoolSequencedTaskAndReply to
hshi1
2012/04/18 17:28:15
Thanks for the explanation, I think I understood m
kuan
2012/04/18 17:39:20
u use base::Unretained(this) for the task to run o
|
| + base::AutoLock lock(lock_); |
| + |
| + FilePath base_name = file_path.BaseName(); |
| + FilePath::StringType resource_id = base_name.RemoveExtension().value(); |
| + FilePath::StringType extension = base_name.Extension(); |
| + FilePath::StringType md5; |
| + if (to_mount && !extension.empty()) { |
| + // FilePath::Extension returns ".", so strip it. |
| + md5 = GDataFileBase::UnescapeUtf8FileName(extension.substr(1)); |
| + } |
| + GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(resource_id, |
| + md5); |
| + // Report error if cache entry does not exist, or |
| + // if the mounted state of the cache entry is incorrect. |
| + if (!entry || (entry->IsMounted() == to_mount)) { |
| + if (!callback.is_null()) { |
| + MessageLoop::current()->PostTask(FROM_HERE, |
| + base::Bind(callback, base::PLATFORM_FILE_ERROR_INVALID_OPERATION, |
| + FilePath())); |
| + } |
| + return; |
| + } |
| + |
| + // Returns path of the file if it were to be unmounted. |
|
kuan
2012/04/18 00:36:36
nit: s/Returns/Gets/
|
| + FilePath unmounted_path = GetCacheFilePath( |
| + resource_id, md5, |
| + entry->IsPinned() ? |
| + GDataRootDirectory::CACHE_TYPE_PERSISTENT : |
| + GDataRootDirectory::CACHE_TYPE_TMP, |
| + CACHED_FILE_FROM_SERVER); |
| + // Returns path of the file if it were to be mounted. |
|
kuan
2012/04/18 00:36:36
nit: s/Returns/Gets/
|
| + FilePath mounted_path = GetCacheFilePath( |
| + resource_id, md5, |
| + GDataRootDirectory::CACHE_TYPE_PERSISTENT, |
| + CACHED_FILE_MOUNTED); |
| + // Determine the source and destination paths for moving the cache blob. |
| + FilePath src_path, dst_path; |
| + if (to_mount) { |
| + src_path = unmounted_path; |
| + dst_path = mounted_path; |
| + entry->cache_state = GDataFile::SetCacheMounted(entry->cache_state); |
|
kuan
2012/04/18 00:36:36
please use a variable "int cache_state" to store t
|
| + } else { |
| + src_path = mounted_path; |
| + dst_path = unmounted_path; |
| + entry->cache_state = GDataFile::ClearCacheMounted(entry->cache_state); |
| + } |
| + // Move cache blob from source path to destination path. |
| + base::PlatformFileError error = ModifyCacheState( |
| + src_path, dst_path, |
| + GDataFileSystem::FILE_OPERATION_MOVE, |
| + FilePath(), false); |
| + if (error == base::PLATFORM_FILE_OK) { |
| + // Now that cache operation is complete, update cache map |
| + root_->UpdateCacheMap(resource_id, md5, |
| + GDataRootDirectory::CACHE_TYPE_PERSISTENT, |
| + entry->cache_state); |
| + } |
| + if (!callback.is_null()) { |
| + MessageLoop::current()->PostTask(FROM_HERE, |
| + base::Bind(callback, error, dst_path)); |
| + } |
| +} |
| + |
| void GDataFileSystem::OnSetPinStateCompleted( |
| const FileOperationCallback& callback, |
| base::PlatformFileError error, |
| @@ -3184,6 +3254,10 @@ FilePath GDataFileSystem::GetCacheFilePath( |
| DCHECK(sub_dir_type == GDataRootDirectory::CACHE_TYPE_PERSISTENT); |
| base_name += FilePath::kExtensionSeparator; |
| base_name += kLocallyModifiedFileExtension; |
| + } else if (file_origin == CACHED_FILE_MOUNTED) { |
| + DCHECK(sub_dir_type == GDataRootDirectory::CACHE_TYPE_PERSISTENT); |
| + base_name += FilePath::kExtensionSeparator; |
| + base_name += kMountedArchiveFileExtension; |
| } else if (!md5.empty()) { |
| base_name += FilePath::kExtensionSeparator; |
| base_name += GDataFileBase::EscapeUtf8FileName(md5); |
| @@ -3426,12 +3500,19 @@ void GDataFileSystem::GetFromCacheOnIOThreadPool( |
| GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(resource_id, |
| md5); |
| if (entry && entry->IsPresent()) { |
| + CachedFileOrigin file_origin; |
| + if (entry->IsMounted()) { |
| + file_origin = CACHED_FILE_MOUNTED; |
| + } else if (entry->IsDirty()) { |
| + file_origin = CACHED_FILE_LOCALLY_MODIFIED; |
| + } else { |
| + file_origin = CACHED_FILE_FROM_SERVER; |
| + } |
| *cache_file_path = GetCacheFilePath( |
| resource_id, |
| md5, |
| entry->sub_dir_type, |
| - entry->IsDirty() ? CACHED_FILE_LOCALLY_MODIFIED : |
| - CACHED_FILE_FROM_SERVER); |
| + file_origin); |
| *error = base::PLATFORM_FILE_OK; |
| } else { |
| *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |