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 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 | 10 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 // Callback for completion of cache operation. | 50 // Callback for completion of cache operation. |
51 typedef base::Callback<void(base::PlatformFileError error, | 51 typedef base::Callback<void(base::PlatformFileError error, |
52 const std::string& resource_id, | 52 const std::string& resource_id, |
53 const std::string& md5)> CacheOperationCallback; | 53 const std::string& md5)> CacheOperationCallback; |
54 | 54 |
55 // Callback for GetFileFromCache. | 55 // Callback for GetFileFromCache. |
56 typedef base::Callback<void(base::PlatformFileError error, | 56 typedef base::Callback<void(base::PlatformFileError error, |
57 const std::string& resource_id, | 57 const std::string& resource_id, |
58 const std::string& md5, | 58 const std::string& md5, |
59 const FilePath& gdata_file_path, | |
60 const FilePath& cache_file_path)> | 59 const FilePath& cache_file_path)> |
61 GetFileFromCacheCallback; | 60 GetFileFromCacheCallback; |
62 | 61 |
63 // Used to get result of file search. Please note that |file| is a live | 62 // Used to get result of file search. Please note that |file| is a live |
64 // object provided to this callback under lock. It must not be used outside | 63 // object provided to this callback under lock. It must not be used outside |
65 // of the callback method. This callback can be invoked on different thread | 64 // of the callback method. This callback can be invoked on different thread |
66 // than one that started FileFileByPath() request. | 65 // than one that started FileFileByPath() request. |
67 typedef base::Callback<void(base::PlatformFileError error, | 66 typedef base::Callback<void(base::PlatformFileError error, |
68 const FilePath& directory_path, | 67 const FilePath& directory_path, |
69 GDataEntry* entry)> | 68 GDataEntry* entry)> |
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 | 1101 |
1103 // Task posted from GetFileFromCacheInternal to run on IO thread pool. | 1102 // Task posted from GetFileFromCacheInternal to run on IO thread pool. |
1104 // Checks if file corresponding to |resource_id| and |md5| exists in cache | 1103 // Checks if file corresponding to |resource_id| and |md5| exists in cache |
1105 // map. | 1104 // map. |
1106 // Even though this task doesn't involve IO operations, it still runs on the | 1105 // Even though this task doesn't involve IO operations, it still runs on the |
1107 // IO thread pool, to force synchronization of all tasks on IO thread pool, | 1106 // IO thread pool, to force synchronization of all tasks on IO thread pool, |
1108 // e.g. this absolute must execute after InitailizeCacheOnIOTheadPool. | 1107 // e.g. this absolute must execute after InitailizeCacheOnIOTheadPool. |
1109 void GetFileFromCacheOnIOThreadPool( | 1108 void GetFileFromCacheOnIOThreadPool( |
1110 const std::string& resource_id, | 1109 const std::string& resource_id, |
1111 const std::string& md5, | 1110 const std::string& md5, |
1112 const FilePath& gdata_file_path, | |
1113 base::PlatformFileError* error, | 1111 base::PlatformFileError* error, |
1114 FilePath* cache_file_path); | 1112 FilePath* cache_file_path); |
1115 | 1113 |
1116 // Task posted from GetCacheState to run on IO thread pool. | 1114 // Task posted from GetCacheState to run on IO thread pool. |
1117 // Checks if file corresponding to |resource_id| and |md5| exists in cache | 1115 // Checks if file corresponding to |resource_id| and |md5| exists in cache |
1118 // map. If yes, returns its cache state; otherwise, returns CACHE_STATE_NONE. | 1116 // map. If yes, returns its cache state; otherwise, returns CACHE_STATE_NONE. |
1119 // Even though this task doesn't involve IO operations, it still runs on the | 1117 // Even though this task doesn't involve IO operations, it still runs on the |
1120 // IO thread pool, to force synchronization of all tasks on IO thread pool, | 1118 // IO thread pool, to force synchronization of all tasks on IO thread pool, |
1121 // e.g. this absolutely must execute after InitailizeCacheOnIOTheadPool. | 1119 // e.g. this absolutely must execute after InitailizeCacheOnIOTheadPool. |
1122 void GetCacheStateOnIOThreadPool( | 1120 void GetCacheStateOnIOThreadPool( |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 const CacheOperationCallback& callback); | 1206 const CacheOperationCallback& callback); |
1209 | 1207 |
1210 // Callback for Unpin. Runs |callback| and notifies the observers. | 1208 // Callback for Unpin. Runs |callback| and notifies the observers. |
1211 void OnFileUnpinned(base::PlatformFileError* error, | 1209 void OnFileUnpinned(base::PlatformFileError* error, |
1212 const std::string& resource_id, | 1210 const std::string& resource_id, |
1213 const std::string& md5, | 1211 const std::string& md5, |
1214 const CacheOperationCallback& callback); | 1212 const CacheOperationCallback& callback); |
1215 | 1213 |
1216 // Helper function for internally handling responses from | 1214 // Helper function for internally handling responses from |
1217 // GetFileFromCacheByResourceIdAndMd5() calls during processing of | 1215 // GetFileFromCacheByResourceIdAndMd5() calls during processing of |
1218 // GetFile() request. | 1216 // GetFileByPath() request. |
1219 void OnGetFileFromCache(const GetFileFromCacheParams& params, | 1217 void OnGetFileFromCache(const GetFileFromCacheParams& params, |
1220 base::PlatformFileError error, | 1218 base::PlatformFileError error, |
1221 const std::string& resource_id, | 1219 const std::string& resource_id, |
1222 const std::string& md5, | 1220 const std::string& md5, |
1223 const FilePath& gdata_file_path, | |
1224 const FilePath& cache_file_path); | 1221 const FilePath& cache_file_path); |
1225 | 1222 |
1226 // Frees up disk space to store the given number of bytes, while keeping | 1223 // Frees up disk space to store the given number of bytes, while keeping |
1227 // kMinFreSpace bytes on the disk, if needed. |has_enough_space| is | 1224 // kMinFreSpace bytes on the disk, if needed. |has_enough_space| is |
1228 // updated to indicate if we have enough space. | 1225 // updated to indicate if we have enough space. |
1229 void FreeDiskSpaceIfNeededFor(int64 num_bytes, | 1226 void FreeDiskSpaceIfNeededFor(int64 num_bytes, |
1230 bool* has_enough_space); | 1227 bool* has_enough_space); |
1231 | 1228 |
1232 // Frees up disk space if we have less than kMinFreSpace. |has_enough_space| | 1229 // Frees up disk space if we have less than kMinFreSpace. |has_enough_space| |
1233 // is updated to indicate if we have enough space. | 1230 // is updated to indicate if we have enough space. |
1234 void FreeDiskSpaceIfNeeded(bool* has_enough_space); | 1231 void FreeDiskSpaceIfNeeded(bool* has_enough_space); |
1235 | 1232 |
1236 // Starts downloading a file if we have enough disk space indicated by | 1233 // Starts downloading a file if we have enough disk space indicated by |
1237 // |has_enough_space|. | 1234 // |has_enough_space|. |
1238 void StartDownloadFileIfEnoughSpace(const GetFileFromCacheParams& params, | 1235 void StartDownloadFileIfEnoughSpace(const GetFileFromCacheParams& params, |
1239 const FilePath& cache_file_path, | 1236 const FilePath& cache_file_path, |
1240 bool* has_enough_space); | 1237 bool* has_enough_space); |
1241 | 1238 |
1242 // Cache internal helper functions. | 1239 // Cache internal helper functions. |
1243 | 1240 |
1244 // Unsafe (unlocked) version of InitializeCacheIfnecessary method. | 1241 // Unsafe (unlocked) version of InitializeCacheIfnecessary method. |
1245 void UnsafeInitializeCacheIfNecessary(); | 1242 void UnsafeInitializeCacheIfNecessary(); |
1246 | 1243 |
1247 // Scans cache subdirectory |sub_dir_type| and build or update |cache_map| | 1244 // Scans cache subdirectory |sub_dir_type| and build or update |cache_map| |
1248 // with found file blobs or symlinks. | 1245 // with found file blobs or symlinks. |
1249 void ScanCacheDirectory( | 1246 void ScanCacheDirectory( |
1250 GDataRootDirectory::CacheSubDirectoryType sub_dir_type, | 1247 GDataRootDirectory::CacheSubDirectoryType sub_dir_type, |
1251 GDataRootDirectory::CacheMap* cache_map); | 1248 GDataRootDirectory::CacheMap* cache_map); |
1252 | 1249 |
1253 // Called from GetFileFromCacheByResourceIdAndMd5() and | |
1254 // GetFileFromCacheByPath(). | |
1255 void GetFileFromCacheByResourceIdAndMd5Internal( | |
1256 const std::string& resource_id, | |
1257 const std::string& md5, | |
1258 const FilePath& gdata_file_path, | |
1259 const GetFileFromCacheCallback& callback); | |
1260 | |
1261 // Wrapper task around any sequenced task that runs on IO thread pool that | 1250 // Wrapper task around any sequenced task that runs on IO thread pool that |
1262 // makes sure |in_shutdown_| and |on_io_completed_| are handled properly in | 1251 // makes sure |in_shutdown_| and |on_io_completed_| are handled properly in |
1263 // the right order. | 1252 // the right order. |
1264 void RunTaskOnIOThreadPool(const base::Closure& task); | 1253 void RunTaskOnIOThreadPool(const base::Closure& task); |
1265 | 1254 |
1266 // Wrapper around BrowserThread::PostTask to post | 1255 // Wrapper around BrowserThread::PostTask to post |
1267 // RunTaskOnIOThreadPool task to the blocking thread pool. | 1256 // RunTaskOnIOThreadPool task to the blocking thread pool. |
1268 // TODO(satorux): As of now, it's posting to FILE thread. | 1257 // TODO(satorux): As of now, it's posting to FILE thread. |
1269 void PostBlockingPoolSequencedTask( | 1258 void PostBlockingPoolSequencedTask( |
1270 const std::string& sequence_token_name, | 1259 const std::string& sequence_token_name, |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1357 }; | 1346 }; |
1358 | 1347 |
1359 // Sets the free disk space getter for testing. | 1348 // Sets the free disk space getter for testing. |
1360 // The existing getter is deleted. | 1349 // The existing getter is deleted. |
1361 void SetFreeDiskSpaceGetterForTesting( | 1350 void SetFreeDiskSpaceGetterForTesting( |
1362 FreeDiskSpaceGetterInterface* getter); | 1351 FreeDiskSpaceGetterInterface* getter); |
1363 | 1352 |
1364 } // namespace gdata | 1353 } // namespace gdata |
1365 | 1354 |
1366 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | 1355 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
OLD | NEW |