| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 // Updates cache map with entry corresponding to |resource_id|. | 36 // Updates cache map with entry corresponding to |resource_id|. |
| 37 // Creates new entry if it doesn't exist, otherwise update the entry. | 37 // Creates new entry if it doesn't exist, otherwise update the entry. |
| 38 virtual void UpdateCache(const std::string& resource_id, | 38 virtual void UpdateCache(const std::string& resource_id, |
| 39 const std::string& md5, | 39 const std::string& md5, |
| 40 GDataCache::CacheSubDirectoryType subdir, | 40 GDataCache::CacheSubDirectoryType subdir, |
| 41 int cache_state) = 0; | 41 int cache_state) = 0; |
| 42 | 42 |
| 43 // Removes entry corresponding to |resource_id| from cache map. | 43 // Removes entry corresponding to |resource_id| from cache map. |
| 44 virtual void RemoveFromCache(const std::string& resource_id) = 0; | 44 virtual void RemoveFromCache(const std::string& resource_id) = 0; |
| 45 | 45 |
| 46 // Returns the cache entry for file corresponding to |resource_id| and |md5| | 46 // Gets the cache entry for file corresponding to |resource_id| and |md5| |
| 47 // if entry exists in cache map. Otherwise, returns NULL. | 47 // and returns true if entry exists in cache map. Otherwise, returns false. |
| 48 // |md5| can be empty if only matching |resource_id| is desired, which may | 48 // |md5| can be empty if only matching |resource_id| is desired, which may |
| 49 // happen when looking for pinned entries where symlinks' filenames have no | 49 // happen when looking for pinned entries where symlinks' filenames have no |
| 50 // extension and hence no md5. | 50 // extension and hence no md5. |
| 51 virtual scoped_ptr<GDataCache::CacheEntry> GetCacheEntry( | 51 virtual bool GetCacheEntry(const std::string& resource_id, |
| 52 const std::string& resource_id, | 52 const std::string& md5, |
| 53 const std::string& md5) = 0; | 53 GDataCache::CacheEntry* entry) = 0; |
| 54 | 54 |
| 55 // Removes temporary files (files in CACHE_TYPE_TMP) from the cache map. | 55 // Removes temporary files (files in CACHE_TYPE_TMP) from the cache map. |
| 56 virtual void RemoveTemporaryFiles() = 0; | 56 virtual void RemoveTemporaryFiles() = 0; |
| 57 | 57 |
| 58 // Iterates over all the cache entries synchronously. |callback| is called | 58 // Iterates over all the cache entries synchronously. |callback| is called |
| 59 // on each cache entry. | 59 // on each cache entry. |
| 60 virtual void Iterate(const IterateCallback& callback) = 0; | 60 virtual void Iterate(const IterateCallback& callback) = 0; |
| 61 | 61 |
| 62 protected: | 62 protected: |
| 63 // Checks whether the current thread is on the right sequenced worker pool | 63 // Checks whether the current thread is on the right sequenced worker pool |
| (...skipping 17 matching lines...) Expand all Loading... |
| 81 | 81 |
| 82 // Initializes the data. | 82 // Initializes the data. |
| 83 void Initialize(const std::vector<FilePath>& cache_paths); | 83 void Initialize(const std::vector<FilePath>& cache_paths); |
| 84 | 84 |
| 85 // GDataCacheMetadata overrides: | 85 // GDataCacheMetadata overrides: |
| 86 virtual void UpdateCache(const std::string& resource_id, | 86 virtual void UpdateCache(const std::string& resource_id, |
| 87 const std::string& md5, | 87 const std::string& md5, |
| 88 GDataCache::CacheSubDirectoryType subdir, | 88 GDataCache::CacheSubDirectoryType subdir, |
| 89 int cache_state) OVERRIDE; | 89 int cache_state) OVERRIDE; |
| 90 virtual void RemoveFromCache(const std::string& resource_id) OVERRIDE; | 90 virtual void RemoveFromCache(const std::string& resource_id) OVERRIDE; |
| 91 virtual scoped_ptr<GDataCache::CacheEntry> GetCacheEntry( | 91 virtual bool GetCacheEntry(const std::string& resource_id, |
| 92 const std::string& resource_id, | 92 const std::string& md5, |
| 93 const std::string& md5) OVERRIDE; | 93 GDataCache::CacheEntry* entry) OVERRIDE; |
| 94 virtual void RemoveTemporaryFiles() OVERRIDE; | 94 virtual void RemoveTemporaryFiles() OVERRIDE; |
| 95 virtual void Iterate(const IterateCallback& callback) OVERRIDE; | 95 virtual void Iterate(const IterateCallback& callback) OVERRIDE; |
| 96 | 96 |
| 97 private: | 97 private: |
| 98 friend class GDataCacheMetadataMapTest; | 98 friend class GDataCacheMetadataMapTest; |
| 99 FRIEND_TEST_ALL_PREFIXES(GDataCacheMetadataMapTest, RemoveTemporaryFilesTest); | 99 FRIEND_TEST_ALL_PREFIXES(GDataCacheMetadataMapTest, RemoveTemporaryFilesTest); |
| 100 | 100 |
| 101 // A map table of cache file's resource id to its CacheEntry* entry. | 101 // A map table of cache file's resource id to its CacheEntry* entry. |
| 102 typedef std::map<std::string, GDataCache::CacheEntry> CacheMap; | 102 typedef std::map<std::string, GDataCache::CacheEntry> CacheMap; |
| 103 | 103 |
| 104 // Scans cache subdirectory and build or update |cache_map| | 104 // Scans cache subdirectory and build or update |cache_map| |
| 105 // with found file blobs or symlinks. | 105 // with found file blobs or symlinks. |
| 106 void ScanCacheDirectory(const std::vector<FilePath>& cache_paths, | 106 void ScanCacheDirectory(const std::vector<FilePath>& cache_paths, |
| 107 GDataCache::CacheSubDirectoryType sub_dir_type, | 107 GDataCache::CacheSubDirectoryType sub_dir_type, |
| 108 CacheMap* cache_map); | 108 CacheMap* cache_map); |
| 109 | 109 |
| 110 // Returns true if |md5| matches the one in |cache_entry| with some | 110 // Returns true if |md5| matches the one in |cache_entry| with some |
| 111 // exceptions. See the function definition for details. | 111 // exceptions. See the function definition for details. |
| 112 static bool CheckIfMd5Matches(const std::string& md5, | 112 static bool CheckIfMd5Matches(const std::string& md5, |
| 113 const GDataCache::CacheEntry& cache_entry); | 113 const GDataCache::CacheEntry& cache_entry); |
| 114 | 114 |
| 115 CacheMap cache_map_; | 115 CacheMap cache_map_; |
| 116 | 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(GDataCacheMetadataMap); | 117 DISALLOW_COPY_AND_ASSIGN(GDataCacheMetadataMap); |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 } // namespace gdata | 120 } // namespace gdata |
| 121 | 121 |
| 122 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_METADATA_H_ | 122 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_METADATA_H_ |
| OLD | NEW |