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

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

Issue 10116044: gdata: Support mounting archive files 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 (!extension.empty()) {
2071 // FilePath::Extension returns ".", so strip it.
2072 md5 = GDataFileBase::UnescapeUtf8FileName(extension.substr(1));
2073 if (md5.compare(kMountedArchiveFileExtension) == 0) {
kuan 2012/04/19 21:02:15 i'm wondering if u can just do md5 == kMountedArch
2074 // Files that are already mounted will not have a md5 extension
2075 md5 = FilePath::StringType();
2076 }
2077 }
2078 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(resource_id,
2079 md5);
2080 if (!entry) {
2081 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND;
2082 return;
2083 }
2084 if (to_mount == entry->IsMounted()) {
2085 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
2086 return;
2087 }
2088
2089 md5 = entry->md5;
2090 // Get subdir types for the unmounted and mounted state.
2091 GDataRootDirectory::CacheSubDirectoryType unmounted_subdir =
2092 entry->IsPinned() ? GDataRootDirectory::CACHE_TYPE_PERSISTENT :
2093 GDataRootDirectory::CACHE_TYPE_TMP;
2094 GDataRootDirectory::CacheSubDirectoryType mounted_subdir =
2095 GDataRootDirectory::CACHE_TYPE_PERSISTENT;
2096 // Gets path of the file if it were to be unmounted.
2097 FilePath unmounted_path = GetCacheFilePath(resource_id, md5, unmounted_subdir,
2098 CACHED_FILE_FROM_SERVER);
2099 // Gets path of the file if it were to be mounted.
2100 FilePath mounted_path = GetCacheFilePath(resource_id, md5, mounted_subdir,
2101 CACHED_FILE_MOUNTED);
2102
2103 // Determine the source and destination paths for moving the cache blob.
2104 FilePath source_path;
2105 GDataRootDirectory::CacheSubDirectoryType dest_subdir;
2106 int cache_state = entry->cache_state;
2107 if (to_mount) {
2108 source_path = unmounted_path;
2109 *cache_file_path = mounted_path;
2110 dest_subdir = mounted_subdir;
2111 cache_state = GDataFile::SetCacheMounted(cache_state);
2112 } else {
2113 source_path = mounted_path;
2114 *cache_file_path = unmounted_path;
2115 dest_subdir = unmounted_subdir;
2116 cache_state = GDataFile::ClearCacheMounted(cache_state);
2117 }
2118
2119 // Copy/move cache blob from source path to destination path.
2120 // When mounting, make a copy so the original blob persists after shutdown
2121 // When unmounting, move the file back to replace the original blob
kuan 2012/04/19 21:01:09 maybe comment that u're moving in case it was evic
2122 *error = ModifyCacheState(source_path, *cache_file_path,
2123 to_mount ? GDataFileSystem::FILE_OPERATION_COPY :
2124 GDataFileSystem::FILE_OPERATION_MOVE,
2125 FilePath(), false);
2126 if (*error == base::PLATFORM_FILE_OK) {
2127 // Now that cache operation is complete, update cache map
2128 root_->UpdateCacheMap(resource_id, md5, dest_subdir, cache_state);
2129 }
2130 }
2131
2016 void GDataFileSystem::OnSetPinStateCompleted( 2132 void GDataFileSystem::OnSetPinStateCompleted(
2017 const FileOperationCallback& callback, 2133 const FileOperationCallback& callback,
2018 base::PlatformFileError error, 2134 base::PlatformFileError error,
2019 const std::string& resource_id, 2135 const std::string& resource_id,
2020 const std::string& md5) { 2136 const std::string& md5) {
2021 callback.Run(error); 2137 callback.Run(error);
2022 } 2138 }
2023 2139
2024 void GDataFileSystem::OnGetAvailableSpace( 2140 void GDataFileSystem::OnGetAvailableSpace(
2025 const GetAvailableSpaceCallback& callback, 2141 const GetAvailableSpaceCallback& callback,
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after
3177 DCHECK(sub_dir_type != GDataRootDirectory::CACHE_TYPE_META); 3293 DCHECK(sub_dir_type != GDataRootDirectory::CACHE_TYPE_META);
3178 3294
3179 // Runs on any thread. 3295 // Runs on any thread.
3180 // Filename is formatted as resource_id.md5, i.e. resource_id is the base 3296 // Filename is formatted as resource_id.md5, i.e. resource_id is the base
3181 // name and md5 is the extension. 3297 // name and md5 is the extension.
3182 std::string base_name = GDataFileBase::EscapeUtf8FileName(resource_id); 3298 std::string base_name = GDataFileBase::EscapeUtf8FileName(resource_id);
3183 if (file_origin == CACHED_FILE_LOCALLY_MODIFIED) { 3299 if (file_origin == CACHED_FILE_LOCALLY_MODIFIED) {
3184 DCHECK(sub_dir_type == GDataRootDirectory::CACHE_TYPE_PERSISTENT); 3300 DCHECK(sub_dir_type == GDataRootDirectory::CACHE_TYPE_PERSISTENT);
3185 base_name += FilePath::kExtensionSeparator; 3301 base_name += FilePath::kExtensionSeparator;
3186 base_name += kLocallyModifiedFileExtension; 3302 base_name += kLocallyModifiedFileExtension;
3303 } else if (file_origin == CACHED_FILE_MOUNTED) {
3304 DCHECK(sub_dir_type == GDataRootDirectory::CACHE_TYPE_PERSISTENT);
3305 base_name += FilePath::kExtensionSeparator;
3306 base_name += kMountedArchiveFileExtension;
3187 } else if (!md5.empty()) { 3307 } else if (!md5.empty()) {
3188 base_name += FilePath::kExtensionSeparator; 3308 base_name += FilePath::kExtensionSeparator;
3189 base_name += GDataFileBase::EscapeUtf8FileName(md5); 3309 base_name += GDataFileBase::EscapeUtf8FileName(md5);
3190 } 3310 }
3191 return cache_paths_[sub_dir_type].Append(base_name); 3311 return cache_paths_[sub_dir_type].Append(base_name);
3192 } 3312 }
3193 3313
3194 void GDataFileSystem::GetFromCache(const std::string& resource_id, 3314 void GDataFileSystem::GetFromCache(const std::string& resource_id,
3195 const std::string& md5, 3315 const std::string& md5,
3196 const GetFromCacheCallback& callback) { 3316 const GetFromCacheCallback& callback) {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
3419 FilePath* cache_file_path) { 3539 FilePath* cache_file_path) {
3420 DCHECK(error); 3540 DCHECK(error);
3421 DCHECK(cache_file_path); 3541 DCHECK(cache_file_path);
3422 3542
3423 // Lock to access cache map. 3543 // Lock to access cache map.
3424 base::AutoLock lock(lock_); 3544 base::AutoLock lock(lock_);
3425 3545
3426 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(resource_id, 3546 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(resource_id,
3427 md5); 3547 md5);
3428 if (entry && entry->IsPresent()) { 3548 if (entry && entry->IsPresent()) {
3549 CachedFileOrigin file_origin;
3550 if (entry->IsMounted()) {
3551 file_origin = CACHED_FILE_MOUNTED;
3552 } else if (entry->IsDirty()) {
3553 file_origin = CACHED_FILE_LOCALLY_MODIFIED;
3554 } else {
3555 file_origin = CACHED_FILE_FROM_SERVER;
3556 }
3429 *cache_file_path = GetCacheFilePath( 3557 *cache_file_path = GetCacheFilePath(
3430 resource_id, 3558 resource_id,
3431 md5, 3559 md5,
3432 entry->sub_dir_type, 3560 entry->sub_dir_type,
3433 entry->IsDirty() ? CACHED_FILE_LOCALLY_MODIFIED : 3561 file_origin);
3434 CACHED_FILE_FROM_SERVER);
3435 *error = base::PLATFORM_FILE_OK; 3562 *error = base::PLATFORM_FILE_OK;
3436 } else { 3563 } else {
3437 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; 3564 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND;
3438 } 3565 }
3439 } 3566 }
3440 3567
3441 void GDataFileSystem::GetCacheStateOnIOThreadPool( 3568 void GDataFileSystem::GetCacheStateOnIOThreadPool(
3442 const std::string& resource_id, 3569 const std::string& resource_id,
3443 const std::string& md5, 3570 const std::string& md5,
3444 base::PlatformFileError* error, 3571 base::PlatformFileError* error,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
3481 int cache_state = GDataFile::CACHE_STATE_PRESENT; 3608 int cache_state = GDataFile::CACHE_STATE_PRESENT;
3482 GDataRootDirectory::CacheSubDirectoryType sub_dir_type = 3609 GDataRootDirectory::CacheSubDirectoryType sub_dir_type =
3483 GDataRootDirectory::CACHE_TYPE_TMP; 3610 GDataRootDirectory::CACHE_TYPE_TMP;
3484 3611
3485 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry( 3612 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(
3486 resource_id, md5); 3613 resource_id, md5);
3487 3614
3488 // If file was previously pinned, store it in persistent dir and create 3615 // If file was previously pinned, store it in persistent dir and create
3489 // symlink in pinned dir. 3616 // symlink in pinned dir.
3490 if (entry) { // File exists in cache. 3617 if (entry) { // File exists in cache.
3491 // If file is dirty, return error. 3618 // If file is dirty or mounted, return error.
3492 if (entry->IsDirty()) { 3619 if (entry->IsDirty() || entry->IsMounted()) {
3493 LOG(WARNING) << "Can't store a file to replace a dirty file: res_id=" 3620 LOG(WARNING) << "Can't store a file to replace a "
3494 << resource_id 3621 << (entry->IsDirty() ? "dirty" : "mounted")
3622 << " file: res_id=" << resource_id
3495 << ", md5=" << md5; 3623 << ", md5=" << md5;
3496 *error = base::PLATFORM_FILE_ERROR_IN_USE; 3624 *error = base::PLATFORM_FILE_ERROR_IN_USE;
3497 return; 3625 return;
3498 } 3626 }
3499 3627
3500 cache_state |= entry->cache_state; 3628 cache_state |= entry->cache_state;
3501 3629
3502 // If file is pinned, determines destination path. 3630 // If file is pinned, determines destination path.
3503 if (entry->IsPinned()) { 3631 if (entry->IsPinned()) {
3504 sub_dir_type = GDataRootDirectory::CACHE_TYPE_PERSISTENT; 3632 sub_dir_type = GDataRootDirectory::CACHE_TYPE_PERSISTENT;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
3583 3711
3584 // Set sub_dir_type to PINNED to indicate that the file doesn't exist. 3712 // 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 3713 // When the file is finally downloaded and StoreToCache called, it will be
3586 // moved to persistent directory. 3714 // moved to persistent directory.
3587 sub_dir_type = GDataRootDirectory::CACHE_TYPE_PINNED; 3715 sub_dir_type = GDataRootDirectory::CACHE_TYPE_PINNED;
3588 } else { // File exists in cache, determines destination path. 3716 } else { // File exists in cache, determines destination path.
3589 cache_state |= entry->cache_state; 3717 cache_state |= entry->cache_state;
3590 3718
3591 // Determine source and destination paths. 3719 // Determine source and destination paths.
3592 3720
3593 // If file is dirty, don't move it, so determine |dest_path| and set 3721 // 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 3722 // set |source_path| the same, because ModifyCacheState only moves files if
3595 // source and destination are different. 3723 // source and destination are different.
3596 if (entry->IsDirty()) { 3724 if (entry->IsDirty() || entry->IsMounted()) {
3597 DCHECK_EQ(GDataRootDirectory::CACHE_TYPE_PERSISTENT, entry->sub_dir_type); 3725 DCHECK_EQ(GDataRootDirectory::CACHE_TYPE_PERSISTENT, entry->sub_dir_type);
3598 dest_path = GetCacheFilePath(resource_id, 3726 dest_path = GetCacheFilePath(resource_id,
3599 md5, 3727 md5,
3600 entry->sub_dir_type, 3728 entry->sub_dir_type,
3601 CACHED_FILE_LOCALLY_MODIFIED); 3729 CACHED_FILE_LOCALLY_MODIFIED);
3602 source_path = dest_path; 3730 source_path = dest_path;
3603 } else { 3731 } else {
3604 // Gets the current path of the file in cache. 3732 // Gets the current path of the file in cache.
3605 source_path = GetCacheFilePath(resource_id, 3733 source_path = GetCacheFilePath(resource_id,
3606 md5, 3734 md5,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
3666 return; 3794 return;
3667 } 3795 }
3668 3796
3669 // Entry exists in cache, determines source and destination paths. 3797 // Entry exists in cache, determines source and destination paths.
3670 3798
3671 FilePath source_path; 3799 FilePath source_path;
3672 FilePath dest_path; 3800 FilePath dest_path;
3673 GDataRootDirectory::CacheSubDirectoryType sub_dir_type = 3801 GDataRootDirectory::CacheSubDirectoryType sub_dir_type =
3674 GDataRootDirectory::CACHE_TYPE_TMP; 3802 GDataRootDirectory::CACHE_TYPE_TMP;
3675 3803
3676 // If file is dirty, don't move it, so determine |dest_path| and set 3804 // 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 3805 // set |source_path| the same, because ModifyCacheState moves files if source
3678 // and destination are different. 3806 // and destination are different.
3679 if (entry->IsDirty()) { 3807 if (entry->IsDirty() || entry->IsMounted()) {
3680 sub_dir_type = GDataRootDirectory::CACHE_TYPE_PERSISTENT; 3808 sub_dir_type = GDataRootDirectory::CACHE_TYPE_PERSISTENT;
3681 DCHECK_EQ(sub_dir_type, entry->sub_dir_type); 3809 DCHECK_EQ(sub_dir_type, entry->sub_dir_type);
3682 dest_path = GetCacheFilePath(resource_id, 3810 dest_path = GetCacheFilePath(resource_id,
3683 md5, 3811 md5,
3684 entry->sub_dir_type, 3812 entry->sub_dir_type,
3685 CACHED_FILE_LOCALLY_MODIFIED); 3813 CACHED_FILE_LOCALLY_MODIFIED);
3686 source_path = dest_path; 3814 source_path = dest_path;
3687 } else { 3815 } else {
3688 // Gets the current path of the file in cache. 3816 // Gets the current path of the file in cache.
3689 source_path = GetCacheFilePath(resource_id, 3817 source_path = GetCacheFilePath(resource_id,
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
4001 // Lock to access cache map. 4129 // Lock to access cache map.
4002 base::AutoLock lock(lock_); 4130 base::AutoLock lock(lock_);
4003 4131
4004 // MD5 is not passed into RemoveFromCache and hence 4132 // MD5 is not passed into RemoveFromCache and hence
4005 // RemoveFromCacheOnIOThreadPool, because we would delete all cache files 4133 // RemoveFromCacheOnIOThreadPool, because we would delete all cache files
4006 // corresponding to <resource_id> regardless of the md5. 4134 // corresponding to <resource_id> regardless of the md5.
4007 // So, search for entry in cache without taking md5 into account. 4135 // So, search for entry in cache without taking md5 into account.
4008 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry( 4136 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(
4009 resource_id, std::string()); 4137 resource_id, std::string());
4010 4138
4011 // If entry doesn't exist or is dirty in cache, nothing to do. 4139 // If entry doesn't exist or is dirty or mounted in cache, nothing to do.
4012 if (!entry || entry->IsDirty()) { 4140 if (!entry || entry->IsDirty() || entry->IsMounted()) {
4013 DVLOG(1) << "Entry " << (entry ? "is dirty" : "doesn't exist") 4141 DVLOG(1) << "Entry is "
4142 << (entry ? (entry->IsDirty() ? "dirty" : "mounted") :
4143 "non-existent")
4014 << " in cache, not removing"; 4144 << " in cache, not removing";
4015 *error = base::PLATFORM_FILE_OK; 4145 *error = base::PLATFORM_FILE_OK;
4016 return; 4146 return;
4017 } 4147 }
4018 4148
4019 // Determine paths to delete all cache versions of |resource_id| in 4149 // Determine paths to delete all cache versions of |resource_id| in
4020 // persistent, tmp and pinned directories. 4150 // persistent, tmp and pinned directories.
4021 std::vector<FilePath> paths_to_delete; 4151 std::vector<FilePath> paths_to_delete;
4022 4152
4023 // For files in persistent and tmp dirs, delete files that match 4153 // For files in persistent and tmp dirs, delete files that match
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
4173 // ignore this outgoing symlink and move on. 4303 // ignore this outgoing symlink and move on.
4174 GDataRootDirectory::CacheMap::iterator iter = 4304 GDataRootDirectory::CacheMap::iterator iter =
4175 cache_map->find(resource_id); 4305 cache_map->find(resource_id);
4176 if (iter != cache_map->end()) { // Entry exists, update dirty state. 4306 if (iter != cache_map->end()) { // Entry exists, update dirty state.
4177 GDataRootDirectory::CacheEntry* entry = iter->second; 4307 GDataRootDirectory::CacheEntry* entry = iter->second;
4178 entry->cache_state = GDataFile::SetCacheDirty(entry->cache_state); 4308 entry->cache_state = GDataFile::SetCacheDirty(entry->cache_state);
4179 } else { 4309 } else {
4180 NOTREACHED() << "Dirty cache file MUST have actual file blob"; 4310 NOTREACHED() << "Dirty cache file MUST have actual file blob";
4181 } 4311 }
4182 continue; 4312 continue;
4313 } else if (sub_dir_type == GDataRootDirectory::CACHE_TYPE_PERSISTENT &&
4314 md5.compare(kMountedArchiveFileExtension) == 0) {
4315 // Mounted archives in cache should be unmounted upon logout/shutdown.
4316 // If we encounter a mounted file at start, discard it and move on.
4317 file_util::Delete(current, false);
4318 continue;
4183 } else { 4319 } else {
4184 // Scanning other directories means that cache file is actually present. 4320 // Scanning other directories means that cache file is actually present.
4185 cache_state = GDataFile::SetCachePresent(cache_state); 4321 cache_state = GDataFile::SetCachePresent(cache_state);
4186 } 4322 }
4187 4323
4188 // Create and insert new entry into cache map. 4324 // Create and insert new entry into cache map.
4189 GDataRootDirectory::CacheEntry* entry = new GDataRootDirectory::CacheEntry( 4325 GDataRootDirectory::CacheEntry* entry = new GDataRootDirectory::CacheEntry(
4190 md5, sub_dir_type, cache_state); 4326 md5, sub_dir_type, cache_state);
4191 cache_map->insert(std::make_pair(resource_id, entry)); 4327 cache_map->insert(std::make_pair(resource_id, entry));
4192 } 4328 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
4282 pref_registrar_->Init(profile_->GetPrefs()); 4418 pref_registrar_->Init(profile_->GetPrefs());
4283 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); 4419 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this);
4284 } 4420 }
4285 4421
4286 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 4422 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
4287 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 4423 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
4288 global_free_disk_getter_for_testing = getter; 4424 global_free_disk_getter_for_testing = getter;
4289 } 4425 }
4290 4426
4291 } // namespace gdata 4427 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_files.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698