| 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_CACHE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "base/platform_file.h" | 17 #include "base/platform_file.h" |
| 18 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" | 18 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" |
| 19 | 19 |
| 20 class Profile; | 20 class Profile; |
| 21 | 21 |
| 22 namespace base { | 22 namespace base { |
| 23 | 23 |
| 24 class SequencedTaskRunner; | 24 class SequencedTaskRunner; |
| 25 | 25 |
| 26 } // namespace base | 26 } // namespace base |
| 27 | 27 |
| 28 namespace gdata { | 28 namespace gdata { |
| 29 | 29 |
| 30 class GDataCacheEntry; | 30 class DriveCacheEntry; |
| 31 class GDataCacheMetadata; | 31 class GDataCacheMetadata; |
| 32 | 32 |
| 33 // Callback for SetMountedStateOnUIThread and ClearAllOnUIThread. | 33 // Callback for SetMountedStateOnUIThread and ClearAllOnUIThread. |
| 34 typedef base::Callback<void(GDataFileError error, | 34 typedef base::Callback<void(GDataFileError error, |
| 35 const FilePath& file_path)> | 35 const FilePath& file_path)> |
| 36 ChangeCacheStateCallback; | 36 ChangeCacheStateCallback; |
| 37 | 37 |
| 38 // Callback for completion of cache operation. | 38 // Callback for completion of cache operation. |
| 39 typedef base::Callback<void(GDataFileError error, | 39 typedef base::Callback<void(GDataFileError error, |
| 40 const std::string& resource_id, | 40 const std::string& resource_id, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 55 GetResourceIdsOfBacklogCallback; | 55 GetResourceIdsOfBacklogCallback; |
| 56 | 56 |
| 57 // Callback for GetResourceIdsOfExistingPinnedFilesOnUIThread. | 57 // Callback for GetResourceIdsOfExistingPinnedFilesOnUIThread. |
| 58 typedef base::Callback<void(const std::vector<std::string>& resource_ids)> | 58 typedef base::Callback<void(const std::vector<std::string>& resource_ids)> |
| 59 GetResourceIdsCallback; | 59 GetResourceIdsCallback; |
| 60 | 60 |
| 61 // Callback for GetCacheEntryOnUIThread. | 61 // Callback for GetCacheEntryOnUIThread. |
| 62 // |success| indicates if the operation was successful. | 62 // |success| indicates if the operation was successful. |
| 63 // |cache_entry| is the obtained cache entry. On failure, |cache_state| is | 63 // |cache_entry| is the obtained cache entry. On failure, |cache_state| is |
| 64 // set to TEST_CACHE_STATE_NONE. | 64 // set to TEST_CACHE_STATE_NONE. |
| 65 typedef base::Callback<void(bool success, const GDataCacheEntry& cache_entry)> | 65 typedef base::Callback<void(bool success, const DriveCacheEntry& cache_entry)> |
| 66 GetCacheEntryCallback; | 66 GetCacheEntryCallback; |
| 67 | 67 |
| 68 // GDataCache is used to maintain cache states of GDataFileSystem. | 68 // GDataCache is used to maintain cache states of GDataFileSystem. |
| 69 // | 69 // |
| 70 // All non-static public member functions, unless mentioned otherwise (see | 70 // All non-static public member functions, unless mentioned otherwise (see |
| 71 // GetCacheFilePath() for example), should be called from the sequenced | 71 // GetCacheFilePath() for example), should be called from the sequenced |
| 72 // worker pool with the sequence token set by CreateGDataCacheOnUIThread(). This | 72 // worker pool with the sequence token set by CreateGDataCacheOnUIThread(). This |
| 73 // threading model is enforced by AssertOnSequencedWorkerPool(). | 73 // threading model is enforced by AssertOnSequencedWorkerPool(). |
| 74 // | 74 // |
| 75 // TODO(hashimoto): Change threading model of this class to make public methods | 75 // TODO(hashimoto): Change threading model of this class to make public methods |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 // Force a rescan of cache files, for testing. | 278 // Force a rescan of cache files, for testing. |
| 279 void ForceRescanOnUIThreadForTesting(); | 279 void ForceRescanOnUIThreadForTesting(); |
| 280 | 280 |
| 281 // Gets the cache entry for file corresponding to |resource_id| and |md5| | 281 // Gets the cache entry for file corresponding to |resource_id| and |md5| |
| 282 // and returns true if entry exists in cache map. Otherwise, returns false. | 282 // and returns true if entry exists in cache map. Otherwise, returns false. |
| 283 // |md5| can be empty if only matching |resource_id| is desired, which may | 283 // |md5| can be empty if only matching |resource_id| is desired, which may |
| 284 // happen when looking for pinned entries where symlinks' filenames have no | 284 // happen when looking for pinned entries where symlinks' filenames have no |
| 285 // extension and hence no md5. | 285 // extension and hence no md5. |
| 286 bool GetCacheEntry(const std::string& resource_id, | 286 bool GetCacheEntry(const std::string& resource_id, |
| 287 const std::string& md5, | 287 const std::string& md5, |
| 288 GDataCacheEntry* entry); | 288 DriveCacheEntry* entry); |
| 289 | 289 |
| 290 // Factory methods for GDataCache. | 290 // Factory methods for GDataCache. |
| 291 // |pool| and |sequence_token| are used to assert that the functions are | 291 // |pool| and |sequence_token| are used to assert that the functions are |
| 292 // called on the right sequenced worker pool with the right sequence token. | 292 // called on the right sequenced worker pool with the right sequence token. |
| 293 // | 293 // |
| 294 // For testing, the thread assertion can be disabled by passing NULL and | 294 // For testing, the thread assertion can be disabled by passing NULL and |
| 295 // the default value of SequenceToken. | 295 // the default value of SequenceToken. |
| 296 static GDataCache* CreateGDataCacheOnUIThread( | 296 static GDataCache* CreateGDataCacheOnUIThread( |
| 297 const FilePath& cache_root_path, | 297 const FilePath& cache_root_path, |
| 298 base::SequencedTaskRunner* blocking_task_runner); | 298 base::SequencedTaskRunner* blocking_task_runner); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 311 | 311 |
| 312 // Creates cache directory and its sub-directories if they don't exist. | 312 // Creates cache directory and its sub-directories if they don't exist. |
| 313 // TODO(glotov): take care of this when the setup and cleanup part is | 313 // TODO(glotov): take care of this when the setup and cleanup part is |
| 314 // landed, noting that these directories need to be created for development | 314 // landed, noting that these directories need to be created for development |
| 315 // in linux box and unittest. (http://crosbug.com/27577) | 315 // in linux box and unittest. (http://crosbug.com/27577) |
| 316 static bool CreateCacheDirectories( | 316 static bool CreateCacheDirectories( |
| 317 const std::vector<FilePath>& paths_to_create); | 317 const std::vector<FilePath>& paths_to_create); |
| 318 | 318 |
| 319 // Returns the type of the sub directory where the cache file is stored. | 319 // Returns the type of the sub directory where the cache file is stored. |
| 320 static CacheSubDirectoryType GetSubDirectoryType( | 320 static CacheSubDirectoryType GetSubDirectoryType( |
| 321 const GDataCacheEntry& cache_entry); | 321 const DriveCacheEntry& cache_entry); |
| 322 | 322 |
| 323 private: | 323 private: |
| 324 GDataCache(const FilePath& cache_root_path, | 324 GDataCache(const FilePath& cache_root_path, |
| 325 base::SequencedTaskRunner* blocking_task_runner); | 325 base::SequencedTaskRunner* blocking_task_runner); |
| 326 virtual ~GDataCache(); | 326 virtual ~GDataCache(); |
| 327 | 327 |
| 328 // Checks whether the current thread is on the right sequenced worker pool | 328 // Checks whether the current thread is on the right sequenced worker pool |
| 329 // with the right sequence ID. If not, DCHECK will fail. | 329 // with the right sequence ID. If not, DCHECK will fail. |
| 330 void AssertOnSequencedWorkerPool(); | 330 void AssertOnSequencedWorkerPool(); |
| 331 | 331 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 // Runs callback and notifies the observers when file is committed. | 427 // Runs callback and notifies the observers when file is committed. |
| 428 void OnCommitDirty(GDataFileError* error, | 428 void OnCommitDirty(GDataFileError* error, |
| 429 const std::string& resource_id, | 429 const std::string& resource_id, |
| 430 const std::string& md5, | 430 const std::string& md5, |
| 431 const CacheOperationCallback& callback); | 431 const CacheOperationCallback& callback); |
| 432 | 432 |
| 433 // Helper function to implement GetCacheEntryOnUIThread(). | 433 // Helper function to implement GetCacheEntryOnUIThread(). |
| 434 void GetCacheEntryHelper(const std::string& resource_id, | 434 void GetCacheEntryHelper(const std::string& resource_id, |
| 435 const std::string& md5, | 435 const std::string& md5, |
| 436 bool* success, | 436 bool* success, |
| 437 GDataCacheEntry* cache_entry); | 437 DriveCacheEntry* cache_entry); |
| 438 | 438 |
| 439 // The root directory of the cache (i.e. <user_profile_dir>/GCache/v1). | 439 // The root directory of the cache (i.e. <user_profile_dir>/GCache/v1). |
| 440 const FilePath cache_root_path_; | 440 const FilePath cache_root_path_; |
| 441 // Paths for all subdirectories of GCache, one for each | 441 // Paths for all subdirectories of GCache, one for each |
| 442 // GDataCache::CacheSubDirectoryType enum. | 442 // GDataCache::CacheSubDirectoryType enum. |
| 443 const std::vector<FilePath> cache_paths_; | 443 const std::vector<FilePath> cache_paths_; |
| 444 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 444 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 445 | 445 |
| 446 // The cache state data. This member must be access only on the blocking pool. | 446 // The cache state data. This member must be access only on the blocking pool. |
| 447 scoped_ptr<GDataCacheMetadata> metadata_; | 447 scoped_ptr<GDataCacheMetadata> metadata_; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 472 }; | 472 }; |
| 473 | 473 |
| 474 // Sets the free disk space getter for testing. | 474 // Sets the free disk space getter for testing. |
| 475 // The existing getter is deleted. | 475 // The existing getter is deleted. |
| 476 void SetFreeDiskSpaceGetterForTesting( | 476 void SetFreeDiskSpaceGetterForTesting( |
| 477 FreeDiskSpaceGetterInterface* getter); | 477 FreeDiskSpaceGetterInterface* getter); |
| 478 | 478 |
| 479 } // namespace gdata | 479 } // namespace gdata |
| 480 | 480 |
| 481 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_ | 481 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_ |
| OLD | NEW |