| 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 <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 typedef base::Callback<void(bool success, const FileCacheEntry& cache_entry)> | 34 typedef base::Callback<void(bool success, const FileCacheEntry& cache_entry)> |
| 35 GetCacheEntryCallback; | 35 GetCacheEntryCallback; |
| 36 | 36 |
| 37 // Callback for Iterate(). | 37 // Callback for Iterate(). |
| 38 typedef base::Callback<void(const std::string& resource_id, | 38 typedef base::Callback<void(const std::string& resource_id, |
| 39 const FileCacheEntry& cache_entry)> | 39 const FileCacheEntry& cache_entry)> |
| 40 CacheIterateCallback; | 40 CacheIterateCallback; |
| 41 | 41 |
| 42 namespace internal { | 42 namespace internal { |
| 43 | 43 |
| 44 class FileCacheMetadata; | 44 class ResourceMetadataStorage; |
| 45 | 45 |
| 46 // Callback for GetFileFromCache. | 46 // Callback for GetFileFromCache. |
| 47 typedef base::Callback<void(FileError error, | 47 typedef base::Callback<void(FileError error, |
| 48 const base::FilePath& cache_file_path)> | 48 const base::FilePath& cache_file_path)> |
| 49 GetFileFromCacheCallback; | 49 GetFileFromCacheCallback; |
| 50 | 50 |
| 51 // Callback for RequestInitialize. | 51 // Callback for RequestInitialize. |
| 52 // |success| indicates if the operation was successful. | 52 // |success| indicates if the operation was successful. |
| 53 // TODO(satorux): Change this to FileError when it becomes necessary. | 53 // TODO(satorux): Change this to FileError when it becomes necessary. |
| 54 typedef base::Callback<void(bool success)> | 54 typedef base::Callback<void(bool success)> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 67 // All non-static public member functions, unless mentioned otherwise (see | 67 // All non-static public member functions, unless mentioned otherwise (see |
| 68 // GetCacheFilePath() for example), should be run with |blocking_task_runner|. | 68 // GetCacheFilePath() for example), should be run with |blocking_task_runner|. |
| 69 class FileCache { | 69 class FileCache { |
| 70 public: | 70 public: |
| 71 // Enum defining type of file operation e.g. copy or move, etc. | 71 // Enum defining type of file operation e.g. copy or move, etc. |
| 72 enum FileOperationType { | 72 enum FileOperationType { |
| 73 FILE_OPERATION_MOVE = 0, | 73 FILE_OPERATION_MOVE = 0, |
| 74 FILE_OPERATION_COPY, | 74 FILE_OPERATION_COPY, |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 // |metadata_directory| stores the metadata and |cache_file_directory| stores | 77 // |cache_file_directory| stores cached files. |
| 78 // cached files. | |
| 79 // | 78 // |
| 80 // |blocking_task_runner| is used to post a task to the blocking worker | 79 // |blocking_task_runner| is used to post a task to the blocking worker |
| 81 // pool for file operations. Must not be null. | 80 // pool for file operations. Must not be null. |
| 82 // | 81 // |
| 83 // |free_disk_space_getter| is used to inject a custom free disk space | 82 // |free_disk_space_getter| is used to inject a custom free disk space |
| 84 // getter for testing. NULL must be passed for production code. | 83 // getter for testing. NULL must be passed for production code. |
| 85 // | 84 // |
| 86 // Must be called on the UI thread. | 85 // Must be called on the UI thread. |
| 87 FileCache(const base::FilePath& metadata_directory, | 86 FileCache(ResourceMetadataStorage* storage, |
| 88 const base::FilePath& cache_file_directory, | 87 const base::FilePath& cache_file_directory, |
| 89 base::SequencedTaskRunner* blocking_task_runner, | 88 base::SequencedTaskRunner* blocking_task_runner, |
| 90 FreeDiskSpaceGetterInterface* free_disk_space_getter); | 89 FreeDiskSpaceGetterInterface* free_disk_space_getter); |
| 91 | 90 |
| 92 // Returns true if the given path is under drive cache directory, i.e. | 91 // Returns true if the given path is under drive cache directory, i.e. |
| 93 // <user_profile_dir>/GCache/v1 | 92 // <user_profile_dir>/GCache/v1 |
| 94 // | 93 // |
| 95 // Can be called on any thread. | 94 // Can be called on any thread. |
| 96 bool IsUnderFileCacheDirectory(const base::FilePath& path) const; | 95 bool IsUnderFileCacheDirectory(const base::FilePath& path) const; |
| 97 | 96 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 FileError MarkAsUnmounted(const base::FilePath& file_path); | 286 FileError MarkAsUnmounted(const base::FilePath& file_path); |
| 288 | 287 |
| 289 // Used to implement ClearAllOnUIThread. | 288 // Used to implement ClearAllOnUIThread. |
| 290 bool ClearAll(); | 289 bool ClearAll(); |
| 291 | 290 |
| 292 // Returns true if we have sufficient space to store the given number of | 291 // Returns true if we have sufficient space to store the given number of |
| 293 // bytes, while keeping kMinFreeSpace bytes on the disk. | 292 // bytes, while keeping kMinFreeSpace bytes on the disk. |
| 294 bool HasEnoughSpaceFor(int64 num_bytes, const base::FilePath& path); | 293 bool HasEnoughSpaceFor(int64 num_bytes, const base::FilePath& path); |
| 295 | 294 |
| 296 // Imports old format DB from |old_db_path| and deletes it. | 295 // Imports old format DB from |old_db_path| and deletes it. |
| 297 void ImportOldDB(const base::FilePath& old_db_path); | 296 // TODO(hashimoto): Remove this method and FileCacheMetadata at some point. |
| 297 bool ImportOldDB(const base::FilePath& old_db_path); |
| 298 | 298 |
| 299 const base::FilePath metadata_directory_; | |
| 300 const base::FilePath cache_file_directory_; | 299 const base::FilePath cache_file_directory_; |
| 301 | 300 |
| 302 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 301 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 303 | 302 |
| 304 // The cache state data. This member must be access only on the blocking pool. | 303 ResourceMetadataStorage* storage_; |
| 305 scoped_ptr<FileCacheMetadata> metadata_; | |
| 306 | 304 |
| 307 FreeDiskSpaceGetterInterface* free_disk_space_getter_; // Not owned. | 305 FreeDiskSpaceGetterInterface* free_disk_space_getter_; // Not owned. |
| 308 | 306 |
| 309 // Resource IDs of files marked mounted. | 307 // Resource IDs of files marked mounted. |
| 310 std::set<std::string> mounted_files_; | 308 std::set<std::string> mounted_files_; |
| 311 | 309 |
| 312 // Note: This should remain the last member so it'll be destroyed and | 310 // Note: This should remain the last member so it'll be destroyed and |
| 313 // invalidate its weak pointers before any other members are destroyed. | 311 // invalidate its weak pointers before any other members are destroyed. |
| 314 base::WeakPtrFactory<FileCache> weak_ptr_factory_; | 312 base::WeakPtrFactory<FileCache> weak_ptr_factory_; |
| 315 DISALLOW_COPY_AND_ASSIGN(FileCache); | 313 DISALLOW_COPY_AND_ASSIGN(FileCache); |
| 316 }; | 314 }; |
| 317 | 315 |
| 318 // The minimum free space to keep. FileSystem::GetFileByPath() returns | 316 // The minimum free space to keep. FileSystem::GetFileByPath() returns |
| 319 // GDATA_FILE_ERROR_NO_SPACE if the available space is smaller than | 317 // GDATA_FILE_ERROR_NO_SPACE if the available space is smaller than |
| 320 // this value. | 318 // this value. |
| 321 // | 319 // |
| 322 // Copied from cryptohome/homedirs.h. | 320 // Copied from cryptohome/homedirs.h. |
| 323 // TODO(satorux): Share the constant. | 321 // TODO(satorux): Share the constant. |
| 324 const int64 kMinFreeSpace = 512 * 1LL << 20; | 322 const int64 kMinFreeSpace = 512 * 1LL << 20; |
| 325 | 323 |
| 326 } // namespace internal | 324 } // namespace internal |
| 327 } // namespace drive | 325 } // namespace drive |
| 328 | 326 |
| 329 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_H_ | 327 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_H_ |
| OLD | NEW |