| 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_DRIVE_FILE_CACHE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // FileCache is used to maintain cache states of FileSystem. | 64 // FileCache is used to maintain cache states of FileSystem. |
| 65 // | 65 // |
| 66 // All non-static public member functions, unless mentioned otherwise (see | 66 // All non-static public member functions, unless mentioned otherwise (see |
| 67 // GetCacheFilePath() for example), should be run with |blocking_task_runner|. | 67 // GetCacheFilePath() for example), should be run with |blocking_task_runner|. |
| 68 class FileCache { | 68 class FileCache { |
| 69 public: | 69 public: |
| 70 // Enum defining GCache subdirectory location. | 70 // Enum defining GCache subdirectory location. |
| 71 // This indexes into |FileCache::cache_paths_| vector. | 71 // This indexes into |FileCache::cache_paths_| vector. |
| 72 enum CacheSubDirectoryType { | 72 enum CacheSubDirectoryType { |
| 73 CACHE_TYPE_META = 0, // Resource metadata. | 73 CACHE_TYPE_META = 0, // Resource metadata. |
| 74 CACHE_TYPE_PERSISTENT, // Files that are pinned or modified locally, | 74 CACHE_TYPE_FILES, // Cached files. |
| 75 // not evictable, hopefully. | |
| 76 CACHE_TYPE_TMP, // Files that don't meet criteria to be in | |
| 77 // persistent dir, and hence evictable. | |
| 78 CACHE_TYPE_TMP_DOWNLOADS, // Downloaded files. | 75 CACHE_TYPE_TMP_DOWNLOADS, // Downloaded files. |
| 79 CACHE_TYPE_TMP_DOCUMENTS, // Temporary JSON files for hosted documents. | 76 CACHE_TYPE_TMP_DOCUMENTS, // Temporary JSON files for hosted documents. |
| 80 NUM_CACHE_TYPES, // This must be at the end. | 77 NUM_CACHE_TYPES, // This must be at the end. |
| 81 }; | 78 }; |
| 82 | 79 |
| 83 // Enum defining type of file operation e.g. copy or move, etc. | 80 // Enum defining type of file operation e.g. copy or move, etc. |
| 84 enum FileOperationType { | 81 enum FileOperationType { |
| 85 FILE_OPERATION_MOVE = 0, | 82 FILE_OPERATION_MOVE = 0, |
| 86 FILE_OPERATION_COPY, | 83 FILE_OPERATION_COPY, |
| 87 }; | 84 }; |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 static std::vector<base::FilePath> GetCachePaths( | 269 static std::vector<base::FilePath> GetCachePaths( |
| 273 const base::FilePath& cache_root_path); | 270 const base::FilePath& cache_root_path); |
| 274 | 271 |
| 275 // Creates cache directory and its sub-directories if they don't exist. | 272 // Creates cache directory and its sub-directories if they don't exist. |
| 276 // TODO(glotov): take care of this when the setup and cleanup part is | 273 // TODO(glotov): take care of this when the setup and cleanup part is |
| 277 // landed, noting that these directories need to be created for development | 274 // landed, noting that these directories need to be created for development |
| 278 // in linux box and unittest. (http://crosbug.com/27577) | 275 // in linux box and unittest. (http://crosbug.com/27577) |
| 279 static bool CreateCacheDirectories( | 276 static bool CreateCacheDirectories( |
| 280 const std::vector<base::FilePath>& paths_to_create); | 277 const std::vector<base::FilePath>& paths_to_create); |
| 281 | 278 |
| 282 // Returns the type of the sub directory where the cache file is stored. | |
| 283 static CacheSubDirectoryType GetSubDirectoryType( | |
| 284 const FileCacheEntry& cache_entry); | |
| 285 | |
| 286 private: | 279 private: |
| 287 friend class FileCacheTest; | 280 friend class FileCacheTest; |
| 288 friend class FileCacheTestOnUIThread; | 281 friend class FileCacheTestOnUIThread; |
| 289 | 282 |
| 290 // Enum defining origin of a cached file. | 283 // Enum defining origin of a cached file. |
| 291 enum CachedFileOrigin { | 284 enum CachedFileOrigin { |
| 292 CACHED_FILE_FROM_SERVER = 0, | 285 CACHED_FILE_FROM_SERVER = 0, |
| 293 CACHED_FILE_LOCALLY_MODIFIED, | 286 CACHED_FILE_LOCALLY_MODIFIED, |
| 294 CACHED_FILE_MOUNTED, | 287 CACHED_FILE_MOUNTED, |
| 295 }; | 288 }; |
| 296 | 289 |
| 297 ~FileCache(); | 290 ~FileCache(); |
| 298 | 291 |
| 299 // Returns absolute path of the file if it were cached or to be cached. | 292 // Returns absolute path of the file if it were cached or to be cached. |
| 300 // | 293 // |
| 301 // Can be called on any thread. | 294 // Can be called on any thread. |
| 302 base::FilePath GetCacheFilePath(const std::string& resource_id, | 295 base::FilePath GetCacheFilePath(const std::string& resource_id, |
| 303 const std::string& md5, | 296 const std::string& md5, |
| 304 CacheSubDirectoryType sub_dir_type, | |
| 305 CachedFileOrigin file_origin) const; | 297 CachedFileOrigin file_origin) const; |
| 306 | 298 |
| 307 | 299 |
| 308 // Checks whether the current thread is on the right sequenced worker pool | 300 // Checks whether the current thread is on the right sequenced worker pool |
| 309 // with the right sequence ID. If not, DCHECK will fail. | 301 // with the right sequence ID. If not, DCHECK will fail. |
| 310 void AssertOnSequencedWorkerPool(); | 302 void AssertOnSequencedWorkerPool(); |
| 311 | 303 |
| 312 // Initializes the cache. Returns true on success. | 304 // Initializes the cache. Returns true on success. |
| 313 bool InitializeOnBlockingPool(); | 305 bool InitializeOnBlockingPool(); |
| 314 | 306 |
| 315 // Destroys the cache on the blocking pool. | 307 // Destroys the cache on the blocking pool. |
| 316 void DestroyOnBlockingPool(); | 308 void DestroyOnBlockingPool(); |
| 317 | 309 |
| 310 // Migrates files from old "persistent" and "tmp" directories to the new |
| 311 // "files" directory (see crbug.com/248905). |
| 312 // TODO(hashimoto): Remove this method at some point. |
| 313 void MigrateFilesFromOldDirectories(); |
| 314 |
| 318 // Used to implement Store and StoreLocallyModifiedOnUIThread. | 315 // Used to implement Store and StoreLocallyModifiedOnUIThread. |
| 319 // TODO(hidehiko): Merge this method with Store(), after | 316 // TODO(hidehiko): Merge this method with Store(), after |
| 320 // StoreLocallyModifiedOnUIThread is removed. | 317 // StoreLocallyModifiedOnUIThread is removed. |
| 321 FileError StoreInternal(const std::string& resource_id, | 318 FileError StoreInternal(const std::string& resource_id, |
| 322 const std::string& md5, | 319 const std::string& md5, |
| 323 const base::FilePath& source_path, | 320 const base::FilePath& source_path, |
| 324 FileOperationType file_operation_type); | 321 FileOperationType file_operation_type); |
| 325 | 322 |
| 326 // Used to implement MarkAsMountedOnUIThread. | 323 // Used to implement MarkAsMountedOnUIThread. |
| 327 FileError MarkAsMounted(const std::string& resource_id, | 324 FileError MarkAsMounted(const std::string& resource_id, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 // this value. | 357 // this value. |
| 361 // | 358 // |
| 362 // Copied from cryptohome/homedirs.h. | 359 // Copied from cryptohome/homedirs.h. |
| 363 // TODO(satorux): Share the constant. | 360 // TODO(satorux): Share the constant. |
| 364 const int64 kMinFreeSpace = 512 * 1LL << 20; | 361 const int64 kMinFreeSpace = 512 * 1LL << 20; |
| 365 | 362 |
| 366 } // namespace internal | 363 } // namespace internal |
| 367 } // namespace drive | 364 } // namespace drive |
| 368 | 365 |
| 369 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_H_ | 366 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_H_ |
| OLD | NEW |