OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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) { | |
Ben Chan
2012/04/18 19:38:14
DCHECK(error);
DCHECK(cache_file_path);
hshi
2012/04/18 19:46:43
Oops sorry forgot to check this. Patch set #9 uplo
| |
2060 base::AutoLock lock(lock_); // To access the cache map. | |
2061 | |
2062 FilePath base_name = file_path.BaseName(); | |
2063 FilePath::StringType resource_id = base_name.RemoveExtension().value(); | |
2064 FilePath::StringType extension = base_name.Extension(); | |
2065 FilePath::StringType md5 = FilePath::StringType(); | |
2066 if (to_mount && !extension.empty()) { | |
2067 // FilePath::Extension returns ".", so strip it. | |
2068 md5 = GDataFileBase::UnescapeUtf8FileName(extension.substr(1)); | |
2069 } | |
2070 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(resource_id, | |
2071 md5); | |
2072 if (!entry) { | |
2073 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
2074 return; | |
2075 } else if ((to_mount && entry->IsMounted()) || | |
2076 (!to_mount && !entry->IsMounted())) { | |
2077 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | |
2078 return; | |
2079 } else { | |
2080 md5 = entry->md5; | |
2081 } | |
2082 | |
2083 // Get subdir types for the unmounted and mounted state. | |
2084 GDataRootDirectory::CacheSubDirectoryType unmounted_subdir = | |
2085 entry->IsPinned() ? GDataRootDirectory::CACHE_TYPE_PERSISTENT : | |
2086 GDataRootDirectory::CACHE_TYPE_TMP; | |
2087 GDataRootDirectory::CacheSubDirectoryType mounted_subdir = | |
2088 GDataRootDirectory::CACHE_TYPE_PERSISTENT; | |
2089 // Gets path of the file if it were to be unmounted. | |
2090 FilePath unmounted_path = GetCacheFilePath(resource_id, md5, unmounted_subdir, | |
2091 CACHED_FILE_FROM_SERVER); | |
2092 // Gets path of the file if it were to be mounted. | |
2093 FilePath mounted_path = GetCacheFilePath(resource_id, md5, mounted_subdir, | |
2094 CACHED_FILE_MOUNTED); | |
2095 // Determine the source and destination paths for moving the cache blob. | |
2096 FilePath source_path; | |
2097 GDataRootDirectory::CacheSubDirectoryType dest_subdir; | |
2098 int cache_state = entry->cache_state; | |
2099 if (to_mount) { | |
2100 source_path = unmounted_path; | |
2101 *cache_file_path = mounted_path; | |
2102 dest_subdir = mounted_subdir; | |
2103 cache_state = GDataFile::SetCacheMounted(cache_state); | |
2104 } else { | |
2105 source_path = mounted_path; | |
2106 *cache_file_path = unmounted_path; | |
2107 dest_subdir = unmounted_subdir; | |
2108 cache_state = GDataFile::ClearCacheMounted(cache_state); | |
2109 } | |
2110 // Move cache blob from source path to destination path. | |
2111 *error = ModifyCacheState(source_path, *cache_file_path, | |
2112 GDataFileSystem::FILE_OPERATION_MOVE, FilePath(), | |
2113 false); | |
2114 if (*error == base::PLATFORM_FILE_OK) { | |
2115 // Now that cache operation is complete, update cache map | |
2116 root_->UpdateCacheMap(resource_id, md5, dest_subdir, cache_state); | |
2117 } | |
2118 } | |
2119 | |
2016 void GDataFileSystem::OnSetPinStateCompleted( | 2120 void GDataFileSystem::OnSetPinStateCompleted( |
2017 const FileOperationCallback& callback, | 2121 const FileOperationCallback& callback, |
2018 base::PlatformFileError error, | 2122 base::PlatformFileError error, |
2019 const std::string& resource_id, | 2123 const std::string& resource_id, |
2020 const std::string& md5) { | 2124 const std::string& md5) { |
2021 callback.Run(error); | 2125 callback.Run(error); |
2022 } | 2126 } |
2023 | 2127 |
2024 void GDataFileSystem::OnGetAvailableSpace( | 2128 void GDataFileSystem::OnGetAvailableSpace( |
2025 const GetAvailableSpaceCallback& callback, | 2129 const GetAvailableSpaceCallback& callback, |
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3177 DCHECK(sub_dir_type != GDataRootDirectory::CACHE_TYPE_META); | 3281 DCHECK(sub_dir_type != GDataRootDirectory::CACHE_TYPE_META); |
3178 | 3282 |
3179 // Runs on any thread. | 3283 // Runs on any thread. |
3180 // Filename is formatted as resource_id.md5, i.e. resource_id is the base | 3284 // Filename is formatted as resource_id.md5, i.e. resource_id is the base |
3181 // name and md5 is the extension. | 3285 // name and md5 is the extension. |
3182 std::string base_name = GDataFileBase::EscapeUtf8FileName(resource_id); | 3286 std::string base_name = GDataFileBase::EscapeUtf8FileName(resource_id); |
3183 if (file_origin == CACHED_FILE_LOCALLY_MODIFIED) { | 3287 if (file_origin == CACHED_FILE_LOCALLY_MODIFIED) { |
3184 DCHECK(sub_dir_type == GDataRootDirectory::CACHE_TYPE_PERSISTENT); | 3288 DCHECK(sub_dir_type == GDataRootDirectory::CACHE_TYPE_PERSISTENT); |
3185 base_name += FilePath::kExtensionSeparator; | 3289 base_name += FilePath::kExtensionSeparator; |
3186 base_name += kLocallyModifiedFileExtension; | 3290 base_name += kLocallyModifiedFileExtension; |
3291 } else if (file_origin == CACHED_FILE_MOUNTED) { | |
3292 DCHECK(sub_dir_type == GDataRootDirectory::CACHE_TYPE_PERSISTENT); | |
3293 base_name += FilePath::kExtensionSeparator; | |
3294 base_name += kMountedArchiveFileExtension; | |
3187 } else if (!md5.empty()) { | 3295 } else if (!md5.empty()) { |
3188 base_name += FilePath::kExtensionSeparator; | 3296 base_name += FilePath::kExtensionSeparator; |
3189 base_name += GDataFileBase::EscapeUtf8FileName(md5); | 3297 base_name += GDataFileBase::EscapeUtf8FileName(md5); |
3190 } | 3298 } |
3191 return cache_paths_[sub_dir_type].Append(base_name); | 3299 return cache_paths_[sub_dir_type].Append(base_name); |
3192 } | 3300 } |
3193 | 3301 |
3194 void GDataFileSystem::GetFromCache(const std::string& resource_id, | 3302 void GDataFileSystem::GetFromCache(const std::string& resource_id, |
3195 const std::string& md5, | 3303 const std::string& md5, |
3196 const GetFromCacheCallback& callback) { | 3304 const GetFromCacheCallback& callback) { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3419 FilePath* cache_file_path) { | 3527 FilePath* cache_file_path) { |
3420 DCHECK(error); | 3528 DCHECK(error); |
3421 DCHECK(cache_file_path); | 3529 DCHECK(cache_file_path); |
3422 | 3530 |
3423 // Lock to access cache map. | 3531 // Lock to access cache map. |
3424 base::AutoLock lock(lock_); | 3532 base::AutoLock lock(lock_); |
3425 | 3533 |
3426 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(resource_id, | 3534 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(resource_id, |
3427 md5); | 3535 md5); |
3428 if (entry && entry->IsPresent()) { | 3536 if (entry && entry->IsPresent()) { |
3537 CachedFileOrigin file_origin; | |
3538 if (entry->IsMounted()) { | |
3539 file_origin = CACHED_FILE_MOUNTED; | |
3540 } else if (entry->IsDirty()) { | |
3541 file_origin = CACHED_FILE_LOCALLY_MODIFIED; | |
3542 } else { | |
3543 file_origin = CACHED_FILE_FROM_SERVER; | |
3544 } | |
3429 *cache_file_path = GetCacheFilePath( | 3545 *cache_file_path = GetCacheFilePath( |
3430 resource_id, | 3546 resource_id, |
3431 md5, | 3547 md5, |
3432 entry->sub_dir_type, | 3548 entry->sub_dir_type, |
3433 entry->IsDirty() ? CACHED_FILE_LOCALLY_MODIFIED : | 3549 file_origin); |
3434 CACHED_FILE_FROM_SERVER); | |
3435 *error = base::PLATFORM_FILE_OK; | 3550 *error = base::PLATFORM_FILE_OK; |
3436 } else { | 3551 } else { |
3437 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 3552 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
3438 } | 3553 } |
3439 } | 3554 } |
3440 | 3555 |
3441 void GDataFileSystem::GetCacheStateOnIOThreadPool( | 3556 void GDataFileSystem::GetCacheStateOnIOThreadPool( |
3442 const std::string& resource_id, | 3557 const std::string& resource_id, |
3443 const std::string& md5, | 3558 const std::string& md5, |
3444 base::PlatformFileError* error, | 3559 base::PlatformFileError* error, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3481 int cache_state = GDataFile::CACHE_STATE_PRESENT; | 3596 int cache_state = GDataFile::CACHE_STATE_PRESENT; |
3482 GDataRootDirectory::CacheSubDirectoryType sub_dir_type = | 3597 GDataRootDirectory::CacheSubDirectoryType sub_dir_type = |
3483 GDataRootDirectory::CACHE_TYPE_TMP; | 3598 GDataRootDirectory::CACHE_TYPE_TMP; |
3484 | 3599 |
3485 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry( | 3600 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry( |
3486 resource_id, md5); | 3601 resource_id, md5); |
3487 | 3602 |
3488 // If file was previously pinned, store it in persistent dir and create | 3603 // If file was previously pinned, store it in persistent dir and create |
3489 // symlink in pinned dir. | 3604 // symlink in pinned dir. |
3490 if (entry) { // File exists in cache. | 3605 if (entry) { // File exists in cache. |
3491 // If file is dirty, return error. | 3606 // If file is dirty or mounted, return error. |
3492 if (entry->IsDirty()) { | 3607 if (entry->IsDirty() || entry->IsMounted()) { |
3493 LOG(WARNING) << "Can't store a file to replace a dirty file: res_id=" | 3608 LOG(WARNING) << "Can't store a file to replace a " |
3494 << resource_id | 3609 << (entry->IsDirty() ? "dirty" : "mounted") |
3610 << " file: res_id=" << resource_id | |
3495 << ", md5=" << md5; | 3611 << ", md5=" << md5; |
3496 *error = base::PLATFORM_FILE_ERROR_IN_USE; | 3612 *error = base::PLATFORM_FILE_ERROR_IN_USE; |
3497 return; | 3613 return; |
3498 } | 3614 } |
3499 | 3615 |
3500 cache_state |= entry->cache_state; | 3616 cache_state |= entry->cache_state; |
3501 | 3617 |
3502 // If file is pinned, determines destination path. | 3618 // If file is pinned, determines destination path. |
3503 if (entry->IsPinned()) { | 3619 if (entry->IsPinned()) { |
3504 sub_dir_type = GDataRootDirectory::CACHE_TYPE_PERSISTENT; | 3620 sub_dir_type = GDataRootDirectory::CACHE_TYPE_PERSISTENT; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3583 | 3699 |
3584 // Set sub_dir_type to PINNED to indicate that the file doesn't exist. | 3700 // 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 | 3701 // When the file is finally downloaded and StoreToCache called, it will be |
3586 // moved to persistent directory. | 3702 // moved to persistent directory. |
3587 sub_dir_type = GDataRootDirectory::CACHE_TYPE_PINNED; | 3703 sub_dir_type = GDataRootDirectory::CACHE_TYPE_PINNED; |
3588 } else { // File exists in cache, determines destination path. | 3704 } else { // File exists in cache, determines destination path. |
3589 cache_state |= entry->cache_state; | 3705 cache_state |= entry->cache_state; |
3590 | 3706 |
3591 // Determine source and destination paths. | 3707 // Determine source and destination paths. |
3592 | 3708 |
3593 // If file is dirty, don't move it, so determine |dest_path| and set | 3709 // 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 | 3710 // set |source_path| the same, because ModifyCacheState only moves files if |
3595 // source and destination are different. | 3711 // source and destination are different. |
3596 if (entry->IsDirty()) { | 3712 if (entry->IsDirty() || entry->IsMounted()) { |
3597 DCHECK_EQ(GDataRootDirectory::CACHE_TYPE_PERSISTENT, entry->sub_dir_type); | 3713 DCHECK_EQ(GDataRootDirectory::CACHE_TYPE_PERSISTENT, entry->sub_dir_type); |
3598 dest_path = GetCacheFilePath(resource_id, | 3714 dest_path = GetCacheFilePath(resource_id, |
3599 md5, | 3715 md5, |
3600 entry->sub_dir_type, | 3716 entry->sub_dir_type, |
3601 CACHED_FILE_LOCALLY_MODIFIED); | 3717 CACHED_FILE_LOCALLY_MODIFIED); |
3602 source_path = dest_path; | 3718 source_path = dest_path; |
3603 } else { | 3719 } else { |
3604 // Gets the current path of the file in cache. | 3720 // Gets the current path of the file in cache. |
3605 source_path = GetCacheFilePath(resource_id, | 3721 source_path = GetCacheFilePath(resource_id, |
3606 md5, | 3722 md5, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3666 return; | 3782 return; |
3667 } | 3783 } |
3668 | 3784 |
3669 // Entry exists in cache, determines source and destination paths. | 3785 // Entry exists in cache, determines source and destination paths. |
3670 | 3786 |
3671 FilePath source_path; | 3787 FilePath source_path; |
3672 FilePath dest_path; | 3788 FilePath dest_path; |
3673 GDataRootDirectory::CacheSubDirectoryType sub_dir_type = | 3789 GDataRootDirectory::CacheSubDirectoryType sub_dir_type = |
3674 GDataRootDirectory::CACHE_TYPE_TMP; | 3790 GDataRootDirectory::CACHE_TYPE_TMP; |
3675 | 3791 |
3676 // If file is dirty, don't move it, so determine |dest_path| and set | 3792 // 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 | 3793 // set |source_path| the same, because ModifyCacheState moves files if source |
3678 // and destination are different. | 3794 // and destination are different. |
3679 if (entry->IsDirty()) { | 3795 if (entry->IsDirty() || entry->IsMounted()) { |
3680 sub_dir_type = GDataRootDirectory::CACHE_TYPE_PERSISTENT; | 3796 sub_dir_type = GDataRootDirectory::CACHE_TYPE_PERSISTENT; |
3681 DCHECK_EQ(sub_dir_type, entry->sub_dir_type); | 3797 DCHECK_EQ(sub_dir_type, entry->sub_dir_type); |
3682 dest_path = GetCacheFilePath(resource_id, | 3798 dest_path = GetCacheFilePath(resource_id, |
3683 md5, | 3799 md5, |
3684 entry->sub_dir_type, | 3800 entry->sub_dir_type, |
3685 CACHED_FILE_LOCALLY_MODIFIED); | 3801 CACHED_FILE_LOCALLY_MODIFIED); |
3686 source_path = dest_path; | 3802 source_path = dest_path; |
3687 } else { | 3803 } else { |
3688 // Gets the current path of the file in cache. | 3804 // Gets the current path of the file in cache. |
3689 source_path = GetCacheFilePath(resource_id, | 3805 source_path = GetCacheFilePath(resource_id, |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4001 // Lock to access cache map. | 4117 // Lock to access cache map. |
4002 base::AutoLock lock(lock_); | 4118 base::AutoLock lock(lock_); |
4003 | 4119 |
4004 // MD5 is not passed into RemoveFromCache and hence | 4120 // MD5 is not passed into RemoveFromCache and hence |
4005 // RemoveFromCacheOnIOThreadPool, because we would delete all cache files | 4121 // RemoveFromCacheOnIOThreadPool, because we would delete all cache files |
4006 // corresponding to <resource_id> regardless of the md5. | 4122 // corresponding to <resource_id> regardless of the md5. |
4007 // So, search for entry in cache without taking md5 into account. | 4123 // So, search for entry in cache without taking md5 into account. |
4008 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry( | 4124 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry( |
4009 resource_id, std::string()); | 4125 resource_id, std::string()); |
4010 | 4126 |
4011 // If entry doesn't exist or is dirty in cache, nothing to do. | 4127 // If entry doesn't exist or is dirty or mounted in cache, nothing to do. |
4012 if (!entry || entry->IsDirty()) { | 4128 if (!entry || entry->IsDirty() || entry->IsMounted()) { |
4013 DVLOG(1) << "Entry " << (entry ? "is dirty" : "doesn't exist") | 4129 DVLOG(1) << "Entry " |
4130 << (entry ? (entry->IsDirty() ? "is dirty" : "is mounted") : | |
4131 "doesn't exist") | |
4014 << " in cache, not removing"; | 4132 << " in cache, not removing"; |
4015 *error = base::PLATFORM_FILE_OK; | 4133 *error = base::PLATFORM_FILE_OK; |
4016 return; | 4134 return; |
4017 } | 4135 } |
4018 | 4136 |
4019 // Determine paths to delete all cache versions of |resource_id| in | 4137 // Determine paths to delete all cache versions of |resource_id| in |
4020 // persistent, tmp and pinned directories. | 4138 // persistent, tmp and pinned directories. |
4021 std::vector<FilePath> paths_to_delete; | 4139 std::vector<FilePath> paths_to_delete; |
4022 | 4140 |
4023 // For files in persistent and tmp dirs, delete files that match | 4141 // For files in persistent and tmp dirs, delete files that match |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4282 pref_registrar_->Init(profile_->GetPrefs()); | 4400 pref_registrar_->Init(profile_->GetPrefs()); |
4283 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); | 4401 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); |
4284 } | 4402 } |
4285 | 4403 |
4286 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 4404 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
4287 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 4405 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
4288 global_free_disk_getter_for_testing = getter; | 4406 global_free_disk_getter_for_testing = getter; |
4289 } | 4407 } |
4290 | 4408 |
4291 } // namespace gdata | 4409 } // namespace gdata |
OLD | NEW |