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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 const std::string& md5) {} | 112 const std::string& md5) {} |
113 | 113 |
114 // Triggered when a dirty file has been committed (saved) successfully. | 114 // Triggered when a dirty file has been committed (saved) successfully. |
115 virtual void OnCacheCommitted(const std::string& resource_id) {} | 115 virtual void OnCacheCommitted(const std::string& resource_id) {} |
116 | 116 |
117 protected: | 117 protected: |
118 virtual ~Observer() {} | 118 virtual ~Observer() {} |
119 }; | 119 }; |
120 | 120 |
121 // Structure to store information of an existing cache file. | 121 // Structure to store information of an existing cache file. |
122 struct CacheEntry { | 122 class CacheEntry { |
123 CacheEntry() : cache_state(CACHE_STATE_NONE) {} | 123 public: |
| 124 CacheEntry() : cache_state_(CACHE_STATE_NONE) {} |
124 | 125 |
125 CacheEntry(const std::string& md5, | 126 CacheEntry(const std::string& md5, |
126 int cache_state) | 127 int cache_state) |
127 : md5(md5), | 128 : md5_(md5), |
128 cache_state(cache_state) { | 129 cache_state_(cache_state) { |
129 } | 130 } |
130 | 131 |
| 132 // The MD5 of the cache file. This can be "local" if the file is |
| 133 // locally modified. |
| 134 const std::string& md5() const { return md5_; } |
| 135 |
| 136 // The cache state represented as a bit-field of GDataCacheState. |
| 137 int cache_state() const { return cache_state_; } |
| 138 |
| 139 void set_md5(const std::string& md5) { md5_ = md5; } |
| 140 void set_cache_state(int cache_state) { cache_state_ = cache_state; } |
| 141 |
131 // Returns true if the file is present locally. | 142 // Returns true if the file is present locally. |
132 bool IsPresent() const { return cache_state & CACHE_STATE_PRESENT; } | 143 bool IsPresent() const { return cache_state_ & CACHE_STATE_PRESENT; } |
133 | 144 |
134 // Returns true if the file is pinned (i.e. available offline). | 145 // Returns true if the file is pinned (i.e. available offline). |
135 bool IsPinned() const { return cache_state & CACHE_STATE_PINNED; } | 146 bool IsPinned() const { return cache_state_ & CACHE_STATE_PINNED; } |
136 | 147 |
137 // Returns true if the file is dirty (i.e. modified locally). | 148 // Returns true if the file is dirty (i.e. modified locally). |
138 bool IsDirty() const { return cache_state & CACHE_STATE_DIRTY; } | 149 bool IsDirty() const { return cache_state_ & CACHE_STATE_DIRTY; } |
139 | 150 |
140 // Returns true if the file is a mounted archive file. | 151 // Returns true if the file is a mounted archive file. |
141 bool IsMounted() const { return cache_state & CACHE_STATE_MOUNTED; } | 152 bool IsMounted() const { return cache_state_ & CACHE_STATE_MOUNTED; } |
142 | 153 |
143 // Returns true if the file is in the persistent directory. | 154 // Returns true if the file is in the persistent directory. |
144 bool IsPersistent() const { return cache_state & CACHE_STATE_PERSISTENT; } | 155 bool IsPersistent() const { return cache_state_ & CACHE_STATE_PERSISTENT; } |
145 | 156 |
146 // Setters for the states describe above. | 157 // Setters for the states describe above. |
147 void SetPresent(bool value) { | 158 void SetPresent(bool value) { |
148 if (value) | 159 if (value) |
149 cache_state |= CACHE_STATE_PRESENT; | 160 cache_state_ |= CACHE_STATE_PRESENT; |
150 else | 161 else |
151 cache_state &= ~CACHE_STATE_PRESENT; | 162 cache_state_ &= ~CACHE_STATE_PRESENT; |
152 } | 163 } |
153 void SetPinned(bool value) { | 164 void SetPinned(bool value) { |
154 if (value) | 165 if (value) |
155 cache_state |= CACHE_STATE_PINNED; | 166 cache_state_ |= CACHE_STATE_PINNED; |
156 else | 167 else |
157 cache_state &= ~CACHE_STATE_PINNED; | 168 cache_state_ &= ~CACHE_STATE_PINNED; |
158 } | 169 } |
159 void SetDirty(bool value) { | 170 void SetDirty(bool value) { |
160 if (value) | 171 if (value) |
161 cache_state |= CACHE_STATE_DIRTY; | 172 cache_state_ |= CACHE_STATE_DIRTY; |
162 else | 173 else |
163 cache_state &= ~CACHE_STATE_DIRTY; | 174 cache_state_ &= ~CACHE_STATE_DIRTY; |
164 } | 175 } |
165 void SetMounted(bool value) { | 176 void SetMounted(bool value) { |
166 if (value) | 177 if (value) |
167 cache_state |= CACHE_STATE_MOUNTED; | 178 cache_state_ |= CACHE_STATE_MOUNTED; |
168 else | 179 else |
169 cache_state &= ~CACHE_STATE_MOUNTED; | 180 cache_state_ &= ~CACHE_STATE_MOUNTED; |
170 } | 181 } |
171 void SetPersistent(bool value) { | 182 void SetPersistent(bool value) { |
172 if (value) | 183 if (value) |
173 cache_state |= CACHE_STATE_PERSISTENT; | 184 cache_state_ |= CACHE_STATE_PERSISTENT; |
174 else | 185 else |
175 cache_state &= ~CACHE_STATE_PERSISTENT; | 186 cache_state_ &= ~CACHE_STATE_PERSISTENT; |
176 } | 187 } |
177 | 188 |
178 // Returns the type of the sub directory where the cache file is stored. | 189 // Returns the type of the sub directory where the cache file is stored. |
179 CacheSubDirectoryType GetSubDirectoryType() const { | 190 CacheSubDirectoryType GetSubDirectoryType() const { |
180 return IsPersistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 191 return IsPersistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
181 } | 192 } |
182 | 193 |
183 // For debugging purposes. | 194 // For debugging purposes. |
184 std::string ToString() const; | 195 std::string ToString() const; |
185 | 196 |
186 std::string md5; | 197 private: |
187 int cache_state; | 198 std::string md5_; |
| 199 int cache_state_; |
188 }; | 200 }; |
189 | 201 |
190 // Callback for GetCacheEntryOnUIThread. | 202 // Callback for GetCacheEntryOnUIThread. |
191 // |success| indicates if the operation was successful. | 203 // |success| indicates if the operation was successful. |
192 // |cache_entry| is the obtained cache entry. On failure, |cache_state| is | 204 // |cache_entry| is the obtained cache entry. On failure, |cache_state| is |
193 // set to CACHE_STATE_NONE. | 205 // set to CACHE_STATE_NONE. |
194 // | 206 // |
195 // TODO(satorux): Unlike other callback types, this has to be defined | 207 // TODO(satorux): Unlike other callback types, this has to be defined |
196 // inside GDataCache as CacheEntry is inside GDataCache. We should get them | 208 // inside GDataCache as CacheEntry is inside GDataCache. We should get them |
197 // outside of GDataCache. | 209 // outside of GDataCache. |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 }; | 525 }; |
514 | 526 |
515 // Sets the free disk space getter for testing. | 527 // Sets the free disk space getter for testing. |
516 // The existing getter is deleted. | 528 // The existing getter is deleted. |
517 void SetFreeDiskSpaceGetterForTesting( | 529 void SetFreeDiskSpaceGetterForTesting( |
518 FreeDiskSpaceGetterInterface* getter); | 530 FreeDiskSpaceGetterInterface* getter); |
519 | 531 |
520 } // namespace gdata | 532 } // namespace gdata |
521 | 533 |
522 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_ | 534 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CACHE_H_ |
OLD | NEW |