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

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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 const std::string& md5, 438 const std::string& md5,
438 const FilePath& gdata_file_path, 439 const FilePath& gdata_file_path,
439 FilePath* cache_file_path) { 440 FilePath* cache_file_path) {
440 DCHECK(error); 441 DCHECK(error);
441 DCHECK(cache_file_path); 442 DCHECK(cache_file_path);
442 443
443 if (!callback.is_null()) 444 if (!callback.is_null())
444 callback.Run(*error, resource_id, md5, gdata_file_path, *cache_file_path); 445 callback.Run(*error, resource_id, md5, gdata_file_path, *cache_file_path);
445 } 446 }
446 447
448 // Ditto for SetMountedStateCallback
449 void RunSetMountedStateCallbackHelper(
450 const SetMountedStateCallback& callback,
451 base::PlatformFileError* error,
452 FilePath* cache_file_path) {
453 DCHECK(error);
454 DCHECK(cache_file_path);
455
456 if (!callback.is_null())
457 callback.Run(*error, *cache_file_path);
458 }
459
447 void RunGetCacheStateCallbackHelper( 460 void RunGetCacheStateCallbackHelper(
448 const GetCacheStateCallback& callback, 461 const GetCacheStateCallback& callback,
449 base::PlatformFileError* error, 462 base::PlatformFileError* error,
450 int* cache_state) { 463 int* cache_state) {
451 DCHECK(error); 464 DCHECK(error);
452 DCHECK(cache_state); 465 DCHECK(cache_state);
453 466
454 if (!callback.is_null()) 467 if (!callback.is_null())
455 callback.Run(*error, *cache_state); 468 callback.Run(*error, *cache_state);
456 } 469 }
(...skipping 1401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 if (regular_file) { 1871 if (regular_file) {
1859 properties->file_md5 = regular_file->file_md5(); 1872 properties->file_md5 = regular_file->file_md5();
1860 properties->mime_type = regular_file->content_mime_type(); 1873 properties->mime_type = regular_file->content_mime_type();
1861 properties->content_url = regular_file->content_url(); 1874 properties->content_url = regular_file->content_url();
1862 properties->alternate_url = regular_file->alternate_url(); 1875 properties->alternate_url = regular_file->alternate_url();
1863 properties->is_hosted_document = regular_file->is_hosted_document(); 1876 properties->is_hosted_document = regular_file->is_hosted_document();
1864 } 1877 }
1865 return true; 1878 return true;
1866 } 1879 }
1867 1880
1881 bool GDataFileSystem::IsUnderGDataCacheDirectory(const FilePath& path) const {
1882 return gdata_cache_path_ == path || gdata_cache_path_.IsParent(path);
1883 }
1884
1868 FilePath GDataFileSystem::GetGDataCacheTmpDirectory() const { 1885 FilePath GDataFileSystem::GetGDataCacheTmpDirectory() const {
1869 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP]; 1886 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP];
1870 } 1887 }
1871 1888
1872 FilePath GDataFileSystem::GetGDataTempDownloadFolderPath() const { 1889 FilePath GDataFileSystem::GetGDataTempDownloadFolderPath() const {
1873 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP_DOWNLOADS]; 1890 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP_DOWNLOADS];
1874 } 1891 }
1875 1892
1876 FilePath GDataFileSystem::GetGDataTempDocumentFolderPath() const { 1893 FilePath GDataFileSystem::GetGDataTempDocumentFolderPath() const {
1877 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP_DOCUMENTS]; 1894 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP_DOCUMENTS];
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
2006 GetWeakPtrForCurrentThread(), 2023 GetWeakPtrForCurrentThread(),
2007 callback); 2024 callback);
2008 } 2025 }
2009 2026
2010 if (to_pin) 2027 if (to_pin)
2011 Pin(resource_id, md5, cache_callback); 2028 Pin(resource_id, md5, cache_callback);
2012 else 2029 else
2013 Unpin(resource_id, md5, cache_callback); 2030 Unpin(resource_id, md5, cache_callback);
2014 } 2031 }
2015 2032
2033 void GDataFileSystem::SetMountedState(const FilePath& file_path, bool to_mount,
2034 const SetMountedStateCallback& callback) {
2035 InitializeCacheIfNecessary();
2036
2037 base::PlatformFileError* error =
2038 new base::PlatformFileError(base::PLATFORM_FILE_OK);
2039 FilePath* cache_file_path = new FilePath;
2040 PostBlockingPoolSequencedTaskAndReply(
2041 kGDataFileSystemToken,
2042 FROM_HERE,
2043 base::Bind(&GDataFileSystem::SetMountedStateOnIOThreadPool,
2044 base::Unretained(this),
2045 file_path,
2046 to_mount,
2047 error,
2048 cache_file_path),
2049 base::Bind(&RunSetMountedStateCallbackHelper,
2050 callback,
2051 base::Owned(error),
2052 base::Owned(cache_file_path)));
2053 }
2054
2055 void GDataFileSystem::SetMountedStateOnIOThreadPool(
2056 const FilePath& file_path,
2057 bool to_mount,
2058 base::PlatformFileError *error,
2059 FilePath* cache_file_path) {
2060 DCHECK(error);
2061 DCHECK(cache_file_path);
2062
2063 // Lock to access cache map.
2064 base::AutoLock lock(lock_);
2065
2066 FilePath base_name = file_path.BaseName();
2067 FilePath::StringType resource_id = base_name.RemoveExtension().value();
2068 FilePath::StringType extension = base_name.Extension();
2069 FilePath::StringType md5 = FilePath::StringType();
2070 if (to_mount && !extension.empty()) {
2071 // FilePath::Extension returns ".", so strip it.
2072 md5 = GDataFileBase::UnescapeUtf8FileName(extension.substr(1));
2073 }
2074 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(resource_id,
2075 md5);
2076 if (!entry) {
2077 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND;
2078 return;
2079 } else if ((to_mount && entry->IsMounted()) ||
2080 (!to_mount && !entry->IsMounted())) {
2081 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
2082 return;
2083 } else {
2084 md5 = entry->md5;
2085 }
2086
2087 // Get subdir types for the unmounted and mounted state.
2088 GDataRootDirectory::CacheSubDirectoryType unmounted_subdir =
2089 entry->IsPinned() ? GDataRootDirectory::CACHE_TYPE_PERSISTENT :
2090 GDataRootDirectory::CACHE_TYPE_TMP;
2091 GDataRootDirectory::CacheSubDirectoryType mounted_subdir =
2092 GDataRootDirectory::CACHE_TYPE_PERSISTENT;
2093 // Gets path of the file if it were to be unmounted.
2094 FilePath unmounted_path = GetCacheFilePath(resource_id, md5, unmounted_subdir,
2095 CACHED_FILE_FROM_SERVER);
2096 // Gets path of the file if it were to be mounted.
2097 FilePath mounted_path = GetCacheFilePath(resource_id, md5, mounted_subdir,
2098 CACHED_FILE_MOUNTED);
2099 // Determine the source and destination paths for moving the cache blob.
2100 FilePath source_path;
2101 GDataRootDirectory::CacheSubDirectoryType dest_subdir;
2102 int cache_state = entry->cache_state;
2103 if (to_mount) {
2104 source_path = unmounted_path;
2105 *cache_file_path = mounted_path;
2106 dest_subdir = mounted_subdir;
2107 cache_state = GDataFile::SetCacheMounted(cache_state);
2108 } else {
2109 source_path = mounted_path;
2110 *cache_file_path = unmounted_path;
2111 dest_subdir = unmounted_subdir;
2112 cache_state = GDataFile::ClearCacheMounted(cache_state);
2113 }
2114 // Move cache blob from source path to destination path.
2115 *error = ModifyCacheState(source_path, *cache_file_path,
2116 GDataFileSystem::FILE_OPERATION_MOVE, FilePath(),
2117 false);
2118 if (*error == base::PLATFORM_FILE_OK) {
2119 // Now that cache operation is complete, update cache map
2120 root_->UpdateCacheMap(resource_id, md5, dest_subdir, cache_state);
2121 }
2122 }
2123
2016 void GDataFileSystem::OnSetPinStateCompleted( 2124 void GDataFileSystem::OnSetPinStateCompleted(
2017 const FileOperationCallback& callback, 2125 const FileOperationCallback& callback,
2018 base::PlatformFileError error, 2126 base::PlatformFileError error,
2019 const std::string& resource_id, 2127 const std::string& resource_id,
2020 const std::string& md5) { 2128 const std::string& md5) {
2021 callback.Run(error); 2129 callback.Run(error);
2022 } 2130 }
2023 2131
2024 void GDataFileSystem::OnGetAvailableSpace( 2132 void GDataFileSystem::OnGetAvailableSpace(
2025 const GetAvailableSpaceCallback& callback, 2133 const GetAvailableSpaceCallback& callback,
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after
3177 DCHECK(sub_dir_type != GDataRootDirectory::CACHE_TYPE_META); 3285 DCHECK(sub_dir_type != GDataRootDirectory::CACHE_TYPE_META);
3178 3286
3179 // Runs on any thread. 3287 // Runs on any thread.
3180 // Filename is formatted as resource_id.md5, i.e. resource_id is the base 3288 // Filename is formatted as resource_id.md5, i.e. resource_id is the base
3181 // name and md5 is the extension. 3289 // name and md5 is the extension.
3182 std::string base_name = GDataFileBase::EscapeUtf8FileName(resource_id); 3290 std::string base_name = GDataFileBase::EscapeUtf8FileName(resource_id);
3183 if (file_origin == CACHED_FILE_LOCALLY_MODIFIED) { 3291 if (file_origin == CACHED_FILE_LOCALLY_MODIFIED) {
3184 DCHECK(sub_dir_type == GDataRootDirectory::CACHE_TYPE_PERSISTENT); 3292 DCHECK(sub_dir_type == GDataRootDirectory::CACHE_TYPE_PERSISTENT);
3185 base_name += FilePath::kExtensionSeparator; 3293 base_name += FilePath::kExtensionSeparator;
3186 base_name += kLocallyModifiedFileExtension; 3294 base_name += kLocallyModifiedFileExtension;
3295 } else if (file_origin == CACHED_FILE_MOUNTED) {
3296 DCHECK(sub_dir_type == GDataRootDirectory::CACHE_TYPE_PERSISTENT);
3297 base_name += FilePath::kExtensionSeparator;
3298 base_name += kMountedArchiveFileExtension;
3187 } else if (!md5.empty()) { 3299 } else if (!md5.empty()) {
3188 base_name += FilePath::kExtensionSeparator; 3300 base_name += FilePath::kExtensionSeparator;
3189 base_name += GDataFileBase::EscapeUtf8FileName(md5); 3301 base_name += GDataFileBase::EscapeUtf8FileName(md5);
3190 } 3302 }
3191 return cache_paths_[sub_dir_type].Append(base_name); 3303 return cache_paths_[sub_dir_type].Append(base_name);
3192 } 3304 }
3193 3305
3194 void GDataFileSystem::GetFromCache(const std::string& resource_id, 3306 void GDataFileSystem::GetFromCache(const std::string& resource_id,
3195 const std::string& md5, 3307 const std::string& md5,
3196 const GetFromCacheCallback& callback) { 3308 const GetFromCacheCallback& callback) {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
3419 FilePath* cache_file_path) { 3531 FilePath* cache_file_path) {
3420 DCHECK(error); 3532 DCHECK(error);
3421 DCHECK(cache_file_path); 3533 DCHECK(cache_file_path);
3422 3534
3423 // Lock to access cache map. 3535 // Lock to access cache map.
3424 base::AutoLock lock(lock_); 3536 base::AutoLock lock(lock_);
3425 3537
3426 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(resource_id, 3538 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(resource_id,
3427 md5); 3539 md5);
3428 if (entry && entry->IsPresent()) { 3540 if (entry && entry->IsPresent()) {
3541 CachedFileOrigin file_origin;
3542 if (entry->IsMounted()) {
3543 file_origin = CACHED_FILE_MOUNTED;
3544 } else if (entry->IsDirty()) {
3545 file_origin = CACHED_FILE_LOCALLY_MODIFIED;
3546 } else {
3547 file_origin = CACHED_FILE_FROM_SERVER;
3548 }
3429 *cache_file_path = GetCacheFilePath( 3549 *cache_file_path = GetCacheFilePath(
3430 resource_id, 3550 resource_id,
3431 md5, 3551 md5,
3432 entry->sub_dir_type, 3552 entry->sub_dir_type,
3433 entry->IsDirty() ? CACHED_FILE_LOCALLY_MODIFIED : 3553 file_origin);
3434 CACHED_FILE_FROM_SERVER);
3435 *error = base::PLATFORM_FILE_OK; 3554 *error = base::PLATFORM_FILE_OK;
3436 } else { 3555 } else {
3437 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; 3556 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND;
3438 } 3557 }
3439 } 3558 }
3440 3559
3441 void GDataFileSystem::GetCacheStateOnIOThreadPool( 3560 void GDataFileSystem::GetCacheStateOnIOThreadPool(
3442 const std::string& resource_id, 3561 const std::string& resource_id,
3443 const std::string& md5, 3562 const std::string& md5,
3444 base::PlatformFileError* error, 3563 base::PlatformFileError* error,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
3481 int cache_state = GDataFile::CACHE_STATE_PRESENT; 3600 int cache_state = GDataFile::CACHE_STATE_PRESENT;
3482 GDataRootDirectory::CacheSubDirectoryType sub_dir_type = 3601 GDataRootDirectory::CacheSubDirectoryType sub_dir_type =
3483 GDataRootDirectory::CACHE_TYPE_TMP; 3602 GDataRootDirectory::CACHE_TYPE_TMP;
3484 3603
3485 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry( 3604 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(
3486 resource_id, md5); 3605 resource_id, md5);
3487 3606
3488 // If file was previously pinned, store it in persistent dir and create 3607 // If file was previously pinned, store it in persistent dir and create
3489 // symlink in pinned dir. 3608 // symlink in pinned dir.
3490 if (entry) { // File exists in cache. 3609 if (entry) { // File exists in cache.
3491 // If file is dirty, return error. 3610 // If file is dirty or mounted, return error.
3492 if (entry->IsDirty()) { 3611 if (entry->IsDirty() || entry->IsMounted()) {
3493 LOG(WARNING) << "Can't store a file to replace a dirty file: res_id=" 3612 LOG(WARNING) << "Can't store a file to replace a "
3494 << resource_id 3613 << (entry->IsDirty() ? "dirty" : "mounted")
3614 << " file: res_id=" << resource_id
3495 << ", md5=" << md5; 3615 << ", md5=" << md5;
3496 *error = base::PLATFORM_FILE_ERROR_IN_USE; 3616 *error = base::PLATFORM_FILE_ERROR_IN_USE;
3497 return; 3617 return;
3498 } 3618 }
3499 3619
3500 cache_state |= entry->cache_state; 3620 cache_state |= entry->cache_state;
3501 3621
3502 // If file is pinned, determines destination path. 3622 // If file is pinned, determines destination path.
3503 if (entry->IsPinned()) { 3623 if (entry->IsPinned()) {
3504 sub_dir_type = GDataRootDirectory::CACHE_TYPE_PERSISTENT; 3624 sub_dir_type = GDataRootDirectory::CACHE_TYPE_PERSISTENT;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
3583 3703
3584 // Set sub_dir_type to PINNED to indicate that the file doesn't exist. 3704 // Set sub_dir_type to PINNED to indicate that the file doesn't exist.
3585 // When the file is finally downloaded and StoreToCache called, it will be 3705 // When the file is finally downloaded and StoreToCache called, it will be
3586 // moved to persistent directory. 3706 // moved to persistent directory.
3587 sub_dir_type = GDataRootDirectory::CACHE_TYPE_PINNED; 3707 sub_dir_type = GDataRootDirectory::CACHE_TYPE_PINNED;
3588 } else { // File exists in cache, determines destination path. 3708 } else { // File exists in cache, determines destination path.
3589 cache_state |= entry->cache_state; 3709 cache_state |= entry->cache_state;
3590 3710
3591 // Determine source and destination paths. 3711 // Determine source and destination paths.
3592 3712
3593 // If file is dirty, don't move it, so determine |dest_path| and set 3713 // If file is dirty or mounted, don't move it, so determine |dest_path| and
3594 // |source_path| the same, because ModifyCacheState only moves files if 3714 // set |source_path| the same, because ModifyCacheState only moves files if
3595 // source and destination are different. 3715 // source and destination are different.
3596 if (entry->IsDirty()) { 3716 if (entry->IsDirty() || entry->IsMounted()) {
3597 DCHECK_EQ(GDataRootDirectory::CACHE_TYPE_PERSISTENT, entry->sub_dir_type); 3717 DCHECK_EQ(GDataRootDirectory::CACHE_TYPE_PERSISTENT, entry->sub_dir_type);
3598 dest_path = GetCacheFilePath(resource_id, 3718 dest_path = GetCacheFilePath(resource_id,
3599 md5, 3719 md5,
3600 entry->sub_dir_type, 3720 entry->sub_dir_type,
3601 CACHED_FILE_LOCALLY_MODIFIED); 3721 CACHED_FILE_LOCALLY_MODIFIED);
3602 source_path = dest_path; 3722 source_path = dest_path;
3603 } else { 3723 } else {
3604 // Gets the current path of the file in cache. 3724 // Gets the current path of the file in cache.
3605 source_path = GetCacheFilePath(resource_id, 3725 source_path = GetCacheFilePath(resource_id,
3606 md5, 3726 md5,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
3666 return; 3786 return;
3667 } 3787 }
3668 3788
3669 // Entry exists in cache, determines source and destination paths. 3789 // Entry exists in cache, determines source and destination paths.
3670 3790
3671 FilePath source_path; 3791 FilePath source_path;
3672 FilePath dest_path; 3792 FilePath dest_path;
3673 GDataRootDirectory::CacheSubDirectoryType sub_dir_type = 3793 GDataRootDirectory::CacheSubDirectoryType sub_dir_type =
3674 GDataRootDirectory::CACHE_TYPE_TMP; 3794 GDataRootDirectory::CACHE_TYPE_TMP;
3675 3795
3676 // If file is dirty, don't move it, so determine |dest_path| and set 3796 // If file is dirty or mounted, don't move it, so determine |dest_path| and
3677 // |source_path| the same, because ModifyCacheState moves files if source 3797 // set |source_path| the same, because ModifyCacheState moves files if source
3678 // and destination are different. 3798 // and destination are different.
3679 if (entry->IsDirty()) { 3799 if (entry->IsDirty() || entry->IsMounted()) {
3680 sub_dir_type = GDataRootDirectory::CACHE_TYPE_PERSISTENT; 3800 sub_dir_type = GDataRootDirectory::CACHE_TYPE_PERSISTENT;
3681 DCHECK_EQ(sub_dir_type, entry->sub_dir_type); 3801 DCHECK_EQ(sub_dir_type, entry->sub_dir_type);
3682 dest_path = GetCacheFilePath(resource_id, 3802 dest_path = GetCacheFilePath(resource_id,
3683 md5, 3803 md5,
3684 entry->sub_dir_type, 3804 entry->sub_dir_type,
3685 CACHED_FILE_LOCALLY_MODIFIED); 3805 CACHED_FILE_LOCALLY_MODIFIED);
3686 source_path = dest_path; 3806 source_path = dest_path;
3687 } else { 3807 } else {
3688 // Gets the current path of the file in cache. 3808 // Gets the current path of the file in cache.
3689 source_path = GetCacheFilePath(resource_id, 3809 source_path = GetCacheFilePath(resource_id,
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
4001 // Lock to access cache map. 4121 // Lock to access cache map.
4002 base::AutoLock lock(lock_); 4122 base::AutoLock lock(lock_);
4003 4123
4004 // MD5 is not passed into RemoveFromCache and hence 4124 // MD5 is not passed into RemoveFromCache and hence
4005 // RemoveFromCacheOnIOThreadPool, because we would delete all cache files 4125 // RemoveFromCacheOnIOThreadPool, because we would delete all cache files
4006 // corresponding to <resource_id> regardless of the md5. 4126 // corresponding to <resource_id> regardless of the md5.
4007 // So, search for entry in cache without taking md5 into account. 4127 // So, search for entry in cache without taking md5 into account.
4008 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry( 4128 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(
4009 resource_id, std::string()); 4129 resource_id, std::string());
4010 4130
4011 // If entry doesn't exist or is dirty in cache, nothing to do. 4131 // If entry doesn't exist or is dirty or mounted in cache, nothing to do.
4012 if (!entry || entry->IsDirty()) { 4132 if (!entry || entry->IsDirty() || entry->IsMounted()) {
4013 DVLOG(1) << "Entry " << (entry ? "is dirty" : "doesn't exist") 4133 DVLOG(1) << "Entry "
4134 << (entry ? (entry->IsDirty() ? "is dirty" : "is mounted") :
4135 "doesn't exist")
4014 << " in cache, not removing"; 4136 << " in cache, not removing";
4015 *error = base::PLATFORM_FILE_OK; 4137 *error = base::PLATFORM_FILE_OK;
4016 return; 4138 return;
4017 } 4139 }
4018 4140
4019 // Determine paths to delete all cache versions of |resource_id| in 4141 // Determine paths to delete all cache versions of |resource_id| in
4020 // persistent, tmp and pinned directories. 4142 // persistent, tmp and pinned directories.
4021 std::vector<FilePath> paths_to_delete; 4143 std::vector<FilePath> paths_to_delete;
4022 4144
4023 // For files in persistent and tmp dirs, delete files that match 4145 // For files in persistent and tmp dirs, delete files that match
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
4282 pref_registrar_->Init(profile_->GetPrefs()); 4404 pref_registrar_->Init(profile_->GetPrefs());
4283 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); 4405 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this);
4284 } 4406 }
4285 4407
4286 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 4408 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
4287 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 4409 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
4288 global_free_disk_getter_for_testing = getter; 4410 global_free_disk_getter_for_testing = getter;
4289 } 4411 }
4290 4412
4291 } // namespace gdata 4413 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698