| 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 | 10 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // Structure to store information of an existing cache file. | 121 // Structure to store information of an existing cache file. |
| 122 struct CacheEntry { | 122 struct CacheEntry { |
| 123 CacheEntry() : cache_state(CACHE_STATE_NONE) {} | 123 CacheEntry() : cache_state(CACHE_STATE_NONE) {} |
| 124 | 124 |
| 125 CacheEntry(const std::string& md5, | 125 CacheEntry(const std::string& md5, |
| 126 int cache_state) | 126 int cache_state) |
| 127 : md5(md5), | 127 : md5(md5), |
| 128 cache_state(cache_state) { | 128 cache_state(cache_state) { |
| 129 } | 129 } |
| 130 | 130 |
| 131 bool IsPresent() const { return IsCachePresent(cache_state); } | 131 // Returns true if the file is present locally. |
| 132 bool IsPinned() const { return IsCachePinned(cache_state); } | 132 bool IsPresent() const { return cache_state & CACHE_STATE_PRESENT; } |
| 133 bool IsDirty() const { return IsCacheDirty(cache_state); } | 133 |
| 134 bool IsMounted() const { return IsCacheMounted(cache_state); } | 134 // Returns true if the file is pinned (i.e. available offline). |
| 135 bool IsPersistent() const { return IsCachePersistent(cache_state); } | 135 bool IsPinned() const { return cache_state & CACHE_STATE_PINNED; } |
| 136 |
| 137 // Returns true if the file is dirty (i.e. modified locally). |
| 138 bool IsDirty() const { return cache_state & CACHE_STATE_DIRTY; } |
| 139 |
| 140 // Returns true if the file is a mounted archive file. |
| 141 bool IsMounted() const { return cache_state & CACHE_STATE_MOUNTED; } |
| 142 |
| 143 // Returns true if the file is in the persistent directory. |
| 144 bool IsPersistent() const { return cache_state & CACHE_STATE_PERSISTENT; } |
| 145 |
| 146 // Setters for the states describe above. |
| 147 void SetPresent(bool value) { |
| 148 cache_state = (value ? cache_state |= CACHE_STATE_PRESENT : |
| 149 cache_state &= ~CACHE_STATE_PRESENT); |
| 150 } |
| 151 void SetPinned(bool value) { |
| 152 cache_state = (value ? cache_state |= CACHE_STATE_PINNED : |
| 153 cache_state &= ~CACHE_STATE_PINNED); |
| 154 } |
| 155 void SetDirty(bool value) { |
| 156 cache_state = (value ? cache_state |= CACHE_STATE_DIRTY : |
| 157 cache_state &= ~CACHE_STATE_DIRTY); |
| 158 } |
| 159 void SetMounted(bool value) { |
| 160 cache_state = (value ? cache_state |= CACHE_STATE_MOUNTED : |
| 161 cache_state &= ~CACHE_STATE_MOUNTED); |
| 162 } |
| 163 void SetPersistent(bool value) { |
| 164 cache_state = (value ? cache_state |= CACHE_STATE_PERSISTENT : |
| 165 cache_state &= ~CACHE_STATE_PERSISTENT); |
| 166 } |
| 136 | 167 |
| 137 // Returns the type of the sub directory where the cache file is stored. | 168 // Returns the type of the sub directory where the cache file is stored. |
| 138 CacheSubDirectoryType GetSubDirectoryType() const { | 169 CacheSubDirectoryType GetSubDirectoryType() const { |
| 139 return IsPersistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 170 return IsPersistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
| 140 } | 171 } |
| 141 | 172 |
| 142 // For debugging purposes. | 173 // For debugging purposes. |
| 143 std::string ToString() const; | 174 std::string ToString() const; |
| 144 | 175 |
| 145 std::string md5; | 176 std::string md5; |
| 146 int cache_state; | 177 int cache_state; |
| 147 }; | 178 }; |
| 148 | 179 |
| 149 // Callback for GetCacheEntryOnUIThread. | 180 // Callback for GetCacheEntryOnUIThread. |
| 150 // |success| indicates if the operation was successful. | 181 // |success| indicates if the operation was successful. |
| 151 // |cache_entry| is the obtained cache entry. On failure, |cache_state| is | 182 // |cache_entry| is the obtained cache entry. On failure, |cache_state| is |
| 152 // set to CACHE_STATE_NONE. | 183 // set to CACHE_STATE_NONE. |
| 153 // | 184 // |
| 154 // TODO(satorux): Unlike other callback types, this has to be defined | 185 // TODO(satorux): Unlike other callback types, this has to be defined |
| 155 // inside GDataCache as CacheEntry is inside GDataCache. We should get them | 186 // inside GDataCache as CacheEntry is inside GDataCache. We should get them |
| 156 // outside of GDataCache. | 187 // outside of GDataCache. |
| 157 typedef base::Callback<void(bool success, const CacheEntry& cache_entry)> | 188 typedef base::Callback<void(bool success, const CacheEntry& cache_entry)> |
| 158 GetCacheEntryCallback; | 189 GetCacheEntryCallback; |
| 159 | 190 |
| 160 static bool IsCachePresent(int cache_state) { | |
| 161 return cache_state & CACHE_STATE_PRESENT; | |
| 162 } | |
| 163 static bool IsCachePinned(int cache_state) { | |
| 164 return cache_state & CACHE_STATE_PINNED; | |
| 165 } | |
| 166 static bool IsCacheDirty(int cache_state) { | |
| 167 return cache_state & CACHE_STATE_DIRTY; | |
| 168 } | |
| 169 static bool IsCacheMounted(int cache_state) { | |
| 170 return cache_state & CACHE_STATE_MOUNTED; | |
| 171 } | |
| 172 static bool IsCachePersistent(int cache_state) { | |
| 173 return cache_state & CACHE_STATE_PERSISTENT; | |
| 174 } | |
| 175 static int SetCachePresent(int cache_state) { | |
| 176 return cache_state |= CACHE_STATE_PRESENT; | |
| 177 } | |
| 178 static int SetCachePinned(int cache_state) { | |
| 179 return cache_state |= CACHE_STATE_PINNED; | |
| 180 } | |
| 181 static int SetCacheDirty(int cache_state) { | |
| 182 return cache_state |= CACHE_STATE_DIRTY; | |
| 183 } | |
| 184 static int SetCacheMounted(int cache_state) { | |
| 185 return cache_state |= CACHE_STATE_MOUNTED; | |
| 186 } | |
| 187 static int SetCachePersistent(int cache_state) { | |
| 188 return cache_state |= CACHE_STATE_PERSISTENT; | |
| 189 } | |
| 190 static int ClearCachePresent(int cache_state) { | |
| 191 return cache_state &= ~CACHE_STATE_PRESENT; | |
| 192 } | |
| 193 static int ClearCachePinned(int cache_state) { | |
| 194 return cache_state &= ~CACHE_STATE_PINNED; | |
| 195 } | |
| 196 static int ClearCacheDirty(int cache_state) { | |
| 197 return cache_state &= ~CACHE_STATE_DIRTY; | |
| 198 } | |
| 199 static int ClearCacheMounted(int cache_state) { | |
| 200 return cache_state &= ~CACHE_STATE_MOUNTED; | |
| 201 } | |
| 202 static int ClearCachePersistent(int cache_state) { | |
| 203 return cache_state &= ~CACHE_STATE_PERSISTENT; | |
| 204 } | |
| 205 | |
| 206 // Returns the sub-directory under gdata cache directory for the given sub | 191 // Returns the sub-directory under gdata cache directory for the given sub |
| 207 // directory type. Example: <user_profile_dir>/GCache/v1/tmp | 192 // directory type. Example: <user_profile_dir>/GCache/v1/tmp |
| 208 // | 193 // |
| 209 // Can be called on any thread. | 194 // Can be called on any thread. |
| 210 FilePath GetCacheDirectoryPath(CacheSubDirectoryType sub_dir_type) const; | 195 FilePath GetCacheDirectoryPath(CacheSubDirectoryType sub_dir_type) const; |
| 211 | 196 |
| 212 // Returns absolute path of the file if it were cached or to be cached. | 197 // Returns absolute path of the file if it were cached or to be cached. |
| 213 // | 198 // |
| 214 // Can be called on any thread. | 199 // Can be called on any thread. |
| 215 FilePath GetCacheFilePath(const std::string& resource_id, | 200 FilePath GetCacheFilePath(const std::string& resource_id, |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 }; | 510 }; |
| 526 | 511 |
| 527 // Sets the free disk space getter for testing. | 512 // Sets the free disk space getter for testing. |
| 528 // The existing getter is deleted. | 513 // The existing getter is deleted. |
| 529 void SetFreeDiskSpaceGetterForTesting( | 514 void SetFreeDiskSpaceGetterForTesting( |
| 530 FreeDiskSpaceGetterInterface* getter); | 515 FreeDiskSpaceGetterInterface* getter); |
| 531 | 516 |
| 532 } // namespace gdata | 517 } // namespace gdata |
| 533 | 518 |
| 534 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_ | 519 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_ |
| OLD | NEW |