| 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_METADATA_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_METADATA_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_METADATA_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_METADATA_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "chrome/browser/chromeos/gdata/gdata_cache.h" | 14 #include "chrome/browser/chromeos/gdata/gdata_cache.h" |
| 15 | 15 |
| 16 namespace gdata { | 16 namespace gdata { |
| 17 | 17 |
| 18 // GDataCacheMetadata is interface to maintain metadata of GDataCache's cached | 18 // GDataCacheMetadata is interface to maintain metadata of GDataCache's cached |
| 19 // files. This class only manages metadata. File operations are done by | 19 // files. This class only manages metadata. File operations are done by |
| 20 // GDataCache. | 20 // GDataCache. |
| 21 // All member access including ctor and dtor must be made on the blocking pool. | 21 // All member access including ctor and dtor must be made on the blocking pool. |
| 22 class GDataCacheMetadata { | 22 class GDataCacheMetadata { |
| 23 public: | 23 public: |
| 24 // Callback for Iterate(). | 24 // Callback for Iterate(). |
| 25 typedef base::Callback<void(const std::string& resource_id, | 25 typedef base::Callback<void(const std::string& resource_id, |
| 26 const GDataCacheEntry& cache_entry)> | 26 const DriveCacheEntry& cache_entry)> |
| 27 IterateCallback; | 27 IterateCallback; |
| 28 | 28 |
| 29 // A map table of cache file's resource id to its CacheEntry* entry. | 29 // A map table of cache file's resource id to its CacheEntry* entry. |
| 30 typedef std::map<std::string, GDataCacheEntry> CacheMap; | 30 typedef std::map<std::string, DriveCacheEntry> CacheMap; |
| 31 | 31 |
| 32 virtual ~GDataCacheMetadata(); | 32 virtual ~GDataCacheMetadata(); |
| 33 | 33 |
| 34 // Creates GDataCacheMetadata instance. | 34 // Creates GDataCacheMetadata instance. |
| 35 static scoped_ptr<GDataCacheMetadata> CreateGDataCacheMetadata( | 35 static scoped_ptr<GDataCacheMetadata> CreateGDataCacheMetadata( |
| 36 base::SequencedTaskRunner* blocking_task_runner); | 36 base::SequencedTaskRunner* blocking_task_runner); |
| 37 | 37 |
| 38 // Creates GDataCacheMetadata instance. This uses FakeGDataCacheMetadata, | 38 // Creates GDataCacheMetadata instance. This uses FakeGDataCacheMetadata, |
| 39 // which is an in-memory implmentation and faster than GDataCacheMetadataDB. | 39 // which is an in-memory implmentation and faster than GDataCacheMetadataDB. |
| 40 static scoped_ptr<GDataCacheMetadata> CreateGDataCacheMetadataForTesting( | 40 static scoped_ptr<GDataCacheMetadata> CreateGDataCacheMetadataForTesting( |
| 41 base::SequencedTaskRunner* blocking_task_runner); | 41 base::SequencedTaskRunner* blocking_task_runner); |
| 42 | 42 |
| 43 // Initialize the cache metadata store. | 43 // Initialize the cache metadata store. |
| 44 virtual void Initialize(const std::vector<FilePath>& cache_paths) = 0; | 44 virtual void Initialize(const std::vector<FilePath>& cache_paths) = 0; |
| 45 // Adds a new cache entry corresponding to |resource_id| if it doesn't | 45 // Adds a new cache entry corresponding to |resource_id| if it doesn't |
| 46 // exist, otherwise update the existing entry. | 46 // exist, otherwise update the existing entry. |
| 47 virtual void AddOrUpdateCacheEntry(const std::string& resource_id, | 47 virtual void AddOrUpdateCacheEntry(const std::string& resource_id, |
| 48 const GDataCacheEntry& cache_entry) = 0; | 48 const DriveCacheEntry& cache_entry) = 0; |
| 49 | 49 |
| 50 // Removes entry corresponding to |resource_id| from cache map. | 50 // Removes entry corresponding to |resource_id| from cache map. |
| 51 virtual void RemoveCacheEntry(const std::string& resource_id) = 0; | 51 virtual void RemoveCacheEntry(const std::string& resource_id) = 0; |
| 52 | 52 |
| 53 // Gets the cache entry for file corresponding to |resource_id| and |md5| | 53 // Gets the cache entry for file corresponding to |resource_id| and |md5| |
| 54 // and returns true if entry exists in cache map. Otherwise, returns false. | 54 // and returns true if entry exists in cache map. Otherwise, returns false. |
| 55 // |md5| can be empty if only matching |resource_id| is desired, which may | 55 // |md5| can be empty if only matching |resource_id| is desired, which may |
| 56 // happen when looking for pinned entries where symlinks' filenames have no | 56 // happen when looking for pinned entries where symlinks' filenames have no |
| 57 // extension and hence no md5. | 57 // extension and hence no md5. |
| 58 virtual bool GetCacheEntry(const std::string& resource_id, | 58 virtual bool GetCacheEntry(const std::string& resource_id, |
| 59 const std::string& md5, | 59 const std::string& md5, |
| 60 GDataCacheEntry* entry) = 0; | 60 DriveCacheEntry* entry) = 0; |
| 61 | 61 |
| 62 // Removes temporary files (files in CACHE_TYPE_TMP) from the cache map. | 62 // Removes temporary files (files in CACHE_TYPE_TMP) from the cache map. |
| 63 virtual void RemoveTemporaryFiles() = 0; | 63 virtual void RemoveTemporaryFiles() = 0; |
| 64 | 64 |
| 65 // Iterates over all the cache entries synchronously. |callback| is called | 65 // Iterates over all the cache entries synchronously. |callback| is called |
| 66 // on each cache entry. | 66 // on each cache entry. |
| 67 virtual void Iterate(const IterateCallback& callback) = 0; | 67 virtual void Iterate(const IterateCallback& callback) = 0; |
| 68 | 68 |
| 69 // Force a rescan of cache directories, for testing. | 69 // Force a rescan of cache directories, for testing. |
| 70 virtual void ForceRescanForTesting( | 70 virtual void ForceRescanForTesting( |
| 71 const std::vector<FilePath>& cache_paths) = 0; | 71 const std::vector<FilePath>& cache_paths) = 0; |
| 72 | 72 |
| 73 protected: | 73 protected: |
| 74 explicit GDataCacheMetadata(base::SequencedTaskRunner* blocking_task_runner); | 74 explicit GDataCacheMetadata(base::SequencedTaskRunner* blocking_task_runner); |
| 75 | 75 |
| 76 // Checks whether the current thread is on the right sequenced worker pool | 76 // Checks whether the current thread is on the right sequenced worker pool |
| 77 // with the right sequence ID. If not, DCHECK will fail. | 77 // with the right sequence ID. If not, DCHECK will fail. |
| 78 void AssertOnSequencedWorkerPool(); | 78 void AssertOnSequencedWorkerPool(); |
| 79 | 79 |
| 80 private: | 80 private: |
| 81 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 81 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 82 | 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(GDataCacheMetadata); | 83 DISALLOW_COPY_AND_ASSIGN(GDataCacheMetadata); |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 } // namespace gdata | 86 } // namespace gdata |
| 87 | 87 |
| 88 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_METADATA_H_ | 88 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_METADATA_H_ |
| OLD | NEW |