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