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