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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/file_path.h" | |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 | 14 |
14 namespace gdata { | 15 namespace gdata { |
15 | 16 |
16 class GDataCache { | 17 class GDataCache { |
17 public: | 18 public: |
18 // Enum defining GCache subdirectory location. | 19 // Enum defining GCache subdirectory location. |
19 // This indexes into |GDataFileSystem::cache_paths_| vector. | 20 // This indexes into |GDataFileSystem::cache_paths_| vector. |
20 enum CacheSubDirectoryType { | 21 enum CacheSubDirectoryType { |
21 CACHE_TYPE_META = 0, // Downloaded feeds. | 22 CACHE_TYPE_META = 0, // Downloaded feeds. |
(...skipping 13 matching lines...) Expand all Loading... | |
35 | 36 |
36 // This is used as a bitmask for the cache state. | 37 // This is used as a bitmask for the cache state. |
37 enum CacheState { | 38 enum CacheState { |
38 CACHE_STATE_NONE = 0x0, | 39 CACHE_STATE_NONE = 0x0, |
39 CACHE_STATE_PINNED = 0x1 << 0, | 40 CACHE_STATE_PINNED = 0x1 << 0, |
40 CACHE_STATE_PRESENT = 0x1 << 1, | 41 CACHE_STATE_PRESENT = 0x1 << 1, |
41 CACHE_STATE_DIRTY = 0x1 << 2, | 42 CACHE_STATE_DIRTY = 0x1 << 2, |
42 CACHE_STATE_MOUNTED = 0x1 << 3, | 43 CACHE_STATE_MOUNTED = 0x1 << 3, |
43 }; | 44 }; |
44 | 45 |
46 // Enum defining origin of a cached file. | |
47 enum CachedFileOrigin { | |
48 CACHED_FILE_FROM_SERVER = 0, | |
49 CACHED_FILE_LOCALLY_MODIFIED, | |
50 CACHED_FILE_MOUNTED, | |
51 }; | |
52 | |
53 static const char kMountedArchiveFileExtension[]; | |
54 | |
45 // Structure to store information of an existing cache file. | 55 // Structure to store information of an existing cache file. |
46 struct CacheEntry { | 56 struct CacheEntry { |
47 CacheEntry(const std::string& md5, | 57 CacheEntry(const std::string& md5, |
48 CacheSubDirectoryType sub_dir_type, | 58 CacheSubDirectoryType sub_dir_type, |
49 int cache_state) | 59 int cache_state) |
50 : md5(md5), | 60 : md5(md5), |
51 sub_dir_type(sub_dir_type), | 61 sub_dir_type(sub_dir_type), |
52 cache_state(cache_state) { | 62 cache_state(cache_state) { |
53 } | 63 } |
54 | 64 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 } | 110 } |
101 static int ClearCacheMounted(int cache_state) { | 111 static int ClearCacheMounted(int cache_state) { |
102 return cache_state &= ~CACHE_STATE_MOUNTED; | 112 return cache_state &= ~CACHE_STATE_MOUNTED; |
103 } | 113 } |
104 | 114 |
105 // A map table of cache file's resource id to its CacheEntry* entry. | 115 // A map table of cache file's resource id to its CacheEntry* entry. |
106 typedef std::map<std::string, CacheEntry> CacheMap; | 116 typedef std::map<std::string, CacheEntry> CacheMap; |
107 | 117 |
108 virtual ~GDataCache(); | 118 virtual ~GDataCache(); |
109 | 119 |
120 // Returns the sub-directory under gdata cache directory for the given sub | |
121 // directory type. Example: <user_profile_dir>/GCache/v1/tmp | |
122 FilePath GetCacheDirectoryPath(CacheSubDirectoryType sub_dir_type) const; | |
satorux1
2012/06/08 15:10:54
The class used to be a pure interface class where
| |
123 | |
124 // Returns absolute path of the file if it were cached or to be cached. | |
125 FilePath GetCacheFilePath(const std::string& resource_id, | |
126 const std::string& md5, | |
127 CacheSubDirectoryType sub_dir_type, | |
128 CachedFileOrigin file_orign) const; | |
129 | |
130 // TODO(hashimoto): Remove this method when crbug.com/131756 is fixed. | |
131 const std::vector<FilePath>& cache_paths() const { return cache_paths_; } | |
132 | |
110 // Sets |cache_map_| data member to formal parameter |new_cache_map|. | 133 // Sets |cache_map_| data member to formal parameter |new_cache_map|. |
111 virtual void SetCacheMap(const CacheMap& new_cache_map) = 0; | 134 virtual void SetCacheMap(const CacheMap& new_cache_map) = 0; |
112 | 135 |
113 // Updates cache map with entry corresponding to |resource_id|. | 136 // Updates cache map with entry corresponding to |resource_id|. |
114 // Creates new entry if it doesn't exist, otherwise update the entry. | 137 // Creates new entry if it doesn't exist, otherwise update the entry. |
115 virtual void UpdateCache(const std::string& resource_id, | 138 virtual void UpdateCache(const std::string& resource_id, |
116 const std::string& md5, | 139 const std::string& md5, |
117 CacheSubDirectoryType subdir, | 140 CacheSubDirectoryType subdir, |
118 int cache_state) = 0; | 141 int cache_state) = 0; |
119 | 142 |
120 // Removes entry corresponding to |resource_id| from cache map. | 143 // Removes entry corresponding to |resource_id| from cache map. |
121 virtual void RemoveFromCache(const std::string& resource_id) = 0; | 144 virtual void RemoveFromCache(const std::string& resource_id) = 0; |
122 | 145 |
123 // Returns the cache entry for file corresponding to |resource_id| and |md5| | 146 // Returns the cache entry for file corresponding to |resource_id| and |md5| |
124 // if entry exists in cache map. Otherwise, returns NULL. | 147 // if entry exists in cache map. Otherwise, returns NULL. |
125 // |md5| can be empty if only matching |resource_id| is desired, which may | 148 // |md5| can be empty if only matching |resource_id| is desired, which may |
126 // happen when looking for pinned entries where symlinks' filenames have no | 149 // happen when looking for pinned entries where symlinks' filenames have no |
127 // extension and hence no md5. | 150 // extension and hence no md5. |
128 virtual scoped_ptr<CacheEntry> GetCacheEntry(const std::string& resource_id, | 151 virtual scoped_ptr<CacheEntry> GetCacheEntry(const std::string& resource_id, |
129 const std::string& md5) = 0; | 152 const std::string& md5) = 0; |
130 | 153 |
131 // Removes temporary files (files in CACHE_TYPE_TMP) from the cache map. | 154 // Removes temporary files (files in CACHE_TYPE_TMP) from the cache map. |
132 virtual void RemoveTemporaryFiles() = 0; | 155 virtual void RemoveTemporaryFiles() = 0; |
133 | 156 |
134 // Factory methods for GDataCache. | 157 // Factory methods for GDataCache. |
135 static scoped_ptr<GDataCache> CreateGDataCache(); | 158 static scoped_ptr<GDataCache> CreateGDataCache( |
159 const FilePath& cache_root_path); | |
136 | 160 |
137 protected: | 161 protected: |
138 GDataCache(); | 162 explicit GDataCache(const FilePath& cache_root_path); |
139 | 163 |
140 private: | 164 private: |
165 // Paths for all subdirectories of GCache, one for each | |
166 // GDataCache::CacheSubDirectoryType enum. | |
167 std::vector<FilePath> cache_paths_; | |
168 | |
141 DISALLOW_COPY_AND_ASSIGN(GDataCache); | 169 DISALLOW_COPY_AND_ASSIGN(GDataCache); |
142 }; | 170 }; |
143 | 171 |
144 } // namespace gdata | 172 } // namespace gdata |
145 | 173 |
146 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_ | 174 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_ |
OLD | NEW |