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

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 under 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 <utility> 10 #include <utility>
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 namespace gdata { 46 namespace gdata {
47 namespace { 47 namespace {
48 48
49 const char kMimeTypeJson[] = "application/json"; 49 const char kMimeTypeJson[] = "application/json";
50 const char kMimeTypeOctetStream[] = "application/octet-stream"; 50 const char kMimeTypeOctetStream[] = "application/octet-stream";
51 51
52 const FilePath::CharType kGDataRootDirectory[] = FILE_PATH_LITERAL("gdata"); 52 const FilePath::CharType kGDataRootDirectory[] = FILE_PATH_LITERAL("gdata");
53 const char kFeedField[] = "feed"; 53 const char kFeedField[] = "feed";
54 const char kWildCard[] = "*"; 54 const char kWildCard[] = "*";
55 const char kLocallyModifiedFileExtension[] = "local"; 55 const char kLocallyModifiedFileExtension[] = "local";
56 const char kMountedArchiveFileExtension[] = "mounted";
56 57
57 const FilePath::CharType kGDataCacheVersionDir[] = FILE_PATH_LITERAL("v1"); 58 const FilePath::CharType kGDataCacheVersionDir[] = FILE_PATH_LITERAL("v1");
58 const FilePath::CharType kGDataCacheMetaDir[] = FILE_PATH_LITERAL("meta"); 59 const FilePath::CharType kGDataCacheMetaDir[] = FILE_PATH_LITERAL("meta");
59 const FilePath::CharType kGDataCachePinnedDir[] = FILE_PATH_LITERAL("pinned"); 60 const FilePath::CharType kGDataCachePinnedDir[] = FILE_PATH_LITERAL("pinned");
60 const FilePath::CharType kGDataCacheOutgoingDir[] = 61 const FilePath::CharType kGDataCacheOutgoingDir[] =
61 FILE_PATH_LITERAL("outgoing"); 62 FILE_PATH_LITERAL("outgoing");
62 const FilePath::CharType kGDataCachePersistentDir[] = 63 const FilePath::CharType kGDataCachePersistentDir[] =
63 FILE_PATH_LITERAL("persistent"); 64 FILE_PATH_LITERAL("persistent");
64 const FilePath::CharType kGDataCacheTmpDir[] = FILE_PATH_LITERAL("tmp"); 65 const FilePath::CharType kGDataCacheTmpDir[] = FILE_PATH_LITERAL("tmp");
65 const FilePath::CharType kGDataCacheTmpDownloadsDir[] = 66 const FilePath::CharType kGDataCacheTmpDownloadsDir[] =
(...skipping 1740 matching lines...) Expand 10 before | Expand all | Expand 10 after
1806 if (regular_file) { 1807 if (regular_file) {
1807 properties->file_md5 = regular_file->file_md5(); 1808 properties->file_md5 = regular_file->file_md5();
1808 properties->mime_type = regular_file->content_mime_type(); 1809 properties->mime_type = regular_file->content_mime_type();
1809 properties->content_url = regular_file->content_url(); 1810 properties->content_url = regular_file->content_url();
1810 properties->edit_url = regular_file->edit_url(); 1811 properties->edit_url = regular_file->edit_url();
1811 properties->is_hosted_document = regular_file->is_hosted_document(); 1812 properties->is_hosted_document = regular_file->is_hosted_document();
1812 } 1813 }
1813 return true; 1814 return true;
1814 } 1815 }
1815 1816
1817 bool GDataFileSystem::IsUnderGDataCacheDirectory(const FilePath& path) const {
1818 return gdata_cache_path_ == path ||
1819 gdata_cache_path_.IsParent(path);
Ben Chan 2012/04/17 20:57:53 nit: can this fit in one line? also, please add u
1820 }
1821
1816 FilePath GDataFileSystem::GetGDataCacheTmpDirectory() const { 1822 FilePath GDataFileSystem::GetGDataCacheTmpDirectory() const {
1817 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP]; 1823 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP];
1818 } 1824 }
1819 1825
1820 FilePath GDataFileSystem::GetGDataTempDownloadFolderPath() const { 1826 FilePath GDataFileSystem::GetGDataTempDownloadFolderPath() const {
1821 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP_DOWNLOADS]; 1827 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP_DOWNLOADS];
1822 } 1828 }
1823 1829
1824 FilePath GDataFileSystem::GetGDataTempDocumentFolderPath() const { 1830 FilePath GDataFileSystem::GetGDataTempDocumentFolderPath() const {
1825 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP_DOCUMENTS]; 1831 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP_DOCUMENTS];
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1954 GetWeakPtrForCurrentThread(), 1960 GetWeakPtrForCurrentThread(),
1955 callback); 1961 callback);
1956 } 1962 }
1957 1963
1958 if (to_pin) 1964 if (to_pin)
1959 Pin(resource_id, md5, cache_callback); 1965 Pin(resource_id, md5, cache_callback);
1960 else 1966 else
1961 Unpin(resource_id, md5, cache_callback); 1967 Unpin(resource_id, md5, cache_callback);
1962 } 1968 }
1963 1969
1970 void GDataFileSystem::SetMountedState(const FilePath& file_path,
1971 const std::string& file_name,
tbarzic 2012/04/17 21:33:13 I don't see that you really use file_name and moun
1972 const std::string& mount_type,
1973 const SetMountedStateCallback& callback) {
1974 std::string resource_id = file_path.BaseName().RemoveExtension().value();
tbarzic 2012/04/17 21:33:13 I think you have to acquire |lock_| before you acc
1975 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(resource_id,
1976 std::string());
Ben Chan 2012/04/17 20:57:53 Should we pass md5 to GetCacheEntry here?
1977 if (!entry || entry->IsMounted()) {
1978 if (!callback.is_null()) {
1979 MessageLoop::current()->PostTask(FROM_HERE,
1980 base::Bind(callback, base::PLATFORM_FILE_ERROR_INVALID_OPERATION,
1981 FilePath(), std::string(), std::string()));
1982 }
1983 return;
1984 }
Ben Chan 2012/04/17 20:57:53 nit: line break
1985 base::PlatformFileError error;
Ben Chan 2012/04/17 20:57:53 this can be defined in the scope below.
1986 {
1987 base::AutoLock lock(lock_);
tbarzic 2012/04/17 21:33:13 You should move this to the method scope.
1988 // Returns original path of the file in cache
1989 FilePath src_path = GetCacheFilePath(resource_id, entry->md5,
1990 entry->IsPinned() ?
1991 GDataRootDirectory::CACHE_TYPE_PERSISTENT :
1992 GDataRootDirectory::CACHE_TYPE_TMP,
1993 CACHED_FILE_FROM_SERVER);
1994 // Returns destination path of the file if it were to be mounted
1995 FilePath dst_path = GetCacheFilePath(resource_id, entry->md5,
1996 GDataRootDirectory::CACHE_TYPE_PERSISTENT,
1997 CACHED_FILE_MOUNTED_ARCHIVE);
1998 // Move cache blob to the mounted path
1999 error = ModifyCacheState(src_path, dst_path,
Ben Chan 2012/04/17 20:57:53 base::PlatformFileError error = ...
2000 GDataFileSystem::FILE_OPERATION_MOVE,
2001 FilePath(), false);
2002 if (error == base::PLATFORM_FILE_OK) {
2003 // Now that cache operation is complete, update cache map
2004 entry->cache_state = GDataFile::SetCacheMounted(entry->cache_state);
2005 root_->UpdateCacheMap(resource_id, entry->md5,
2006 GDataRootDirectory::CACHE_TYPE_PERSISTENT,
2007 entry->cache_state);
2008 }
2009 if (!callback.is_null()) {
2010 MessageLoop::current()->PostTask(FROM_HERE,
2011 base::Bind(callback, error, dst_path, file_name, mount_type));
2012 }
2013 }
2014 }
2015
2016 void GDataFileSystem::ClearMountedState(const FilePath& file_path,
2017 const FileOperationCallback& callback) {
tbarzic 2012/04/17 21:33:13 This looks very similar to SetMountState.. Why do
hshi 2012/04/17 22:36:45 Yes I had initially attempted to merge the two, bu
tbarzic 2012/04/17 23:01:10 when I think about it, it may have sense to pass d
2018 std::string resource_id = file_path.BaseName().RemoveExtension().value();
2019 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(resource_id,
2020 std::string());
2021 if (!entry || !entry->IsMounted()) {
2022 if (!callback.is_null()) {
2023 MessageLoop::current()->PostTask(FROM_HERE,
2024 base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND));
2025 }
2026 return;
2027 }
Ben Chan 2012/04/17 20:57:53 nit: line break
2028 base::PlatformFileError error;
Ben Chan 2012/04/17 20:57:53 this can be defined within the scope below
2029 {
2030 base::AutoLock lock(lock_);
2031 // Returns mounted path of the file in cache
2032 FilePath src_path = GetCacheFilePath(resource_id, entry->md5,
2033 GDataRootDirectory::CACHE_TYPE_PERSISTENT,
Ben Chan 2012/04/17 20:57:53 nit: thisseems like a weird indentation
2034 CACHED_FILE_MOUNTED_ARCHIVE);
2035 // Returns destination path of the file if it were to be unmounted
2036 FilePath dst_path = GetCacheFilePath(resource_id, entry->md5,
2037 entry->IsPinned() ?
Ben Chan 2012/04/17 20:57:53 ditto
2038 GDataRootDirectory::CACHE_TYPE_PERSISTENT :
2039 GDataRootDirectory::CACHE_TYPE_TMP,
2040 CACHED_FILE_FROM_SERVER);
2041 // Move cache blob to the destination path
2042 error = ModifyCacheState(src_path, dst_path,
Ben Chan 2012/04/17 20:57:53 base::PlatformFileError error = ...
2043 GDataFileSystem::FILE_OPERATION_MOVE,
2044 FilePath(), false);
2045 if (error == base::PLATFORM_FILE_OK) {
2046 // Now that cache operation is complete, update cache map
2047 entry->cache_state = GDataFile::ClearCacheMounted(entry->cache_state);
2048 root_->UpdateCacheMap(resource_id, entry->md5,
2049 entry->IsPinned() ?
2050 GDataRootDirectory::CACHE_TYPE_PERSISTENT :
2051 GDataRootDirectory::CACHE_TYPE_TMP,
2052 entry->cache_state);
2053 }
2054 if (!callback.is_null()) {
2055 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, error));
2056 }
2057 }
2058 }
2059
1964 void GDataFileSystem::OnSetPinStateCompleted( 2060 void GDataFileSystem::OnSetPinStateCompleted(
1965 const FileOperationCallback& callback, 2061 const FileOperationCallback& callback,
1966 base::PlatformFileError error, 2062 base::PlatformFileError error,
1967 const std::string& resource_id, 2063 const std::string& resource_id,
1968 const std::string& md5) { 2064 const std::string& md5) {
1969 callback.Run(error); 2065 callback.Run(error);
1970 } 2066 }
1971 2067
1972 void GDataFileSystem::OnGetAvailableSpace( 2068 void GDataFileSystem::OnGetAvailableSpace(
1973 const GetAvailableSpaceCallback& callback, 2069 const GetAvailableSpaceCallback& callback,
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after
3060 DCHECK(sub_dir_type != GDataRootDirectory::CACHE_TYPE_META); 3156 DCHECK(sub_dir_type != GDataRootDirectory::CACHE_TYPE_META);
3061 3157
3062 // Runs on any thread. 3158 // Runs on any thread.
3063 // Filename is formatted as resource_id.md5, i.e. resource_id is the base 3159 // Filename is formatted as resource_id.md5, i.e. resource_id is the base
3064 // name and md5 is the extension. 3160 // name and md5 is the extension.
3065 std::string base_name = GDataFileBase::EscapeUtf8FileName(resource_id); 3161 std::string base_name = GDataFileBase::EscapeUtf8FileName(resource_id);
3066 if (file_origin == CACHED_FILE_LOCALLY_MODIFIED) { 3162 if (file_origin == CACHED_FILE_LOCALLY_MODIFIED) {
3067 DCHECK(sub_dir_type == GDataRootDirectory::CACHE_TYPE_PERSISTENT); 3163 DCHECK(sub_dir_type == GDataRootDirectory::CACHE_TYPE_PERSISTENT);
3068 base_name += FilePath::kExtensionSeparator; 3164 base_name += FilePath::kExtensionSeparator;
3069 base_name += kLocallyModifiedFileExtension; 3165 base_name += kLocallyModifiedFileExtension;
3166 } else if (file_origin == CACHED_FILE_MOUNTED_ARCHIVE) {
3167 DCHECK(sub_dir_type == GDataRootDirectory::CACHE_TYPE_PERSISTENT);
3168 base_name += FilePath::kExtensionSeparator;
3169 base_name += kMountedArchiveFileExtension;
3070 } else if (!md5.empty()) { 3170 } else if (!md5.empty()) {
3071 base_name += FilePath::kExtensionSeparator; 3171 base_name += FilePath::kExtensionSeparator;
3072 base_name += GDataFileBase::EscapeUtf8FileName(md5); 3172 base_name += GDataFileBase::EscapeUtf8FileName(md5);
3073 } 3173 }
3074 return cache_paths_[sub_dir_type].Append(base_name); 3174 return cache_paths_[sub_dir_type].Append(base_name);
3075 } 3175 }
3076 3176
3077 void GDataFileSystem::GetFromCache(const std::string& resource_id, 3177 void GDataFileSystem::GetFromCache(const std::string& resource_id,
3078 const std::string& md5, 3178 const std::string& md5,
3079 const GetFromCacheCallback& callback) { 3179 const GetFromCacheCallback& callback) {
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
3306 // Lock to access cache map. 3406 // Lock to access cache map.
3307 base::AutoLock lock(lock_); 3407 base::AutoLock lock(lock_);
3308 3408
3309 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(resource_id, 3409 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(resource_id,
3310 md5); 3410 md5);
3311 if (entry && entry->IsPresent()) { 3411 if (entry && entry->IsPresent()) {
3312 *cache_file_path = GetCacheFilePath( 3412 *cache_file_path = GetCacheFilePath(
3313 resource_id, 3413 resource_id,
3314 md5, 3414 md5,
3315 entry->sub_dir_type, 3415 entry->sub_dir_type,
3416 entry->IsMounted() ? CACHED_FILE_MOUNTED_ARCHIVE :
tbarzic 2012/04/17 21:33:13 This looks a bit ugly (at least to me:) )
3316 entry->IsDirty() ? CACHED_FILE_LOCALLY_MODIFIED : 3417 entry->IsDirty() ? CACHED_FILE_LOCALLY_MODIFIED :
3317 CACHED_FILE_FROM_SERVER); 3418 CACHED_FILE_FROM_SERVER);
3318 *error = base::PLATFORM_FILE_OK; 3419 *error = base::PLATFORM_FILE_OK;
3319 } else { 3420 } else {
3320 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; 3421 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND;
3321 } 3422 }
3322 } 3423 }
3323 3424
3324 void GDataFileSystem::GetCacheStateOnIOThreadPool( 3425 void GDataFileSystem::GetCacheStateOnIOThreadPool(
3325 const std::string& resource_id, 3426 const std::string& resource_id,
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
4165 pref_registrar_->Init(profile_->GetPrefs()); 4266 pref_registrar_->Init(profile_->GetPrefs());
4166 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); 4267 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this);
4167 } 4268 }
4168 4269
4169 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 4270 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
4170 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 4271 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
4171 global_free_disk_getter_for_testing = getter; 4272 global_free_disk_getter_for_testing = getter;
4172 } 4273 }
4173 4274
4174 } // namespace gdata 4275 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698