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