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

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

Issue 9742002: Wired GDataFileSystem::GetFile() method with internal cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/eintr_wrapper.h" 10 #include "base/eintr_wrapper.h"
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 void ReadOnlyFindFileDelegate::OnDone(base::PlatformFileError error, 513 void ReadOnlyFindFileDelegate::OnDone(base::PlatformFileError error,
514 const FilePath& directory_path, 514 const FilePath& directory_path,
515 GDataFileBase* file) { 515 GDataFileBase* file) {
516 DCHECK(!file_); 516 DCHECK(!file_);
517 if (error == base::PLATFORM_FILE_OK) 517 if (error == base::PLATFORM_FILE_OK)
518 file_ = file; 518 file_ = file;
519 else 519 else
520 file_ = NULL; 520 file_ = NULL;
521 } 521 }
522 522
523 // GDataFileProperties struct implementation.
524
525 GDataFileProperties::GDataFileProperties() : is_hosted_document(false) {
526 }
527
528 GDataFileProperties::~GDataFileProperties() {
529 }
530
523 // GDataFileSystem::CreateDirectoryParams struct implementation. 531 // GDataFileSystem::CreateDirectoryParams struct implementation.
524 532
525 GDataFileSystem::CreateDirectoryParams::CreateDirectoryParams( 533 GDataFileSystem::CreateDirectoryParams::CreateDirectoryParams(
526 const FilePath& created_directory_path, 534 const FilePath& created_directory_path,
527 const FilePath& target_directory_path, 535 const FilePath& target_directory_path,
528 bool is_exclusive, 536 bool is_exclusive,
529 bool is_recursive, 537 bool is_recursive,
530 const FileOperationCallback& callback) 538 const FileOperationCallback& callback)
531 : created_directory_path(created_directory_path), 539 : created_directory_path(created_directory_path),
532 target_directory_path(target_directory_path), 540 target_directory_path(target_directory_path),
533 is_exclusive(is_exclusive), 541 is_exclusive(is_exclusive),
534 is_recursive(is_recursive), 542 is_recursive(is_recursive),
535 callback(callback) { 543 callback(callback) {
536 } 544 }
537 545
538 GDataFileSystem::CreateDirectoryParams::~CreateDirectoryParams() { 546 GDataFileSystem::CreateDirectoryParams::~CreateDirectoryParams() {
539 } 547 }
540 548
549 //=================== GetFileFromCacheParams implementation ===================
550
551 GDataFileSystem::GetFileFromCacheParams::GetFileFromCacheParams(
552 const FilePath& virtual_file_path,
553 const FilePath& local_tmp_path,
554 const GURL& content_url,
555 const std::string& resource_id,
556 const std::string& md5,
557 scoped_refptr<base::MessageLoopProxy> proxy,
558 const GetFileCallback& callback)
559 : virtual_file_path(virtual_file_path),
560 local_tmp_path(local_tmp_path),
561 content_url(content_url),
562 resource_id(resource_id),
563 md5(md5),
564 proxy(proxy),
565 callback(callback) {
566 }
567
568 GDataFileSystem::GetFileFromCacheParams::~GetFileFromCacheParams() {
569 }
570
541 // GDataFileSystem class implementatsion. 571 // GDataFileSystem class implementatsion.
542 572
543 GDataFileSystem::GDataFileSystem(Profile* profile, 573 GDataFileSystem::GDataFileSystem(Profile* profile,
544 DocumentsServiceInterface* documents_service, 574 DocumentsServiceInterface* documents_service,
545 GDataSyncClientInterface* sync_client) 575 GDataSyncClientInterface* sync_client)
546 : profile_(profile), 576 : profile_(profile),
547 documents_service_(documents_service), 577 documents_service_(documents_service),
548 gdata_uploader_(new GDataUploader(ALLOW_THIS_IN_INITIALIZER_LIST(this))), 578 gdata_uploader_(new GDataUploader(ALLOW_THIS_IN_INITIALIZER_LIST(this))),
549 gdata_download_observer_(new GDataDownloadObserver()), 579 gdata_download_observer_(new GDataDownloadObserver()),
550 on_cache_initialized_(new base::WaitableEvent( 580 on_cache_initialized_(new base::WaitableEvent(
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 if (error != base::PLATFORM_FILE_OK) 1054 if (error != base::PLATFORM_FILE_OK)
1025 temp_file.clear(); 1055 temp_file.clear();
1026 1056
1027 relay_proxy->PostTask(FROM_HERE, 1057 relay_proxy->PostTask(FROM_HERE,
1028 base::Bind(callback, error, temp_file, HOSTED_DOCUMENT)); 1058 base::Bind(callback, error, temp_file, HOSTED_DOCUMENT));
1029 } 1059 }
1030 } 1060 }
1031 1061
1032 void GDataFileSystem::GetFile(const FilePath& file_path, 1062 void GDataFileSystem::GetFile(const FilePath& file_path,
1033 const GetFileCallback& callback) { 1063 const GetFileCallback& callback) {
1034 base::AutoLock lock(lock_); 1064 GDataFileProperties file_properties;
1035 GDataFileBase* file_info = GetGDataFileInfoFromPath(file_path); 1065 if (!GetFileInfoFromPath(file_path, &file_properties)) {
1036 if (!file_info) {
1037 if (!callback.is_null()) { 1066 if (!callback.is_null()) {
1038 MessageLoop::current()->PostTask( 1067 MessageLoop::current()->PostTask(
1039 FROM_HERE, 1068 FROM_HERE,
1040 base::Bind(callback, 1069 base::Bind(callback,
1041 base::PLATFORM_FILE_ERROR_NOT_FOUND, 1070 base::PLATFORM_FILE_ERROR_NOT_FOUND,
1042 FilePath(), 1071 FilePath(),
1043 REGULAR_FILE)); 1072 REGULAR_FILE));
1044 } 1073 }
1045 return; 1074 return;
1046 } 1075 }
1047 1076
1048 // For a hosted document, we create a special JSON file to represent the 1077 // For a hosted document, we create a special JSON file to represent the
1049 // document instead of fetching the document content in one of the exported 1078 // document instead of fetching the document content in one of the exported
1050 // formats. The JSON file contains the edit URL and resource ID of the 1079 // formats. The JSON file contains the edit URL and resource ID of the
1051 // document. 1080 // document.
1052 GDataFile* gdata_file = file_info->AsGDataFile(); 1081 if (file_properties.is_hosted_document) {
1053 if (gdata_file && gdata_file->is_hosted_document()) {
1054 BrowserThread::PostBlockingPoolTask(FROM_HERE, 1082 BrowserThread::PostBlockingPoolTask(FROM_HERE,
1055 base::Bind(&GDataFileSystem::CreateDocumentJsonFileOnIOThreadPool, 1083 base::Bind(&GDataFileSystem::CreateDocumentJsonFileOnIOThreadPool,
1056 gdata_file->edit_url(), 1084 file_properties.edit_url,
1057 gdata_file->resource_id(), 1085 file_properties.resource_id,
1058 callback, 1086 callback,
1059 base::MessageLoopProxy::current())); 1087 base::MessageLoopProxy::current()));
1060 return; 1088 return;
1061 } 1089 }
1062 1090
1063 // TODO(satorux): We should get a file from the cache if it's present, but 1091 // Returns absolute path of the file if it were cached or to be cached.
1064 // the caching layer is not implemented yet. For now, always download from 1092 FilePath local_tmp_path = GetCacheFilePath(file_properties.resource_id,
1065 // the cloud. 1093 file_properties.file_md5,
1094 CACHE_TYPE_TMP,
1095 CACHED_FILE_FROM_SERVER);
1096 GetFromCache(file_properties.resource_id, file_properties.file_md5,
1097 base::Bind(
1098 &GDataFileSystem::OnGetFileFromCache,
1099 weak_ptr_factory_.GetWeakPtr(),
1100 GetFileFromCacheParams(file_path,
1101 local_tmp_path,
1102 file_properties.content_url,
1103 file_properties.resource_id,
1104 file_properties.file_md5,
1105 base::MessageLoopProxy::current(),
1106 callback)));
1107 }
1108
1109 void GDataFileSystem::OnGetFileFromCache(const GetFileFromCacheParams& params,
1110 base::PlatformFileError error,
1111 const std::string& resource_id,
1112 const std::string& md5,
1113 const FilePath& gdata_file_path,
1114 const FilePath& cache_file_path) {
1115 // Have we found the file in cache? If so, return it back to the caller.
1116 if (error == base::PLATFORM_FILE_OK) {
1117 if (!params.callback.is_null()) {
1118 params.proxy->PostTask(FROM_HERE,
1119 base::Bind(params.callback,
1120 error,
1121 cache_file_path,
1122 REGULAR_FILE));
1123 }
1124
1125 return;
1126 }
1127
1128 // If cache file is not found, try to download it from the server instead.
1066 documents_service_->DownloadFile( 1129 documents_service_->DownloadFile(
1067 file_info->GetFilePath(), 1130 params.virtual_file_path,
1068 file_info->content_url(), 1131 params.local_tmp_path,
1132 params.content_url,
1069 base::Bind(&GDataFileSystem::OnFileDownloaded, 1133 base::Bind(&GDataFileSystem::OnFileDownloaded,
1070 weak_ptr_factory_.GetWeakPtr(), 1134 weak_ptr_factory_.GetWeakPtr(),
1071 callback)); 1135 params));
1072 } 1136 }
1073 1137
1074 void GDataFileSystem::InitiateUpload( 1138 void GDataFileSystem::InitiateUpload(
1075 const std::string& file_name, 1139 const std::string& file_name,
1076 const std::string& content_type, 1140 const std::string& content_type,
1077 int64 content_length, 1141 int64 content_length,
1078 const FilePath& destination_directory, 1142 const FilePath& destination_directory,
1079 const FilePath& virtual_path, 1143 const FilePath& virtual_path,
1080 const InitiateUploadCallback& callback) { 1144 const InitiateUploadCallback& callback) {
1081 GURL destination_directory_url = 1145 GURL destination_directory_url =
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 delegate->OnDone(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL); 1252 delegate->OnDone(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL);
1189 } 1253 }
1190 1254
1191 return; 1255 return;
1192 } 1256 }
1193 } 1257 }
1194 delegate->OnDone(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL); 1258 delegate->OnDone(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL);
1195 } 1259 }
1196 1260
1197 bool GDataFileSystem::GetFileInfoFromPath( 1261 bool GDataFileSystem::GetFileInfoFromPath(
1198 const FilePath& file_path, base::PlatformFileInfo* file_info) { 1262 const FilePath& file_path, GDataFileProperties* properties) {
1263 DCHECK(properties);
1199 base::AutoLock lock(lock_); 1264 base::AutoLock lock(lock_);
1200 GDataFileBase* file = GetGDataFileInfoFromPath(file_path); 1265 GDataFileBase* file = GetGDataFileInfoFromPath(file_path);
1201 if (!file) 1266 if (!file)
1202 return false; 1267 return false;
1203 1268
1204 *file_info = file->file_info(); 1269 properties->file_info = file->file_info();
1270 properties->resource_id = file->resource_id();
1271
1272 GDataFile* regular_file = file->AsGDataFile();
1273 if (regular_file) {
1274 properties->file_md5 = regular_file->file_md5();
1275 properties->content_url = regular_file->content_url();
1276 properties->edit_url = regular_file->edit_url();
1277 properties->is_hosted_document = regular_file->is_hosted_document();
1278 }
1205 return true; 1279 return true;
1206 } 1280 }
1207 1281
1208 FilePath GDataFileSystem::GetGDataCacheTmpDirectory() { 1282 FilePath GDataFileSystem::GetGDataCacheTmpDirectory() {
1209 return cache_paths_[CACHE_TYPE_TMP]; 1283 return cache_paths_[CACHE_TYPE_TMP];
1210 } 1284 }
1211 1285
1212 GDataFileBase* GDataFileSystem::GetGDataFileInfoFromPath( 1286 GDataFileBase* GDataFileSystem::GetGDataFileInfoFromPath(
1213 const FilePath& file_path) { 1287 const FilePath& file_path) {
1214 lock_.AssertAcquired(); 1288 lock_.AssertAcquired();
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
1697 1771
1698 if (error == base::PLATFORM_FILE_OK) 1772 if (error == base::PLATFORM_FILE_OK)
1699 error = RemoveFileFromFileSystem(file_path); 1773 error = RemoveFileFromFileSystem(file_path);
1700 1774
1701 if (!callback.is_null()) { 1775 if (!callback.is_null()) {
1702 callback.Run(error); 1776 callback.Run(error);
1703 } 1777 }
1704 } 1778 }
1705 1779
1706 void GDataFileSystem::OnFileDownloaded( 1780 void GDataFileSystem::OnFileDownloaded(
1707 const GetFileCallback& callback, 1781 const GetFileFromCacheParams& params,
1708 GDataErrorCode status, 1782 GDataErrorCode status,
1709 const GURL& content_url, 1783 const GURL& content_url,
1710 const FilePath& file_path) { 1784 const FilePath& downloaded_file_path) {
1711 base::PlatformFileError error = GDataToPlatformError(status); 1785 base::PlatformFileError error = GDataToPlatformError(status);
1712 1786
1713 if (!callback.is_null()) { 1787 // Make sure that downloaded file is properly stored in cache. We don't have
1714 callback.Run(error, file_path, REGULAR_FILE); 1788 // to wait for this operation to finish since the user can already use the
1789 // downloaded file.
1790 if (error == base::PLATFORM_FILE_OK) {
1791 StoreToCache(params.resource_id,
1792 params.md5,
1793 downloaded_file_path,
1794 base::Bind(&GDataFileSystem::OnDownloadStoredToCache,
1795 weak_ptr_factory_.GetWeakPtr()));
1715 } 1796 }
1797
1798 if (!params.callback.is_null()) {
1799 params.proxy->PostTask(FROM_HERE,
1800 base::Bind(params.callback,
1801 error,
1802 downloaded_file_path,
1803 REGULAR_FILE));
1804 }
1805 }
1806
1807 void GDataFileSystem::OnDownloadStoredToCache(base::PlatformFileError error,
1808 const std::string& resource_id,
1809 const std::string& md5) {
1810 // Nothing much to do here for now.
1716 } 1811 }
1717 1812
1718 base::PlatformFileError GDataFileSystem::RenameFileOnFilesystem( 1813 base::PlatformFileError GDataFileSystem::RenameFileOnFilesystem(
1719 const FilePath& file_path, 1814 const FilePath& file_path,
1720 const FilePath::StringType& new_name, 1815 const FilePath::StringType& new_name,
1721 FilePath* updated_file_path) { 1816 FilePath* updated_file_path) {
1722 DCHECK(updated_file_path); 1817 DCHECK(updated_file_path);
1723 1818
1724 base::AutoLock lock(lock_); 1819 base::AutoLock lock(lock_);
1725 GDataFileBase* file = GetGDataFileInfoFromPath(file_path); 1820 GDataFileBase* file = GetGDataFileInfoFromPath(file_path);
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
2017 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 2112 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
2018 2113
2019 return base::PLATFORM_FILE_OK; 2114 return base::PLATFORM_FILE_OK;
2020 } 2115 }
2021 2116
2022 //===================== GDataFileSystem: Cache entry points ==================== 2117 //===================== GDataFileSystem: Cache entry points ====================
2023 2118
2024 FilePath GDataFileSystem::GetCacheFilePath(const std::string& resource_id, 2119 FilePath GDataFileSystem::GetCacheFilePath(const std::string& resource_id,
2025 const std::string& md5, 2120 const std::string& md5,
2026 CacheSubdir subdir_id, 2121 CacheSubdir subdir_id,
2027 bool is_local) { 2122 CachedFileOrigin file_origin) {
2028 DCHECK(subdir_id != CACHE_TYPE_META); 2123 DCHECK(subdir_id != CACHE_TYPE_META);
2029 // Runs on any thread. 2124 // Runs on any thread.
2030 // Filename is formatted as resource_id.md5, i.e. resource_id is the base 2125 // Filename is formatted as resource_id.md5, i.e. resource_id is the base
2031 // name and md5 is the extension. 2126 // name and md5 is the extension.
2032 std::string base_name = GDataFileBase::EscapeUtf8FileName(resource_id); 2127 std::string base_name = GDataFileBase::EscapeUtf8FileName(resource_id);
2033 if (is_local) { 2128 if (file_origin == CACHED_FILE_LOCALLY_MODIFIED) {
2034 DCHECK(subdir_id == CACHE_TYPE_PERSISTENT); 2129 DCHECK(subdir_id == CACHE_TYPE_PERSISTENT);
2035 base_name += FilePath::kExtensionSeparator; 2130 base_name += FilePath::kExtensionSeparator;
2036 base_name += kLocallyModifiedFileExtension; 2131 base_name += kLocallyModifiedFileExtension;
2037 } else if (!md5.empty()) { 2132 } else if (!md5.empty()) {
2038 base_name += FilePath::kExtensionSeparator; 2133 base_name += FilePath::kExtensionSeparator;
2039 base_name += GDataFileBase::EscapeUtf8FileName(md5); 2134 base_name += GDataFileBase::EscapeUtf8FileName(md5);
2040 } 2135 }
2041 return cache_paths_[subdir_id].Append(base_name); 2136 return cache_paths_[subdir_id].Append(base_name);
2042 } 2137 }
2043 2138
(...skipping 14 matching lines...) Expand all
2058 FROM_HERE, 2153 FROM_HERE,
2059 base::Bind(StoreToCacheOnIOThreadPool, 2154 base::Bind(StoreToCacheOnIOThreadPool,
2060 StoreToCacheParams( 2155 StoreToCacheParams(
2061 resource_id, 2156 resource_id,
2062 md5, 2157 md5,
2063 source_path, 2158 source_path,
2064 callback, 2159 callback,
2065 GetCacheFilePath(resource_id, 2160 GetCacheFilePath(resource_id,
2066 md5, 2161 md5,
2067 CACHE_TYPE_TMP, 2162 CACHE_TYPE_TMP,
2068 false /* is_local */), 2163 CACHED_FILE_FROM_SERVER),
2069 base::Bind(&GDataFileSystem::OnStoredToCache, 2164 base::Bind(&GDataFileSystem::OnStoredToCache,
2070 weak_ptr_factory_.GetWeakPtr()), 2165 weak_ptr_factory_.GetWeakPtr()),
2071 base::MessageLoopProxy::current()))); 2166 base::MessageLoopProxy::current())));
2072 } 2167 }
2073 2168
2074 void GDataFileSystem::GetFromCache(const std::string& resource_id, 2169 void GDataFileSystem::GetFromCache(const std::string& resource_id,
2075 const std::string& md5, 2170 const std::string& md5,
2076 const GetFromCacheCallback& callback) { 2171 const GetFromCacheCallback& callback) {
2077 GetFromCacheInternal(resource_id, md5, FilePath(), callback); 2172 GetFromCacheInternal(resource_id, md5, FilePath(), callback);
2078 } 2173 }
2079 2174
2080 void GDataFileSystem::RemoveFromCache(const std::string& resource_id, 2175 void GDataFileSystem::RemoveFromCache(const std::string& resource_id,
2081 const CacheOperationCallback& callback) { 2176 const CacheOperationCallback& callback) {
2082 InitializeCacheIfNecessary(); 2177 InitializeCacheIfNecessary();
2083 2178
2084 // Lock to access cache map. 2179 // Lock to access cache map.
2085 base::AutoLock lock(lock_); 2180 base::AutoLock lock(lock_);
2086 root_->RemoveFromCacheMap(resource_id); 2181 root_->RemoveFromCacheMap(resource_id);
2087 2182
2088 // Post task to delete all cache versions of resource_id. 2183 // Post task to delete all cache versions of resource_id.
2089 // If $resource_id.* is passed to DeleteStaleCacheVersions, then all 2184 // If $resource_id.* is passed to DeleteStaleCacheVersions, then all
2090 // $resource_id.* will be deleted since no file will match "$resource_id.*". 2185 // $resource_id.* will be deleted since no file will match "$resource_id.*".
2091 FilePath files_to_delete = GetCacheFilePath(resource_id, 2186 FilePath files_to_delete = GetCacheFilePath(resource_id,
2092 kWildCard, 2187 kWildCard,
2093 CACHE_TYPE_TMP, 2188 CACHE_TYPE_TMP,
2094 false /* is_local */); 2189 CACHED_FILE_FROM_SERVER);
2095 BrowserThread::PostBlockingPoolSequencedTask( 2190 BrowserThread::PostBlockingPoolSequencedTask(
2096 kGDataFileSystemToken, 2191 kGDataFileSystemToken,
2097 FROM_HERE, 2192 FROM_HERE,
2098 base::Bind(DeleteStaleCacheVersionsWithCallback, 2193 base::Bind(DeleteStaleCacheVersionsWithCallback,
2099 resource_id, 2194 resource_id,
2100 callback, 2195 callback,
2101 files_to_delete, 2196 files_to_delete,
2102 base::MessageLoopProxy::current())); 2197 base::MessageLoopProxy::current()));
2103 2198
2104 } 2199 }
2105 2200
2106 void GDataFileSystem::Pin(const std::string& resource_id, 2201 void GDataFileSystem::Pin(const std::string& resource_id,
2107 const std::string& md5, 2202 const std::string& md5,
2108 const CacheOperationCallback& callback) { 2203 const CacheOperationCallback& callback) {
2109 InitializeCacheIfNecessary(); 2204 InitializeCacheIfNecessary();
2110 2205
2111 BrowserThread::PostBlockingPoolSequencedTask( 2206 BrowserThread::PostBlockingPoolSequencedTask(
2112 kGDataFileSystemToken, 2207 kGDataFileSystemToken,
2113 FROM_HERE, 2208 FROM_HERE,
2114 base::Bind(ModifyCacheStatusOnIOThreadPool, 2209 base::Bind(ModifyCacheStatusOnIOThreadPool,
2115 ModifyCacheStatusParams( 2210 ModifyCacheStatusParams(
2116 resource_id, 2211 resource_id,
2117 md5, 2212 md5,
2118 callback, 2213 callback,
2119 GDataRootDirectory::CACHE_PINNED, 2214 GDataRootDirectory::CACHE_PINNED,
2120 true, 2215 true,
2121 GetCacheFilePath(resource_id, 2216 GetCacheFilePath(resource_id,
2122 md5, 2217 md5,
2123 CACHE_TYPE_TMP, 2218 CACHE_TYPE_TMP,
2124 false /* is_local */), 2219 CACHED_FILE_FROM_SERVER),
2125 base::Bind(&GDataFileSystem::OnFilePinned, 2220 base::Bind(&GDataFileSystem::OnFilePinned,
2126 weak_ptr_factory_.GetWeakPtr()), 2221 weak_ptr_factory_.GetWeakPtr()),
2127 base::MessageLoopProxy::current()))); 2222 base::MessageLoopProxy::current())));
2128 } 2223 }
2129 2224
2130 void GDataFileSystem::Unpin(const std::string& resource_id, 2225 void GDataFileSystem::Unpin(const std::string& resource_id,
2131 const std::string& md5, 2226 const std::string& md5,
2132 const CacheOperationCallback& callback) { 2227 const CacheOperationCallback& callback) {
2133 InitializeCacheIfNecessary(); 2228 InitializeCacheIfNecessary();
2134 2229
2135 BrowserThread::PostBlockingPoolSequencedTask( 2230 BrowserThread::PostBlockingPoolSequencedTask(
2136 kGDataFileSystemToken, 2231 kGDataFileSystemToken,
2137 FROM_HERE, 2232 FROM_HERE,
2138 base::Bind(ModifyCacheStatusOnIOThreadPool, 2233 base::Bind(ModifyCacheStatusOnIOThreadPool,
2139 ModifyCacheStatusParams( 2234 ModifyCacheStatusParams(
2140 resource_id, 2235 resource_id,
2141 md5, 2236 md5,
2142 callback, 2237 callback,
2143 GDataRootDirectory::CACHE_PINNED, 2238 GDataRootDirectory::CACHE_PINNED,
2144 false, 2239 false,
2145 GetCacheFilePath(resource_id, 2240 GetCacheFilePath(resource_id,
2146 md5, 2241 md5,
2147 CACHE_TYPE_TMP, 2242 CACHE_TYPE_TMP,
2148 false /* is_local */), 2243 CACHED_FILE_FROM_SERVER),
2149 base::Bind(&GDataFileSystem::OnFileUnpinned, 2244 base::Bind(&GDataFileSystem::OnFileUnpinned,
2150 weak_ptr_factory_.GetWeakPtr()), 2245 weak_ptr_factory_.GetWeakPtr()),
2151 base::MessageLoopProxy::current()))); 2246 base::MessageLoopProxy::current())));
2152 } 2247 }
2153 2248
2154 //========= GDataFileSystem: Cache tasks that ran on io thread pool ============ 2249 //========= GDataFileSystem: Cache tasks that ran on io thread pool ============
2155 2250
2156 void GDataFileSystem::InitializeCacheOnIOThreadPool() { 2251 void GDataFileSystem::InitializeCacheOnIOThreadPool() {
2157 base::PlatformFileError error = CreateCacheDirectories(cache_paths_); 2252 base::PlatformFileError error = CreateCacheDirectories(cache_paths_);
2158 2253
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
2234 2329
2235 base::PlatformFileError error = base::PLATFORM_FILE_OK; 2330 base::PlatformFileError error = base::PLATFORM_FILE_OK;
2236 FilePath path; 2331 FilePath path;
2237 2332
2238 // Lock to access cache map. 2333 // Lock to access cache map.
2239 base::AutoLock lock(lock_); 2334 base::AutoLock lock(lock_);
2240 if (root_->CacheFileExists(resource_id, md5)) { 2335 if (root_->CacheFileExists(resource_id, md5)) {
2241 path = GetCacheFilePath(resource_id, 2336 path = GetCacheFilePath(resource_id,
2242 md5, 2337 md5,
2243 CACHE_TYPE_TMP, 2338 CACHE_TYPE_TMP,
2244 false /* is_local */); 2339 CACHED_FILE_FROM_SERVER);
2245 } else { 2340 } else {
2246 error = base::PLATFORM_FILE_ERROR_NOT_FOUND; 2341 error = base::PLATFORM_FILE_ERROR_NOT_FOUND;
2247 } 2342 }
2248 2343
2249 // Invoke callback. 2344 // Invoke callback.
2250 if (!callback.is_null()) 2345 if (!callback.is_null())
2251 callback.Run(error, resource_id, md5, gdata_file_path, path); 2346 callback.Run(error, resource_id, md5, gdata_file_path, path);
2252 } 2347 }
2253 2348
2254 void GDataFileSystem::OnRemovedFromCache(base::PlatformFileError error, 2349 void GDataFileSystem::OnRemovedFromCache(base::PlatformFileError error,
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
2391 } 2486 }
2392 2487
2393 ProfileKeyedService* GDataFileSystemFactory::BuildServiceInstanceFor( 2488 ProfileKeyedService* GDataFileSystemFactory::BuildServiceInstanceFor(
2394 Profile* profile) const { 2489 Profile* profile) const {
2395 return new GDataFileSystem(profile, 2490 return new GDataFileSystem(profile,
2396 new DocumentsService, 2491 new DocumentsService,
2397 new GDataSyncClient); 2492 new GDataSyncClient);
2398 } 2493 }
2399 2494
2400 } // namespace gdata 2495 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_file_system_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698