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

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

Issue 10545084: Move chromeos::GDataFileSystem::GetCacheDirectoryPath and GetCacheFilePath implementation to GDataC… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 | Annotate | Revision Log
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 using content::BrowserThread; 47 using content::BrowserThread;
48 48
49 namespace gdata { 49 namespace gdata {
50 namespace { 50 namespace {
51 51
52 const char kMimeTypeJson[] = "application/json"; 52 const char kMimeTypeJson[] = "application/json";
53 const char kMimeTypeOctetStream[] = "application/octet-stream"; 53 const char kMimeTypeOctetStream[] = "application/octet-stream";
54 54
55 const char kWildCard[] = "*"; 55 const char kWildCard[] = "*";
56 const char kLocallyModifiedFileExtension[] = "local";
57 const char kMountedArchiveFileExtension[] = "mounted";
58 56
59 const FilePath::CharType kGDataCacheVersionDir[] = FILE_PATH_LITERAL("v1"); 57 const FilePath::CharType kGDataCacheVersionDir[] = FILE_PATH_LITERAL("v1");
60 const FilePath::CharType kGDataCacheMetaDir[] = FILE_PATH_LITERAL("meta");
61 const FilePath::CharType kGDataCachePinnedDir[] = FILE_PATH_LITERAL("pinned");
62 const FilePath::CharType kGDataCacheOutgoingDir[] =
63 FILE_PATH_LITERAL("outgoing");
64 const FilePath::CharType kGDataCachePersistentDir[] =
65 FILE_PATH_LITERAL("persistent");
66 const FilePath::CharType kGDataCacheTmpDir[] = FILE_PATH_LITERAL("tmp");
67 const FilePath::CharType kGDataCacheTmpDownloadsDir[] =
68 FILE_PATH_LITERAL("tmp/downloads");
69 const FilePath::CharType kGDataCacheTmpDocumentsDir[] =
70 FILE_PATH_LITERAL("tmp/documents");
71 const FilePath::CharType kAccountMetadataFile[] = 58 const FilePath::CharType kAccountMetadataFile[] =
72 FILE_PATH_LITERAL("account_metadata.json"); 59 FILE_PATH_LITERAL("account_metadata.json");
73 const FilePath::CharType kFilesystemProtoFile[] = 60 const FilePath::CharType kFilesystemProtoFile[] =
74 FILE_PATH_LITERAL("file_system.pb"); 61 FILE_PATH_LITERAL("file_system.pb");
75 const FilePath::CharType kSymLinkToDevNull[] = FILE_PATH_LITERAL("/dev/null"); 62 const FilePath::CharType kSymLinkToDevNull[] = FILE_PATH_LITERAL("/dev/null");
76 63
77 // GData update check interval (in seconds). 64 // GData update check interval (in seconds).
78 #ifndef NDEBUG 65 #ifndef NDEBUG
79 const int kGDataUpdateCheckIntervalInSec = 5; 66 const int kGDataUpdateCheckIntervalInSec = 5;
80 #else 67 #else
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 932 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
946 } 933 }
947 934
948 void GDataFileSystem::Initialize() { 935 void GDataFileSystem::Initialize() {
949 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 936 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
950 937
951 FilePath cache_base_path; 938 FilePath cache_base_path;
952 chrome::GetUserCacheDirectory(profile_->GetPath(), &cache_base_path); 939 chrome::GetUserCacheDirectory(profile_->GetPath(), &cache_base_path);
953 gdata_cache_path_ = cache_base_path.Append(chrome::kGDataCacheDirname); 940 gdata_cache_path_ = cache_base_path.Append(chrome::kGDataCacheDirname);
954 gdata_cache_path_ = gdata_cache_path_.Append(kGDataCacheVersionDir); 941 gdata_cache_path_ = gdata_cache_path_.Append(kGDataCacheVersionDir);
955 SetCachePaths(gdata_cache_path_);
956 942
957 documents_service_->Initialize(profile_); 943 documents_service_->Initialize(profile_);
958 944
959 root_.reset(new GDataRootDirectory); 945 root_.reset(new GDataRootDirectory);
960 cache_ = GDataCache::CreateGDataCache().Pass(); 946 cache_ = GDataCache::CreateGDataCache(gdata_cache_path_).Pass();
961 947
962 PrefService* pref_service = profile_->GetPrefs(); 948 PrefService* pref_service = profile_->GetPrefs();
963 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles); 949 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles);
964 950
965 InitializePreferenceObserver(); 951 InitializePreferenceObserver();
966 952
967 PostBlockingPoolSequencedTask( 953 PostBlockingPoolSequencedTask(
968 FROM_HERE, 954 FROM_HERE,
969 base::Bind(&GDataFileSystem::InitializeCacheOnBlockingPool, 955 base::Bind(&GDataFileSystem::InitializeCacheOnBlockingPool,
970 base::Unretained(this))); 956 base::Unretained(this)));
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after
2028 base::Bind(&RunGetFileCallbackHelper, 2014 base::Bind(&RunGetFileCallbackHelper,
2029 get_file_callback, 2015 get_file_callback,
2030 base::Owned(error), 2016 base::Owned(error),
2031 base::Owned(temp_file_path), 2017 base::Owned(temp_file_path),
2032 base::Owned(mime_type), 2018 base::Owned(mime_type),
2033 base::Owned(file_type))); 2019 base::Owned(file_type)));
2034 return; 2020 return;
2035 } 2021 }
2036 2022
2037 // Returns absolute path of the file if it were cached or to be cached. 2023 // Returns absolute path of the file if it were cached or to be cached.
2038 FilePath local_tmp_path = GetCacheFilePath(file_properties.resource_id, 2024 FilePath local_tmp_path = cache_->GetCacheFilePath(
2039 file_properties.file_md5, 2025 file_properties.resource_id,
2040 GDataCache::CACHE_TYPE_TMP, 2026 file_properties.file_md5,
2041 CACHED_FILE_FROM_SERVER); 2027 GDataCache::CACHE_TYPE_TMP,
2028 GDataCache::CACHED_FILE_FROM_SERVER);
2042 GetFileFromCacheByResourceIdAndMd5( 2029 GetFileFromCacheByResourceIdAndMd5(
2043 file_properties.resource_id, 2030 file_properties.resource_id,
2044 file_properties.file_md5, 2031 file_properties.file_md5,
2045 base::Bind( 2032 base::Bind(
2046 &GDataFileSystem::OnGetFileFromCache, 2033 &GDataFileSystem::OnGetFileFromCache,
2047 ui_weak_ptr_, 2034 ui_weak_ptr_,
2048 GetFileFromCacheParams(file_path, 2035 GetFileFromCacheParams(file_path,
2049 local_tmp_path, 2036 local_tmp_path,
2050 file_properties.content_url, 2037 file_properties.content_url,
2051 file_properties.resource_id, 2038 file_properties.resource_id,
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
2248 documents_service_->DownloadFile( 2235 documents_service_->DownloadFile(
2249 params.virtual_file_path, 2236 params.virtual_file_path,
2250 params.local_tmp_path, 2237 params.local_tmp_path,
2251 content_url, 2238 content_url,
2252 base::Bind(&GDataFileSystem::OnFileDownloaded, 2239 base::Bind(&GDataFileSystem::OnFileDownloaded,
2253 ui_weak_ptr_, 2240 ui_weak_ptr_,
2254 params), 2241 params),
2255 params.get_download_data_callback); 2242 params.get_download_data_callback);
2256 } 2243 }
2257 2244
2258 void GDataFileSystem::SetCachePaths(const FilePath& root_path) {
2259 DCHECK(cache_paths_.empty());
2260
2261 // Insert into |cache_paths_| in order defined in enum CacheSubDirectoryType.
2262 cache_paths_.push_back(root_path.Append(kGDataCacheMetaDir));
2263 cache_paths_.push_back(root_path.Append(kGDataCachePinnedDir));
2264 cache_paths_.push_back(root_path.Append(kGDataCacheOutgoingDir));
2265 cache_paths_.push_back(root_path.Append(kGDataCachePersistentDir));
2266 cache_paths_.push_back(root_path.Append(kGDataCacheTmpDir));
2267 cache_paths_.push_back(root_path.Append(kGDataCacheTmpDownloadsDir));
2268 cache_paths_.push_back(root_path.Append(kGDataCacheTmpDocumentsDir));
2269 }
2270
2271 void GDataFileSystem::GetEntryInfoByPathAsync( 2245 void GDataFileSystem::GetEntryInfoByPathAsync(
2272 const FilePath& file_path, 2246 const FilePath& file_path,
2273 const GetEntryInfoCallback& callback) { 2247 const GetEntryInfoCallback& callback) {
2274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 2248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2275 BrowserThread::CurrentlyOn(BrowserThread::IO)); 2249 BrowserThread::CurrentlyOn(BrowserThread::IO));
2276 RunTaskOnUIThread( 2250 RunTaskOnUIThread(
2277 base::Bind(&GDataFileSystem::GetEntryInfoByPathAsyncOnUIThread, 2251 base::Bind(&GDataFileSystem::GetEntryInfoByPathAsyncOnUIThread,
2278 ui_weak_ptr_, 2252 ui_weak_ptr_,
2279 file_path, 2253 file_path,
2280 CreateRelayCallback(callback))); 2254 CreateRelayCallback(callback)));
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
2702 DCHECK(cache_file_path); 2676 DCHECK(cache_file_path);
2703 2677
2704 base::AutoLock lock(lock_); // For cache access. 2678 base::AutoLock lock(lock_); // For cache access.
2705 2679
2706 // Parse file path to obtain resource_id, md5 and extra_extension. 2680 // Parse file path to obtain resource_id, md5 and extra_extension.
2707 std::string resource_id; 2681 std::string resource_id;
2708 std::string md5; 2682 std::string md5;
2709 std::string extra_extension; 2683 std::string extra_extension;
2710 util::ParseCacheFilePath(file_path, &resource_id, &md5, &extra_extension); 2684 util::ParseCacheFilePath(file_path, &resource_id, &md5, &extra_extension);
2711 // The extra_extension shall be ".mounted" iff we're unmounting. 2685 // The extra_extension shall be ".mounted" iff we're unmounting.
2712 DCHECK(!to_mount == (extra_extension == kMountedArchiveFileExtension)); 2686 DCHECK(!to_mount ==
2687 (extra_extension == GDataCache::kMountedArchiveFileExtension));
2713 2688
2714 // Get cache entry associated with the resource_id and md5 2689 // Get cache entry associated with the resource_id and md5
2715 scoped_ptr<GDataCache::CacheEntry> cache_entry = cache_->GetCacheEntry( 2690 scoped_ptr<GDataCache::CacheEntry> cache_entry = cache_->GetCacheEntry(
2716 resource_id, md5); 2691 resource_id, md5);
2717 if (!cache_entry.get()) { 2692 if (!cache_entry.get()) {
2718 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; 2693 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND;
2719 return; 2694 return;
2720 } 2695 }
2721 if (to_mount == cache_entry->IsMounted()) { 2696 if (to_mount == cache_entry->IsMounted()) {
2722 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 2697 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
2723 return; 2698 return;
2724 } 2699 }
2725 2700
2726 // Get the subdir type and path for the unmounted state. 2701 // Get the subdir type and path for the unmounted state.
2727 GDataCache::CacheSubDirectoryType unmounted_subdir = 2702 GDataCache::CacheSubDirectoryType unmounted_subdir =
2728 cache_entry->IsPinned() ? GDataCache::CACHE_TYPE_PERSISTENT : 2703 cache_entry->IsPinned() ? GDataCache::CACHE_TYPE_PERSISTENT :
2729 GDataCache::CACHE_TYPE_TMP; 2704 GDataCache::CACHE_TYPE_TMP;
2730 FilePath unmounted_path = GetCacheFilePath(resource_id, md5, unmounted_subdir, 2705 FilePath unmounted_path = cache_->GetCacheFilePath(
2731 CACHED_FILE_FROM_SERVER); 2706 resource_id, md5, unmounted_subdir, GDataCache::CACHED_FILE_FROM_SERVER);
2732 2707
2733 // Get the subdir type and path for the mounted state. 2708 // Get the subdir type and path for the mounted state.
2734 GDataCache::CacheSubDirectoryType mounted_subdir = 2709 GDataCache::CacheSubDirectoryType mounted_subdir =
2735 GDataCache::CACHE_TYPE_PERSISTENT; 2710 GDataCache::CACHE_TYPE_PERSISTENT;
2736 FilePath mounted_path = GetCacheFilePath(resource_id, md5, mounted_subdir, 2711 FilePath mounted_path = cache_->GetCacheFilePath(
2737 CACHED_FILE_MOUNTED); 2712 resource_id, md5, mounted_subdir, GDataCache::CACHED_FILE_MOUNTED);
2738 2713
2739 // Determine the source and destination paths for moving the cache blob. 2714 // Determine the source and destination paths for moving the cache blob.
2740 FilePath source_path; 2715 FilePath source_path;
2741 GDataCache::CacheSubDirectoryType dest_subdir; 2716 GDataCache::CacheSubDirectoryType dest_subdir;
2742 int cache_state = cache_entry->cache_state; 2717 int cache_state = cache_entry->cache_state;
2743 if (to_mount) { 2718 if (to_mount) {
2744 source_path = unmounted_path; 2719 source_path = unmounted_path;
2745 *cache_file_path = mounted_path; 2720 *cache_file_path = mounted_path;
2746 dest_subdir = mounted_subdir; 2721 dest_subdir = mounted_subdir;
2747 cache_state = GDataCache::SetCacheMounted(cache_state); 2722 cache_state = GDataCache::SetCacheMounted(cache_state);
(...skipping 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after
3967 } 3942 }
3968 3943
3969 //===================== GDataFileSystem: Cache entry points ==================== 3944 //===================== GDataFileSystem: Cache entry points ====================
3970 3945
3971 bool GDataFileSystem::IsUnderGDataCacheDirectory(const FilePath& path) const { 3946 bool GDataFileSystem::IsUnderGDataCacheDirectory(const FilePath& path) const {
3972 return gdata_cache_path_ == path || gdata_cache_path_.IsParent(path); 3947 return gdata_cache_path_ == path || gdata_cache_path_.IsParent(path);
3973 } 3948 }
3974 3949
3975 FilePath GDataFileSystem::GetCacheDirectoryPath( 3950 FilePath GDataFileSystem::GetCacheDirectoryPath(
3976 GDataCache::CacheSubDirectoryType sub_dir_type) const { 3951 GDataCache::CacheSubDirectoryType sub_dir_type) const {
3977 DCHECK_LE(0, sub_dir_type); 3952 return cache_->GetCacheDirectoryPath(sub_dir_type);
3978 DCHECK_GT(GDataCache::NUM_CACHE_TYPES, sub_dir_type);
3979 return cache_paths_[sub_dir_type];
3980 } 3953 }
3981 3954
3982 FilePath GDataFileSystem::GetCacheFilePath( 3955 FilePath GDataFileSystem::GetCacheFilePath(
3983 const std::string& resource_id, 3956 const std::string& resource_id,
3984 const std::string& md5, 3957 const std::string& md5,
3985 GDataCache::CacheSubDirectoryType sub_dir_type, 3958 GDataCache::CacheSubDirectoryType sub_dir_type,
3986 CachedFileOrigin file_origin) const { 3959 GDataCache::CachedFileOrigin file_origin) const {
3987 DCHECK(sub_dir_type != GDataCache::CACHE_TYPE_META); 3960 return cache_->GetCacheFilePath(resource_id, md5, sub_dir_type, file_origin);
3988
3989 // Runs on any thread.
3990 // Filename is formatted as resource_id.md5, i.e. resource_id is the base
3991 // name and md5 is the extension.
3992 std::string base_name = util::EscapeCacheFileName(resource_id);
3993 if (file_origin == CACHED_FILE_LOCALLY_MODIFIED) {
3994 DCHECK(sub_dir_type == GDataCache::CACHE_TYPE_PERSISTENT);
3995 base_name += FilePath::kExtensionSeparator;
3996 base_name += kLocallyModifiedFileExtension;
3997 } else if (!md5.empty()) {
3998 base_name += FilePath::kExtensionSeparator;
3999 base_name += util::EscapeCacheFileName(md5);
4000 }
4001 // For mounted archives the filename is formatted as resource_id.md5.mounted,
4002 // i.e. resource_id.md5 is the base name and ".mounted" is the extension
4003 if (file_origin == CACHED_FILE_MOUNTED) {
4004 DCHECK(sub_dir_type == GDataCache::CACHE_TYPE_PERSISTENT);
4005 base_name += FilePath::kExtensionSeparator;
4006 base_name += kMountedArchiveFileExtension;
4007 }
4008 return GetCacheDirectoryPath(sub_dir_type).Append(base_name);
4009 } 3961 }
4010 3962
4011 void GDataFileSystem::StoreToCache(const std::string& resource_id, 3963 void GDataFileSystem::StoreToCache(const std::string& resource_id,
4012 const std::string& md5, 3964 const std::string& md5,
4013 const FilePath& source_path, 3965 const FilePath& source_path,
4014 FileOperationType file_operation_type, 3966 FileOperationType file_operation_type,
4015 const CacheOperationCallback& callback) { 3967 const CacheOperationCallback& callback) {
4016 base::PlatformFileError* error = 3968 base::PlatformFileError* error =
4017 new base::PlatformFileError(base::PLATFORM_FILE_OK); 3969 new base::PlatformFileError(base::PLATFORM_FILE_OK);
4018 PostBlockingPoolSequencedTaskAndReply( 3970 PostBlockingPoolSequencedTaskAndReply(
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
4174 FROM_HERE, 4126 FROM_HERE,
4175 base::Bind(&GDataFileSystem::InitializeCacheOnBlockingPool, 4127 base::Bind(&GDataFileSystem::InitializeCacheOnBlockingPool,
4176 base::Unretained(this))); 4128 base::Unretained(this)));
4177 } 4129 }
4178 4130
4179 //========= GDataFileSystem: Cache tasks that ran on blocking pool ============ 4131 //========= GDataFileSystem: Cache tasks that ran on blocking pool ============
4180 4132
4181 void GDataFileSystem::InitializeCacheOnBlockingPool() { 4133 void GDataFileSystem::InitializeCacheOnBlockingPool() {
4182 DCHECK(IsRunningSequenceOnCurrentThread(sequence_token_)); 4134 DCHECK(IsRunningSequenceOnCurrentThread(sequence_token_));
4183 4135
4184 base::PlatformFileError error = CreateCacheDirectories(cache_paths_); 4136 base::PlatformFileError error = CreateCacheDirectories(cache_->cache_paths());
4185 if (error != base::PLATFORM_FILE_OK) 4137 if (error != base::PLATFORM_FILE_OK)
4186 return; 4138 return;
4187 4139
4188 // Change permissions of cache persistent directory to u+rwx,og+x in order to 4140 // Change permissions of cache persistent directory to u+rwx,og+x in order to
4189 // allow archive files in that directory to be mounted by cros-disks. 4141 // allow archive files in that directory to be mounted by cros-disks.
4190 error = ChangeFilePermissions( 4142 error = ChangeFilePermissions(
4191 GetCacheDirectoryPath(GDataCache::CACHE_TYPE_PERSISTENT), 4143 GetCacheDirectoryPath(GDataCache::CACHE_TYPE_PERSISTENT),
4192 S_IRWXU | S_IXGRP | S_IXOTH); 4144 S_IRWXU | S_IXGRP | S_IXOTH);
4193 if (error != base::PLATFORM_FILE_OK) 4145 if (error != base::PLATFORM_FILE_OK)
4194 return; 4146 return;
(...skipping 30 matching lines...) Expand all
4225 FilePath* cache_file_path) { 4177 FilePath* cache_file_path) {
4226 DCHECK(IsRunningSequenceOnCurrentThread(sequence_token_)); 4178 DCHECK(IsRunningSequenceOnCurrentThread(sequence_token_));
4227 DCHECK(error); 4179 DCHECK(error);
4228 DCHECK(cache_file_path); 4180 DCHECK(cache_file_path);
4229 4181
4230 base::AutoLock lock(lock_); // For cache access. 4182 base::AutoLock lock(lock_); // For cache access.
4231 4183
4232 scoped_ptr<GDataCache::CacheEntry> cache_entry = cache_->GetCacheEntry( 4184 scoped_ptr<GDataCache::CacheEntry> cache_entry = cache_->GetCacheEntry(
4233 resource_id, md5); 4185 resource_id, md5);
4234 if (cache_entry.get() && cache_entry->IsPresent()) { 4186 if (cache_entry.get() && cache_entry->IsPresent()) {
4235 CachedFileOrigin file_origin; 4187 GDataCache::CachedFileOrigin file_origin;
4236 if (cache_entry->IsMounted()) { 4188 if (cache_entry->IsMounted()) {
4237 file_origin = CACHED_FILE_MOUNTED; 4189 file_origin = GDataCache::CACHED_FILE_MOUNTED;
4238 } else if (cache_entry->IsDirty()) { 4190 } else if (cache_entry->IsDirty()) {
4239 file_origin = CACHED_FILE_LOCALLY_MODIFIED; 4191 file_origin = GDataCache::CACHED_FILE_LOCALLY_MODIFIED;
4240 } else { 4192 } else {
4241 file_origin = CACHED_FILE_FROM_SERVER; 4193 file_origin = GDataCache::CACHED_FILE_FROM_SERVER;
4242 } 4194 }
4243 *cache_file_path = GetCacheFilePath( 4195 *cache_file_path = cache_->GetCacheFilePath(
4244 resource_id, 4196 resource_id,
4245 md5, 4197 md5,
4246 cache_entry->sub_dir_type, 4198 cache_entry->sub_dir_type,
4247 file_origin); 4199 file_origin);
4248 *error = base::PLATFORM_FILE_OK; 4200 *error = base::PLATFORM_FILE_OK;
4249 } else { 4201 } else {
4250 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; 4202 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND;
4251 } 4203 }
4252 } 4204 }
4253 4205
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
4309 << ", md5=" << md5; 4261 << ", md5=" << md5;
4310 *error = base::PLATFORM_FILE_ERROR_IN_USE; 4262 *error = base::PLATFORM_FILE_ERROR_IN_USE;
4311 return; 4263 return;
4312 } 4264 }
4313 4265
4314 cache_state |= cache_entry->cache_state; 4266 cache_state |= cache_entry->cache_state;
4315 4267
4316 // If file is pinned, determines destination path. 4268 // If file is pinned, determines destination path.
4317 if (cache_entry->IsPinned()) { 4269 if (cache_entry->IsPinned()) {
4318 sub_dir_type = GDataCache::CACHE_TYPE_PERSISTENT; 4270 sub_dir_type = GDataCache::CACHE_TYPE_PERSISTENT;
4319 dest_path = GetCacheFilePath(resource_id, md5, sub_dir_type, 4271 dest_path = cache_->GetCacheFilePath(resource_id, md5, sub_dir_type,
4320 CACHED_FILE_FROM_SERVER); 4272 GDataCache::CACHED_FILE_FROM_SERVER);
4321 symlink_path = GetCacheFilePath(resource_id, std::string(), 4273 symlink_path = cache_->GetCacheFilePath(
4322 GDataCache::CACHE_TYPE_PINNED, 4274 resource_id, std::string(), GDataCache::CACHE_TYPE_PINNED,
4323 CACHED_FILE_FROM_SERVER); 4275 GDataCache::CACHED_FILE_FROM_SERVER);
4324 } 4276 }
4325 } 4277 }
4326 4278
4327 // File wasn't pinned or doesn't exist in cache, store in tmp dir. 4279 // File wasn't pinned or doesn't exist in cache, store in tmp dir.
4328 if (dest_path.empty()) { 4280 if (dest_path.empty()) {
4329 DCHECK_EQ(GDataCache::CACHE_TYPE_TMP, sub_dir_type); 4281 DCHECK_EQ(GDataCache::CACHE_TYPE_TMP, sub_dir_type);
4330 dest_path = GetCacheFilePath(resource_id, md5, sub_dir_type, 4282 dest_path = cache_->GetCacheFilePath(resource_id, md5, sub_dir_type,
4331 CACHED_FILE_FROM_SERVER); 4283 GDataCache::CACHED_FILE_FROM_SERVER);
4332 } 4284 }
4333 4285
4334 *error = ModifyCacheState( 4286 *error = ModifyCacheState(
4335 source_path, 4287 source_path,
4336 dest_path, 4288 dest_path,
4337 file_operation_type, 4289 file_operation_type,
4338 symlink_path, 4290 symlink_path,
4339 !symlink_path.empty()); // create symlink 4291 !symlink_path.empty()); // create symlink
4340 4292
4341 // Determine search pattern for stale filenames corrresponding to resource_id, 4293 // Determine search pattern for stale filenames corrresponding to resource_id,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
4401 } else { // File exists in cache, determines destination path. 4353 } else { // File exists in cache, determines destination path.
4402 cache_state |= cache_entry->cache_state; 4354 cache_state |= cache_entry->cache_state;
4403 4355
4404 // Determine source and destination paths. 4356 // Determine source and destination paths.
4405 4357
4406 // If file is dirty or mounted, don't move it, so determine |dest_path| and 4358 // If file is dirty or mounted, don't move it, so determine |dest_path| and
4407 // set |source_path| the same, because ModifyCacheState only moves files if 4359 // set |source_path| the same, because ModifyCacheState only moves files if
4408 // source and destination are different. 4360 // source and destination are different.
4409 if (cache_entry->IsDirty() || cache_entry->IsMounted()) { 4361 if (cache_entry->IsDirty() || cache_entry->IsMounted()) {
4410 DCHECK_EQ(GDataCache::CACHE_TYPE_PERSISTENT, cache_entry->sub_dir_type); 4362 DCHECK_EQ(GDataCache::CACHE_TYPE_PERSISTENT, cache_entry->sub_dir_type);
4411 dest_path = GetCacheFilePath(resource_id, 4363 dest_path = cache_->GetCacheFilePath(
4412 md5, 4364 resource_id,
4413 cache_entry->sub_dir_type, 4365 md5,
4414 CACHED_FILE_LOCALLY_MODIFIED); 4366 cache_entry->sub_dir_type,
4367 GDataCache::CACHED_FILE_LOCALLY_MODIFIED);
4415 source_path = dest_path; 4368 source_path = dest_path;
4416 } else { 4369 } else {
4417 // Gets the current path of the file in cache. 4370 // Gets the current path of the file in cache.
4418 source_path = GetCacheFilePath(resource_id, 4371 source_path = cache_->GetCacheFilePath(
4419 md5, 4372 resource_id,
4420 cache_entry->sub_dir_type, 4373 md5,
4421 CACHED_FILE_FROM_SERVER); 4374 cache_entry->sub_dir_type,
4375 GDataCache::CACHED_FILE_FROM_SERVER);
4422 4376
4423 // If file was pinned before but actual file blob doesn't exist in cache: 4377 // If file was pinned before but actual file blob doesn't exist in cache:
4424 // - don't need to move the file, so set |dest_path| to |source_path|, 4378 // - don't need to move the file, so set |dest_path| to |source_path|,
4425 // because ModifyCacheState only moves files if source and destination 4379 // because ModifyCacheState only moves files if source and destination
4426 // are different 4380 // are different
4427 // - don't create symlink since it already exists. 4381 // - don't create symlink since it already exists.
4428 if (cache_entry->sub_dir_type == GDataCache::CACHE_TYPE_PINNED) { 4382 if (cache_entry->sub_dir_type == GDataCache::CACHE_TYPE_PINNED) {
4429 dest_path = source_path; 4383 dest_path = source_path;
4430 create_symlink = false; 4384 create_symlink = false;
4431 } else { // File exists, move it to persistent dir. 4385 } else { // File exists, move it to persistent dir.
4432 dest_path = GetCacheFilePath(resource_id, 4386 dest_path = cache_->GetCacheFilePath(
4433 md5, 4387 resource_id,
4434 GDataCache::CACHE_TYPE_PERSISTENT, 4388 md5,
4435 CACHED_FILE_FROM_SERVER); 4389 GDataCache::CACHE_TYPE_PERSISTENT,
4390 GDataCache::CACHED_FILE_FROM_SERVER);
4436 } 4391 }
4437 } 4392 }
4438 } 4393 }
4439 4394
4440 // Create symlink in pinned dir. 4395 // Create symlink in pinned dir.
4441 if (create_symlink) { 4396 if (create_symlink) {
4442 symlink_path = GetCacheFilePath(resource_id, 4397 symlink_path = cache_->GetCacheFilePath(
4443 std::string(), 4398 resource_id,
4444 GDataCache::CACHE_TYPE_PINNED, 4399 std::string(),
4445 CACHED_FILE_FROM_SERVER); 4400 GDataCache::CACHE_TYPE_PINNED,
4401 GDataCache::CACHED_FILE_FROM_SERVER);
4446 } 4402 }
4447 4403
4448 *error = ModifyCacheState(source_path, 4404 *error = ModifyCacheState(source_path,
4449 dest_path, 4405 dest_path,
4450 file_operation_type, 4406 file_operation_type,
4451 symlink_path, 4407 symlink_path,
4452 create_symlink); 4408 create_symlink);
4453 4409
4454 if (*error == base::PLATFORM_FILE_OK) { 4410 if (*error == base::PLATFORM_FILE_OK) {
4455 // Now that file operations have completed, update cache map. 4411 // Now that file operations have completed, update cache map.
(...skipping 28 matching lines...) Expand all
4484 FilePath dest_path; 4440 FilePath dest_path;
4485 GDataCache::CacheSubDirectoryType sub_dir_type = 4441 GDataCache::CacheSubDirectoryType sub_dir_type =
4486 GDataCache::CACHE_TYPE_TMP; 4442 GDataCache::CACHE_TYPE_TMP;
4487 4443
4488 // If file is dirty or mounted, don't move it, so determine |dest_path| and 4444 // If file is dirty or mounted, don't move it, so determine |dest_path| and
4489 // set |source_path| the same, because ModifyCacheState moves files if source 4445 // set |source_path| the same, because ModifyCacheState moves files if source
4490 // and destination are different. 4446 // and destination are different.
4491 if (cache_entry->IsDirty() || cache_entry->IsMounted()) { 4447 if (cache_entry->IsDirty() || cache_entry->IsMounted()) {
4492 sub_dir_type = GDataCache::CACHE_TYPE_PERSISTENT; 4448 sub_dir_type = GDataCache::CACHE_TYPE_PERSISTENT;
4493 DCHECK_EQ(sub_dir_type, cache_entry->sub_dir_type); 4449 DCHECK_EQ(sub_dir_type, cache_entry->sub_dir_type);
4494 dest_path = GetCacheFilePath(resource_id, 4450 dest_path = cache_->GetCacheFilePath(
4495 md5, 4451 resource_id,
4496 cache_entry->sub_dir_type, 4452 md5,
4497 CACHED_FILE_LOCALLY_MODIFIED); 4453 cache_entry->sub_dir_type,
4454 GDataCache::CACHED_FILE_LOCALLY_MODIFIED);
4498 source_path = dest_path; 4455 source_path = dest_path;
4499 } else { 4456 } else {
4500 // Gets the current path of the file in cache. 4457 // Gets the current path of the file in cache.
4501 source_path = GetCacheFilePath(resource_id, 4458 source_path = cache_->GetCacheFilePath(resource_id,
4502 md5, 4459 md5,
4503 cache_entry->sub_dir_type, 4460 cache_entry->sub_dir_type,
4504 CACHED_FILE_FROM_SERVER); 4461 GDataCache::CACHED_FILE_FROM_SERVER);
4505 4462
4506 // If file was pinned but actual file blob still doesn't exist in cache, 4463 // If file was pinned but actual file blob still doesn't exist in cache,
4507 // don't need to move the file, so set |dest_path| to |source_path|, because 4464 // don't need to move the file, so set |dest_path| to |source_path|, because
4508 // ModifyCacheState only moves files if source and destination are 4465 // ModifyCacheState only moves files if source and destination are
4509 // different. 4466 // different.
4510 if (cache_entry->sub_dir_type == GDataCache::CACHE_TYPE_PINNED) { 4467 if (cache_entry->sub_dir_type == GDataCache::CACHE_TYPE_PINNED) {
4511 dest_path = source_path; 4468 dest_path = source_path;
4512 } else { // File exists, move it to tmp dir. 4469 } else { // File exists, move it to tmp dir.
4513 dest_path = GetCacheFilePath(resource_id, md5, 4470 dest_path = cache_->GetCacheFilePath(resource_id, md5,
4514 GDataCache::CACHE_TYPE_TMP, 4471 GDataCache::CACHE_TYPE_TMP,
4515 CACHED_FILE_FROM_SERVER); 4472 GDataCache::CACHED_FILE_FROM_SERVER);
4516 } 4473 }
4517 } 4474 }
4518 4475
4519 // If file was pinned, get absolute path of symlink in pinned dir so as to 4476 // If file was pinned, get absolute path of symlink in pinned dir so as to
4520 // remove it. 4477 // remove it.
4521 FilePath symlink_path; 4478 FilePath symlink_path;
4522 if (cache_entry->IsPinned()) { 4479 if (cache_entry->IsPinned()) {
4523 symlink_path = GetCacheFilePath(resource_id, 4480 symlink_path = cache_->GetCacheFilePath(resource_id,
4524 std::string(), 4481 std::string(),
4525 GDataCache::CACHE_TYPE_PINNED, 4482 GDataCache::CACHE_TYPE_PINNED,
4526 CACHED_FILE_FROM_SERVER); 4483 GDataCache::CACHED_FILE_FROM_SERVER);
4527 } 4484 }
4528 4485
4529 *error = ModifyCacheState( 4486 *error = ModifyCacheState(
4530 source_path, 4487 source_path,
4531 dest_path, 4488 dest_path,
4532 file_operation_type, 4489 file_operation_type,
4533 symlink_path, // This will be deleted if it exists. 4490 symlink_path, // This will be deleted if it exists.
4534 false /* don't create symlink*/); 4491 false /* don't create symlink*/);
4535 4492
4536 if (*error == base::PLATFORM_FILE_OK) { 4493 if (*error == base::PLATFORM_FILE_OK) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
4574 // delete outgoing symlink if it exists. 4531 // delete outgoing symlink if it exists.
4575 // TODO(benchan): We should only delete outgoing symlink if file is currently 4532 // TODO(benchan): We should only delete outgoing symlink if file is currently
4576 // not being uploaded. However, for now, cache doesn't know if uploading of a 4533 // not being uploaded. However, for now, cache doesn't know if uploading of a
4577 // file is in progress. Per zel, the upload process should be canceled before 4534 // file is in progress. Per zel, the upload process should be canceled before
4578 // MarkDirtyInCache is called again. 4535 // MarkDirtyInCache is called again.
4579 if (cache_entry->IsDirty()) { 4536 if (cache_entry->IsDirty()) {
4580 // The file must be in persistent dir. 4537 // The file must be in persistent dir.
4581 DCHECK_EQ(GDataCache::CACHE_TYPE_PERSISTENT, cache_entry->sub_dir_type); 4538 DCHECK_EQ(GDataCache::CACHE_TYPE_PERSISTENT, cache_entry->sub_dir_type);
4582 4539
4583 // Determine symlink path in outgoing dir, so as to remove it. 4540 // Determine symlink path in outgoing dir, so as to remove it.
4584 FilePath symlink_path = GetCacheFilePath( 4541 FilePath symlink_path = cache_->GetCacheFilePath(
4585 resource_id, 4542 resource_id,
4586 std::string(), 4543 std::string(),
4587 GDataCache::CACHE_TYPE_OUTGOING, 4544 GDataCache::CACHE_TYPE_OUTGOING,
4588 CACHED_FILE_FROM_SERVER); 4545 GDataCache::CACHED_FILE_FROM_SERVER);
4589 4546
4590 // We're not moving files here, so simply use empty FilePath for both 4547 // We're not moving files here, so simply use empty FilePath for both
4591 // |source_path| and |dest_path| because ModifyCacheState only move files 4548 // |source_path| and |dest_path| because ModifyCacheState only move files
4592 // if source and destination are different. 4549 // if source and destination are different.
4593 *error = ModifyCacheState( 4550 *error = ModifyCacheState(
4594 FilePath(), // non-applicable source path 4551 FilePath(), // non-applicable source path
4595 FilePath(), // non-applicable dest path 4552 FilePath(), // non-applicable dest path
4596 file_operation_type, 4553 file_operation_type,
4597 symlink_path, 4554 symlink_path,
4598 false /* don't create symlink */); 4555 false /* don't create symlink */);
4599 4556
4600 // Determine current path of dirty file. 4557 // Determine current path of dirty file.
4601 if (*error == base::PLATFORM_FILE_OK) { 4558 if (*error == base::PLATFORM_FILE_OK) {
4602 *cache_file_path = GetCacheFilePath( 4559 *cache_file_path = cache_->GetCacheFilePath(
4603 resource_id, 4560 resource_id,
4604 md5, 4561 md5,
4605 GDataCache::CACHE_TYPE_PERSISTENT, 4562 GDataCache::CACHE_TYPE_PERSISTENT,
4606 CACHED_FILE_LOCALLY_MODIFIED); 4563 GDataCache::CACHED_FILE_LOCALLY_MODIFIED);
4607 } 4564 }
4608 return; 4565 return;
4609 } 4566 }
4610 4567
4611 // Move file to persistent dir with new .local extension. 4568 // Move file to persistent dir with new .local extension.
4612 4569
4613 // Get the current path of the file in cache. 4570 // Get the current path of the file in cache.
4614 FilePath source_path = GetCacheFilePath(resource_id, 4571 FilePath source_path = cache_->GetCacheFilePath(
4615 md5, 4572 resource_id,
4616 cache_entry->sub_dir_type, 4573 md5,
4617 CACHED_FILE_FROM_SERVER); 4574 cache_entry->sub_dir_type,
4575 GDataCache::CACHED_FILE_FROM_SERVER);
4618 4576
4619 // Determine destination path. 4577 // Determine destination path.
4620 GDataCache::CacheSubDirectoryType sub_dir_type = 4578 GDataCache::CacheSubDirectoryType sub_dir_type =
4621 GDataCache::CACHE_TYPE_PERSISTENT; 4579 GDataCache::CACHE_TYPE_PERSISTENT;
4622 *cache_file_path = GetCacheFilePath(resource_id, 4580 *cache_file_path = cache_->GetCacheFilePath(
4623 md5, 4581 resource_id,
4624 sub_dir_type, 4582 md5,
4625 CACHED_FILE_LOCALLY_MODIFIED); 4583 sub_dir_type,
4584 GDataCache::CACHED_FILE_LOCALLY_MODIFIED);
4626 4585
4627 // If file is pinned, update symlink in pinned dir. 4586 // If file is pinned, update symlink in pinned dir.
4628 FilePath symlink_path; 4587 FilePath symlink_path;
4629 if (cache_entry->IsPinned()) { 4588 if (cache_entry->IsPinned()) {
4630 symlink_path = GetCacheFilePath(resource_id, 4589 symlink_path = cache_->GetCacheFilePath(
4631 std::string(), 4590 resource_id,
4632 GDataCache::CACHE_TYPE_PINNED, 4591 std::string(),
4633 CACHED_FILE_FROM_SERVER); 4592 GDataCache::CACHE_TYPE_PINNED,
4593 GDataCache::CACHED_FILE_FROM_SERVER);
4634 } 4594 }
4635 4595
4636 *error = ModifyCacheState( 4596 *error = ModifyCacheState(
4637 source_path, 4597 source_path,
4638 *cache_file_path, 4598 *cache_file_path,
4639 file_operation_type, 4599 file_operation_type,
4640 symlink_path, 4600 symlink_path,
4641 !symlink_path.empty() /* create symlink */); 4601 !symlink_path.empty() /* create symlink */);
4642 4602
4643 if (*error == base::PLATFORM_FILE_OK) { 4603 if (*error == base::PLATFORM_FILE_OK) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
4682 << resource_id 4642 << resource_id
4683 << ", md5=" << md5; 4643 << ", md5=" << md5;
4684 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 4644 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
4685 return; 4645 return;
4686 } 4646 }
4687 4647
4688 // Dirty files must be in persistent dir. 4648 // Dirty files must be in persistent dir.
4689 DCHECK_EQ(GDataCache::CACHE_TYPE_PERSISTENT, cache_entry->sub_dir_type); 4649 DCHECK_EQ(GDataCache::CACHE_TYPE_PERSISTENT, cache_entry->sub_dir_type);
4690 4650
4691 // Create symlink in outgoing dir. 4651 // Create symlink in outgoing dir.
4692 FilePath symlink_path = GetCacheFilePath( 4652 FilePath symlink_path = cache_->GetCacheFilePath(
4693 resource_id, 4653 resource_id,
4694 std::string(), 4654 std::string(),
4695 GDataCache::CACHE_TYPE_OUTGOING, 4655 GDataCache::CACHE_TYPE_OUTGOING,
4696 CACHED_FILE_FROM_SERVER); 4656 GDataCache::CACHED_FILE_FROM_SERVER);
4697 4657
4698 // Get target path of symlink i.e. current path of the file in cache. 4658 // Get target path of symlink i.e. current path of the file in cache.
4699 FilePath target_path = GetCacheFilePath(resource_id, 4659 FilePath target_path = cache_->GetCacheFilePath(
4700 md5, 4660 resource_id,
4701 cache_entry->sub_dir_type, 4661 md5,
4702 CACHED_FILE_LOCALLY_MODIFIED); 4662 cache_entry->sub_dir_type,
4663 GDataCache::CACHED_FILE_LOCALLY_MODIFIED);
4703 4664
4704 // Since there's no need to move files, use |target_path| for both 4665 // Since there's no need to move files, use |target_path| for both
4705 // |source_path| and |dest_path|, because ModifyCacheState only moves files 4666 // |source_path| and |dest_path|, because ModifyCacheState only moves files
4706 // if source and destination are different. 4667 // if source and destination are different.
4707 *error = ModifyCacheState(target_path, // source 4668 *error = ModifyCacheState(target_path, // source
4708 target_path, // destination 4669 target_path, // destination
4709 file_operation_type, 4670 file_operation_type,
4710 symlink_path, 4671 symlink_path,
4711 true /* create symlink */); 4672 true /* create symlink */);
4712 } 4673 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4744 << resource_id 4705 << resource_id
4745 << ", md5=" << md5; 4706 << ", md5=" << md5;
4746 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 4707 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
4747 return; 4708 return;
4748 } 4709 }
4749 4710
4750 // File must be dirty and hence in persistent dir. 4711 // File must be dirty and hence in persistent dir.
4751 DCHECK_EQ(GDataCache::CACHE_TYPE_PERSISTENT, cache_entry->sub_dir_type); 4712 DCHECK_EQ(GDataCache::CACHE_TYPE_PERSISTENT, cache_entry->sub_dir_type);
4752 4713
4753 // Get the current path of the file in cache. 4714 // Get the current path of the file in cache.
4754 FilePath source_path = GetCacheFilePath(resource_id, 4715 FilePath source_path = cache_->GetCacheFilePath(
4755 md5, 4716 resource_id,
4756 cache_entry->sub_dir_type, 4717 md5,
4757 CACHED_FILE_LOCALLY_MODIFIED); 4718 cache_entry->sub_dir_type,
4719 GDataCache::CACHED_FILE_LOCALLY_MODIFIED);
4758 4720
4759 // Determine destination path. 4721 // Determine destination path.
4760 // If file is pinned, move it to persistent dir with .md5 extension; 4722 // If file is pinned, move it to persistent dir with .md5 extension;
4761 // otherwise, move it to tmp dir with .md5 extension. 4723 // otherwise, move it to tmp dir with .md5 extension.
4762 GDataCache::CacheSubDirectoryType sub_dir_type = 4724 GDataCache::CacheSubDirectoryType sub_dir_type =
4763 cache_entry->IsPinned() ? GDataCache::CACHE_TYPE_PERSISTENT : 4725 cache_entry->IsPinned() ? GDataCache::CACHE_TYPE_PERSISTENT :
4764 GDataCache::CACHE_TYPE_TMP; 4726 GDataCache::CACHE_TYPE_TMP;
4765 FilePath dest_path = GetCacheFilePath(resource_id, 4727 FilePath dest_path = cache_->GetCacheFilePath(
4766 md5, 4728 resource_id,
4767 sub_dir_type, 4729 md5,
4768 CACHED_FILE_FROM_SERVER); 4730 sub_dir_type,
4731 GDataCache::CACHED_FILE_FROM_SERVER);
4769 4732
4770 // Delete symlink in outgoing dir. 4733 // Delete symlink in outgoing dir.
4771 FilePath symlink_path = GetCacheFilePath( 4734 FilePath symlink_path = cache_->GetCacheFilePath(
4772 resource_id, 4735 resource_id,
4773 std::string(), 4736 std::string(),
4774 GDataCache::CACHE_TYPE_OUTGOING, 4737 GDataCache::CACHE_TYPE_OUTGOING,
4775 CACHED_FILE_FROM_SERVER); 4738 GDataCache::CACHED_FILE_FROM_SERVER);
4776 4739
4777 *error = ModifyCacheState( 4740 *error = ModifyCacheState(
4778 source_path, 4741 source_path,
4779 dest_path, 4742 dest_path,
4780 file_operation_type, 4743 file_operation_type,
4781 symlink_path, 4744 symlink_path,
4782 false /* don't create symlink */); 4745 false /* don't create symlink */);
4783 4746
4784 // If file is pinned, update symlink in pinned dir. 4747 // If file is pinned, update symlink in pinned dir.
4785 if (*error == base::PLATFORM_FILE_OK && cache_entry->IsPinned()) { 4748 if (*error == base::PLATFORM_FILE_OK && cache_entry->IsPinned()) {
4786 symlink_path = GetCacheFilePath(resource_id, 4749 symlink_path = cache_->GetCacheFilePath(
4787 std::string(), 4750 resource_id,
4788 GDataCache::CACHE_TYPE_PINNED, 4751 std::string(),
4789 CACHED_FILE_FROM_SERVER); 4752 GDataCache::CACHE_TYPE_PINNED,
4753 GDataCache::CACHED_FILE_FROM_SERVER);
4790 4754
4791 // Since there's no moving of files here, use |dest_path| for both 4755 // Since there's no moving of files here, use |dest_path| for both
4792 // |source_path| and |dest_path|, because ModifyCacheState only moves files 4756 // |source_path| and |dest_path|, because ModifyCacheState only moves files
4793 // if source and destination are different. 4757 // if source and destination are different.
4794 *error = ModifyCacheState(dest_path, // source path 4758 *error = ModifyCacheState(dest_path, // source path
4795 dest_path, // destination path 4759 dest_path, // destination path
4796 file_operation_type, 4760 file_operation_type,
4797 symlink_path, 4761 symlink_path,
4798 true /* create symlink */); 4762 true /* create symlink */);
4799 } 4763 }
4800 4764
4801 if (*error == base::PLATFORM_FILE_OK) { 4765 if (*error == base::PLATFORM_FILE_OK) {
4802 // Now that file operations have completed, update cache map. 4766 // Now that file operations have completed, update cache map.
4803 int cache_state = GDataCache::ClearCacheDirty(cache_entry->cache_state); 4767 int cache_state = GDataCache::ClearCacheDirty(cache_entry->cache_state);
4804 cache_->UpdateCache(resource_id, md5, sub_dir_type, cache_state); 4768 cache_->UpdateCache(resource_id, md5, sub_dir_type, cache_state);
4805 } 4769 }
4806 } 4770 }
4807 4771
4808 void GDataFileSystem::RemoveFromCacheOnBlockingPool( 4772 void GDataFileSystem::RemoveFromCacheOnBlockingPool(
(...skipping 23 matching lines...) Expand all
4832 *error = base::PLATFORM_FILE_OK; 4796 *error = base::PLATFORM_FILE_OK;
4833 return; 4797 return;
4834 } 4798 }
4835 4799
4836 // Determine paths to delete all cache versions of |resource_id| in 4800 // Determine paths to delete all cache versions of |resource_id| in
4837 // persistent, tmp and pinned directories. 4801 // persistent, tmp and pinned directories.
4838 std::vector<FilePath> paths_to_delete; 4802 std::vector<FilePath> paths_to_delete;
4839 4803
4840 // For files in persistent and tmp dirs, delete files that match 4804 // For files in persistent and tmp dirs, delete files that match
4841 // "<resource_id>.*". 4805 // "<resource_id>.*".
4842 paths_to_delete.push_back(GetCacheFilePath( 4806 paths_to_delete.push_back(cache_->GetCacheFilePath(
4843 resource_id, 4807 resource_id,
4844 kWildCard, 4808 kWildCard,
4845 GDataCache::CACHE_TYPE_PERSISTENT, 4809 GDataCache::CACHE_TYPE_PERSISTENT,
4846 CACHED_FILE_FROM_SERVER)); 4810 GDataCache::CACHED_FILE_FROM_SERVER));
4847 paths_to_delete.push_back(GetCacheFilePath( 4811 paths_to_delete.push_back(cache_->GetCacheFilePath(
4848 resource_id, 4812 resource_id,
4849 kWildCard, 4813 kWildCard,
4850 GDataCache::CACHE_TYPE_TMP, 4814 GDataCache::CACHE_TYPE_TMP,
4851 CACHED_FILE_FROM_SERVER)); 4815 GDataCache::CACHED_FILE_FROM_SERVER));
4852 4816
4853 // For pinned files, filename is "<resource_id>" with no extension, so delete 4817 // For pinned files, filename is "<resource_id>" with no extension, so delete
4854 // "<resource_id>". 4818 // "<resource_id>".
4855 paths_to_delete.push_back(GetCacheFilePath( 4819 paths_to_delete.push_back(cache_->GetCacheFilePath(
4856 resource_id, 4820 resource_id,
4857 std::string(), 4821 std::string(),
4858 GDataCache::CACHE_TYPE_PINNED, 4822 GDataCache::CACHE_TYPE_PINNED,
4859 CACHED_FILE_FROM_SERVER)); 4823 GDataCache::CACHED_FILE_FROM_SERVER));
4860 4824
4861 // Don't delete locally modified (i.e. dirty and possibly outgoing) files. 4825 // Don't delete locally modified (i.e. dirty and possibly outgoing) files.
4862 // Since we're not deleting outgoing symlinks, we don't need to append 4826 // Since we're not deleting outgoing symlinks, we don't need to append
4863 // outgoing path to |paths_to_delete|. 4827 // outgoing path to |paths_to_delete|.
4864 FilePath path_to_keep = GetCacheFilePath( 4828 FilePath path_to_keep = cache_->GetCacheFilePath(
4865 resource_id, 4829 resource_id,
4866 std::string(), 4830 std::string(),
4867 GDataCache::CACHE_TYPE_PERSISTENT, 4831 GDataCache::CACHE_TYPE_PERSISTENT,
4868 CACHED_FILE_LOCALLY_MODIFIED); 4832 GDataCache::CACHED_FILE_LOCALLY_MODIFIED);
4869 4833
4870 for (size_t i = 0; i < paths_to_delete.size(); ++i) { 4834 for (size_t i = 0; i < paths_to_delete.size(); ++i) {
4871 DeleteFilesSelectively(paths_to_delete[i], path_to_keep); 4835 DeleteFilesSelectively(paths_to_delete[i], path_to_keep);
4872 } 4836 }
4873 4837
4874 // Now that all file operations have completed, remove from cache map. 4838 // Now that all file operations have completed, remove from cache map.
4875 cache_->RemoveFromCache(resource_id); 4839 cache_->RemoveFromCache(resource_id);
4876 4840
4877 *error = base::PLATFORM_FILE_OK; 4841 *error = base::PLATFORM_FILE_OK;
4878 } 4842 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
4957 // ignore this outgoing symlink and move on. 4921 // ignore this outgoing symlink and move on.
4958 GDataCache::CacheMap::iterator iter = 4922 GDataCache::CacheMap::iterator iter =
4959 cache_map->find(resource_id); 4923 cache_map->find(resource_id);
4960 if (iter != cache_map->end()) { // Entry exists, update dirty state. 4924 if (iter != cache_map->end()) { // Entry exists, update dirty state.
4961 iter->second.cache_state = 4925 iter->second.cache_state =
4962 GDataCache::SetCacheDirty(iter->second.cache_state); 4926 GDataCache::SetCacheDirty(iter->second.cache_state);
4963 } else { 4927 } else {
4964 NOTREACHED() << "Dirty cache file MUST have actual file blob"; 4928 NOTREACHED() << "Dirty cache file MUST have actual file blob";
4965 } 4929 }
4966 continue; 4930 continue;
4967 } else if (extra_extension == kMountedArchiveFileExtension) { 4931 } else if (extra_extension == GDataCache::kMountedArchiveFileExtension) {
4968 // Mounted archives in cache should be unmounted upon logout/shutdown. 4932 // Mounted archives in cache should be unmounted upon logout/shutdown.
4969 // But if we encounter a mounted file at start, delete it and create an 4933 // But if we encounter a mounted file at start, delete it and create an
4970 // entry with not PRESENT state. 4934 // entry with not PRESENT state.
4971 DCHECK(sub_dir_type == GDataCache::CACHE_TYPE_PERSISTENT); 4935 DCHECK(sub_dir_type == GDataCache::CACHE_TYPE_PERSISTENT);
4972 file_util::Delete(current, false); 4936 file_util::Delete(current, false);
4973 } else { 4937 } else {
4974 // Scanning other directories means that cache file is actually present. 4938 // Scanning other directories means that cache file is actually present.
4975 cache_state = GDataCache::SetCachePresent(cache_state); 4939 cache_state = GDataCache::SetCachePresent(cache_state);
4976 } 4940 }
4977 4941
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
5239 base::PlatformFileError error, 5203 base::PlatformFileError error,
5240 const std::string& resource_id, 5204 const std::string& resource_id,
5241 const std::string& md5) { 5205 const std::string& md5) {
5242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 5206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
5243 5207
5244 if (!callback.is_null()) 5208 if (!callback.is_null())
5245 callback.Run(error); 5209 callback.Run(error);
5246 } 5210 }
5247 5211
5248 } // namespace gdata 5212 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698