Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system.cc

Issue 10008100: gdata: Support mouting archive file in GData cache (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: gdata: Support mounting archive files in GData cache Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 9
10 #include <set> 10 #include <set>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 namespace gdata { 47 namespace gdata {
48 namespace { 48 namespace {
49 49
50 const char kMimeTypeJson[] = "application/json"; 50 const char kMimeTypeJson[] = "application/json";
51 const char kMimeTypeOctetStream[] = "application/octet-stream"; 51 const char kMimeTypeOctetStream[] = "application/octet-stream";
52 52
53 const FilePath::CharType kGDataRootDirectory[] = FILE_PATH_LITERAL("gdata"); 53 const FilePath::CharType kGDataRootDirectory[] = FILE_PATH_LITERAL("gdata");
54 const char kFeedField[] = "feed"; 54 const char kFeedField[] = "feed";
55 const char kWildCard[] = "*"; 55 const char kWildCard[] = "*";
56 const char kLocallyModifiedFileExtension[] = "local"; 56 const char kLocallyModifiedFileExtension[] = "local";
57 const char kMountedArchiveFileExtension[] = "mounted";
57 58
58 const FilePath::CharType kGDataCacheVersionDir[] = FILE_PATH_LITERAL("v1"); 59 const FilePath::CharType kGDataCacheVersionDir[] = FILE_PATH_LITERAL("v1");
59 const FilePath::CharType kGDataCacheMetaDir[] = FILE_PATH_LITERAL("meta"); 60 const FilePath::CharType kGDataCacheMetaDir[] = FILE_PATH_LITERAL("meta");
60 const FilePath::CharType kGDataCachePinnedDir[] = FILE_PATH_LITERAL("pinned"); 61 const FilePath::CharType kGDataCachePinnedDir[] = FILE_PATH_LITERAL("pinned");
61 const FilePath::CharType kGDataCacheOutgoingDir[] = 62 const FilePath::CharType kGDataCacheOutgoingDir[] =
62 FILE_PATH_LITERAL("outgoing"); 63 FILE_PATH_LITERAL("outgoing");
63 const FilePath::CharType kGDataCachePersistentDir[] = 64 const FilePath::CharType kGDataCachePersistentDir[] =
64 FILE_PATH_LITERAL("persistent"); 65 FILE_PATH_LITERAL("persistent");
65 const FilePath::CharType kGDataCacheTmpDir[] = FILE_PATH_LITERAL("tmp"); 66 const FilePath::CharType kGDataCacheTmpDir[] = FILE_PATH_LITERAL("tmp");
66 const FilePath::CharType kGDataCacheTmpDownloadsDir[] = 67 const FilePath::CharType kGDataCacheTmpDownloadsDir[] =
(...skipping 1791 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 if (regular_file) { 1859 if (regular_file) {
1859 properties->file_md5 = regular_file->file_md5(); 1860 properties->file_md5 = regular_file->file_md5();
1860 properties->mime_type = regular_file->content_mime_type(); 1861 properties->mime_type = regular_file->content_mime_type();
1861 properties->content_url = regular_file->content_url(); 1862 properties->content_url = regular_file->content_url();
1862 properties->alternate_url = regular_file->alternate_url(); 1863 properties->alternate_url = regular_file->alternate_url();
1863 properties->is_hosted_document = regular_file->is_hosted_document(); 1864 properties->is_hosted_document = regular_file->is_hosted_document();
1864 } 1865 }
1865 return true; 1866 return true;
1866 } 1867 }
1867 1868
1869 bool GDataFileSystem::IsUnderGDataCacheDirectory(const FilePath& path) const {
1870 return gdata_cache_path_ == path || gdata_cache_path_.IsParent(path);
1871 }
1872
1868 FilePath GDataFileSystem::GetGDataCacheTmpDirectory() const { 1873 FilePath GDataFileSystem::GetGDataCacheTmpDirectory() const {
1869 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP]; 1874 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP];
1870 } 1875 }
1871 1876
1872 FilePath GDataFileSystem::GetGDataTempDownloadFolderPath() const { 1877 FilePath GDataFileSystem::GetGDataTempDownloadFolderPath() const {
1873 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP_DOWNLOADS]; 1878 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP_DOWNLOADS];
1874 } 1879 }
1875 1880
1876 FilePath GDataFileSystem::GetGDataTempDocumentFolderPath() const { 1881 FilePath GDataFileSystem::GetGDataTempDocumentFolderPath() const {
1877 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP_DOCUMENTS]; 1882 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP_DOCUMENTS];
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
2006 GetWeakPtrForCurrentThread(), 2011 GetWeakPtrForCurrentThread(),
2007 callback); 2012 callback);
2008 } 2013 }
2009 2014
2010 if (to_pin) 2015 if (to_pin)
2011 Pin(resource_id, md5, cache_callback); 2016 Pin(resource_id, md5, cache_callback);
2012 else 2017 else
2013 Unpin(resource_id, md5, cache_callback); 2018 Unpin(resource_id, md5, cache_callback);
2014 } 2019 }
2015 2020
2021 void GDataFileSystem::SetMountedState(const FilePath& file_path, bool to_mount,
2022 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
2023 base::AutoLock lock(lock_);
2024
2025 FilePath base_name = file_path.BaseName();
2026 FilePath::StringType resource_id = base_name.RemoveExtension().value();
2027 FilePath::StringType extension = base_name.Extension();
2028 FilePath::StringType md5;
2029 if (to_mount && !extension.empty()) {
2030 // FilePath::Extension returns ".", so strip it.
2031 md5 = GDataFileBase::UnescapeUtf8FileName(extension.substr(1));
2032 }
2033 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(resource_id,
2034 md5);
2035 // Report error if cache entry does not exist, or
2036 // if the mounted state of the cache entry is incorrect.
2037 if (!entry || (entry->IsMounted() == to_mount)) {
2038 if (!callback.is_null()) {
2039 MessageLoop::current()->PostTask(FROM_HERE,
2040 base::Bind(callback, base::PLATFORM_FILE_ERROR_INVALID_OPERATION,
2041 FilePath()));
2042 }
2043 return;
2044 }
2045
2046 // Returns path of the file if it were to be unmounted.
kuan 2012/04/18 00:36:36 nit: s/Returns/Gets/
2047 FilePath unmounted_path = GetCacheFilePath(
2048 resource_id, md5,
2049 entry->IsPinned() ?
2050 GDataRootDirectory::CACHE_TYPE_PERSISTENT :
2051 GDataRootDirectory::CACHE_TYPE_TMP,
2052 CACHED_FILE_FROM_SERVER);
2053 // Returns path of the file if it were to be mounted.
kuan 2012/04/18 00:36:36 nit: s/Returns/Gets/
2054 FilePath mounted_path = GetCacheFilePath(
2055 resource_id, md5,
2056 GDataRootDirectory::CACHE_TYPE_PERSISTENT,
2057 CACHED_FILE_MOUNTED);
2058 // Determine the source and destination paths for moving the cache blob.
2059 FilePath src_path, dst_path;
2060 if (to_mount) {
2061 src_path = unmounted_path;
2062 dst_path = mounted_path;
2063 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
2064 } else {
2065 src_path = mounted_path;
2066 dst_path = unmounted_path;
2067 entry->cache_state = GDataFile::ClearCacheMounted(entry->cache_state);
2068 }
2069 // Move cache blob from source path to destination path.
2070 base::PlatformFileError error = ModifyCacheState(
2071 src_path, dst_path,
2072 GDataFileSystem::FILE_OPERATION_MOVE,
2073 FilePath(), false);
2074 if (error == base::PLATFORM_FILE_OK) {
2075 // Now that cache operation is complete, update cache map
2076 root_->UpdateCacheMap(resource_id, md5,
2077 GDataRootDirectory::CACHE_TYPE_PERSISTENT,
2078 entry->cache_state);
2079 }
2080 if (!callback.is_null()) {
2081 MessageLoop::current()->PostTask(FROM_HERE,
2082 base::Bind(callback, error, dst_path));
2083 }
2084 }
2085
2016 void GDataFileSystem::OnSetPinStateCompleted( 2086 void GDataFileSystem::OnSetPinStateCompleted(
2017 const FileOperationCallback& callback, 2087 const FileOperationCallback& callback,
2018 base::PlatformFileError error, 2088 base::PlatformFileError error,
2019 const std::string& resource_id, 2089 const std::string& resource_id,
2020 const std::string& md5) { 2090 const std::string& md5) {
2021 callback.Run(error); 2091 callback.Run(error);
2022 } 2092 }
2023 2093
2024 void GDataFileSystem::OnGetAvailableSpace( 2094 void GDataFileSystem::OnGetAvailableSpace(
2025 const GetAvailableSpaceCallback& callback, 2095 const GetAvailableSpaceCallback& callback,
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after
3177 DCHECK(sub_dir_type != GDataRootDirectory::CACHE_TYPE_META); 3247 DCHECK(sub_dir_type != GDataRootDirectory::CACHE_TYPE_META);
3178 3248
3179 // Runs on any thread. 3249 // Runs on any thread.
3180 // Filename is formatted as resource_id.md5, i.e. resource_id is the base 3250 // Filename is formatted as resource_id.md5, i.e. resource_id is the base
3181 // name and md5 is the extension. 3251 // name and md5 is the extension.
3182 std::string base_name = GDataFileBase::EscapeUtf8FileName(resource_id); 3252 std::string base_name = GDataFileBase::EscapeUtf8FileName(resource_id);
3183 if (file_origin == CACHED_FILE_LOCALLY_MODIFIED) { 3253 if (file_origin == CACHED_FILE_LOCALLY_MODIFIED) {
3184 DCHECK(sub_dir_type == GDataRootDirectory::CACHE_TYPE_PERSISTENT); 3254 DCHECK(sub_dir_type == GDataRootDirectory::CACHE_TYPE_PERSISTENT);
3185 base_name += FilePath::kExtensionSeparator; 3255 base_name += FilePath::kExtensionSeparator;
3186 base_name += kLocallyModifiedFileExtension; 3256 base_name += kLocallyModifiedFileExtension;
3257 } else if (file_origin == CACHED_FILE_MOUNTED) {
3258 DCHECK(sub_dir_type == GDataRootDirectory::CACHE_TYPE_PERSISTENT);
3259 base_name += FilePath::kExtensionSeparator;
3260 base_name += kMountedArchiveFileExtension;
3187 } else if (!md5.empty()) { 3261 } else if (!md5.empty()) {
3188 base_name += FilePath::kExtensionSeparator; 3262 base_name += FilePath::kExtensionSeparator;
3189 base_name += GDataFileBase::EscapeUtf8FileName(md5); 3263 base_name += GDataFileBase::EscapeUtf8FileName(md5);
3190 } 3264 }
3191 return cache_paths_[sub_dir_type].Append(base_name); 3265 return cache_paths_[sub_dir_type].Append(base_name);
3192 } 3266 }
3193 3267
3194 void GDataFileSystem::GetFromCache(const std::string& resource_id, 3268 void GDataFileSystem::GetFromCache(const std::string& resource_id,
3195 const std::string& md5, 3269 const std::string& md5,
3196 const GetFromCacheCallback& callback) { 3270 const GetFromCacheCallback& callback) {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
3419 FilePath* cache_file_path) { 3493 FilePath* cache_file_path) {
3420 DCHECK(error); 3494 DCHECK(error);
3421 DCHECK(cache_file_path); 3495 DCHECK(cache_file_path);
3422 3496
3423 // Lock to access cache map. 3497 // Lock to access cache map.
3424 base::AutoLock lock(lock_); 3498 base::AutoLock lock(lock_);
3425 3499
3426 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(resource_id, 3500 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(resource_id,
3427 md5); 3501 md5);
3428 if (entry && entry->IsPresent()) { 3502 if (entry && entry->IsPresent()) {
3503 CachedFileOrigin file_origin;
3504 if (entry->IsMounted()) {
3505 file_origin = CACHED_FILE_MOUNTED;
3506 } else if (entry->IsDirty()) {
3507 file_origin = CACHED_FILE_LOCALLY_MODIFIED;
3508 } else {
3509 file_origin = CACHED_FILE_FROM_SERVER;
3510 }
3429 *cache_file_path = GetCacheFilePath( 3511 *cache_file_path = GetCacheFilePath(
3430 resource_id, 3512 resource_id,
3431 md5, 3513 md5,
3432 entry->sub_dir_type, 3514 entry->sub_dir_type,
3433 entry->IsDirty() ? CACHED_FILE_LOCALLY_MODIFIED : 3515 file_origin);
3434 CACHED_FILE_FROM_SERVER);
3435 *error = base::PLATFORM_FILE_OK; 3516 *error = base::PLATFORM_FILE_OK;
3436 } else { 3517 } else {
3437 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; 3518 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND;
3438 } 3519 }
3439 } 3520 }
3440 3521
3441 void GDataFileSystem::GetCacheStateOnIOThreadPool( 3522 void GDataFileSystem::GetCacheStateOnIOThreadPool(
3442 const std::string& resource_id, 3523 const std::string& resource_id,
3443 const std::string& md5, 3524 const std::string& md5,
3444 base::PlatformFileError* error, 3525 base::PlatformFileError* error,
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
4282 pref_registrar_->Init(profile_->GetPrefs()); 4363 pref_registrar_->Init(profile_->GetPrefs());
4283 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); 4364 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this);
4284 } 4365 }
4285 4366
4286 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 4367 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
4287 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 4368 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
4288 global_free_disk_getter_for_testing = getter; 4369 global_free_disk_getter_for_testing = getter;
4289 } 4370 }
4290 4371
4291 } // namespace gdata 4372 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698