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 // Name of the cache metadata DB previously used. |
78 // cached files. | 78 // TODO(hashimoto): Remove this at some point. |
| 79 static const base::FilePath::CharType kOldCacheMetadataDBName[]; |
| 80 |
| 81 // |cache_file_directory| stores cached files. |
79 // | 82 // |
80 // |blocking_task_runner| is used to post a task to the blocking worker | 83 // |blocking_task_runner| is used to post a task to the blocking worker |
81 // pool for file operations. Must not be null. | 84 // pool for file operations. Must not be null. |
82 // | 85 // |
83 // |free_disk_space_getter| is used to inject a custom free disk space | 86 // |free_disk_space_getter| is used to inject a custom free disk space |
84 // getter for testing. NULL must be passed for production code. | 87 // getter for testing. NULL must be passed for production code. |
85 // | 88 // |
86 // Must be called on the UI thread. | 89 // Must be called on the UI thread. |
87 FileCache(const base::FilePath& metadata_directory, | 90 FileCache(ResourceMetadataStorage* storage, |
88 const base::FilePath& cache_file_directory, | 91 const base::FilePath& cache_file_directory, |
89 base::SequencedTaskRunner* blocking_task_runner, | 92 base::SequencedTaskRunner* blocking_task_runner, |
90 FreeDiskSpaceGetterInterface* free_disk_space_getter); | 93 FreeDiskSpaceGetterInterface* free_disk_space_getter); |
91 | 94 |
92 // Returns true if the given path is under drive cache directory, i.e. | 95 // Returns true if the given path is under drive cache directory, i.e. |
93 // <user_profile_dir>/GCache/v1 | 96 // <user_profile_dir>/GCache/v1 |
94 // | 97 // |
95 // Can be called on any thread. | 98 // Can be called on any thread. |
96 bool IsUnderFileCacheDirectory(const base::FilePath& path) const; | 99 bool IsUnderFileCacheDirectory(const base::FilePath& path) const; |
97 | 100 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 FileError MarkAsUnmounted(const base::FilePath& file_path); | 290 FileError MarkAsUnmounted(const base::FilePath& file_path); |
288 | 291 |
289 // Used to implement ClearAllOnUIThread. | 292 // Used to implement ClearAllOnUIThread. |
290 bool ClearAll(); | 293 bool ClearAll(); |
291 | 294 |
292 // Returns true if we have sufficient space to store the given number of | 295 // Returns true if we have sufficient space to store the given number of |
293 // bytes, while keeping kMinFreeSpace bytes on the disk. | 296 // bytes, while keeping kMinFreeSpace bytes on the disk. |
294 bool HasEnoughSpaceFor(int64 num_bytes, const base::FilePath& path); | 297 bool HasEnoughSpaceFor(int64 num_bytes, const base::FilePath& path); |
295 | 298 |
296 // Imports old format DB from |old_db_path| and deletes it. | 299 // Imports old format DB from |old_db_path| and deletes it. |
297 void ImportOldDB(const base::FilePath& old_db_path); | 300 // TODO(hashimoto): Remove this method and FileCacheMetadata at some point. |
| 301 bool ImportOldDB(const base::FilePath& old_db_path); |
298 | 302 |
299 const base::FilePath metadata_directory_; | |
300 const base::FilePath cache_file_directory_; | 303 const base::FilePath cache_file_directory_; |
301 | 304 |
302 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 305 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
303 | 306 |
304 // The cache state data. This member must be access only on the blocking pool. | 307 ResourceMetadataStorage* storage_; |
305 scoped_ptr<FileCacheMetadata> metadata_; | |
306 | 308 |
307 FreeDiskSpaceGetterInterface* free_disk_space_getter_; // Not owned. | 309 FreeDiskSpaceGetterInterface* free_disk_space_getter_; // Not owned. |
308 | 310 |
309 // Resource IDs of files marked mounted. | 311 // Resource IDs of files marked mounted. |
310 std::set<std::string> mounted_files_; | 312 std::set<std::string> mounted_files_; |
311 | 313 |
312 // Note: This should remain the last member so it'll be destroyed and | 314 // Note: This should remain the last member so it'll be destroyed and |
313 // invalidate its weak pointers before any other members are destroyed. | 315 // invalidate its weak pointers before any other members are destroyed. |
314 base::WeakPtrFactory<FileCache> weak_ptr_factory_; | 316 base::WeakPtrFactory<FileCache> weak_ptr_factory_; |
315 DISALLOW_COPY_AND_ASSIGN(FileCache); | 317 DISALLOW_COPY_AND_ASSIGN(FileCache); |
316 }; | 318 }; |
317 | 319 |
318 // The minimum free space to keep. FileSystem::GetFileByPath() returns | 320 // The minimum free space to keep. FileSystem::GetFileByPath() returns |
319 // GDATA_FILE_ERROR_NO_SPACE if the available space is smaller than | 321 // GDATA_FILE_ERROR_NO_SPACE if the available space is smaller than |
320 // this value. | 322 // this value. |
321 // | 323 // |
322 // Copied from cryptohome/homedirs.h. | 324 // Copied from cryptohome/homedirs.h. |
323 // TODO(satorux): Share the constant. | 325 // TODO(satorux): Share the constant. |
324 const int64 kMinFreeSpace = 512 * 1LL << 20; | 326 const int64 kMinFreeSpace = 512 * 1LL << 20; |
325 | 327 |
326 } // namespace internal | 328 } // namespace internal |
327 } // namespace drive | 329 } // namespace drive |
328 | 330 |
329 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_H_ | 331 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CACHE_H_ |
OLD | NEW |