OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 WEBKIT_APPCACHE_APPCACHE_STORAGE_H_ | 5 #ifndef WEBKIT_APPCACHE_APPCACHE_STORAGE_H_ |
6 #define WEBKIT_APPCACHE_APPCACHE_STORAGE_H_ | 6 #define WEBKIT_APPCACHE_APPCACHE_STORAGE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 class AppCacheEntry; | 24 class AppCacheEntry; |
25 class AppCacheGroup; | 25 class AppCacheGroup; |
26 class AppCacheResponseReader; | 26 class AppCacheResponseReader; |
27 class AppCacheResponseWriter; | 27 class AppCacheResponseWriter; |
28 class AppCacheService; | 28 class AppCacheService; |
29 struct AppCacheInfoCollection; | 29 struct AppCacheInfoCollection; |
30 struct HttpResponseInfoIOBuffer; | 30 struct HttpResponseInfoIOBuffer; |
31 | 31 |
32 class AppCacheStorage { | 32 class AppCacheStorage { |
33 public: | 33 public: |
| 34 typedef std::map<GURL, int64> UsageMap; |
34 | 35 |
35 class Delegate { | 36 class Delegate { |
36 public: | 37 public: |
37 virtual ~Delegate() {} | 38 virtual ~Delegate() {} |
38 | 39 |
39 // If retrieval fails, 'collection' will be NULL. | 40 // If retrieval fails, 'collection' will be NULL. |
40 virtual void OnAllInfo(AppCacheInfoCollection* collection) {} | 41 virtual void OnAllInfo(AppCacheInfoCollection* collection) {} |
41 | 42 |
42 // If a load fails the 'cache' will be NULL. | 43 // If a load fails the 'cache' will be NULL. |
43 virtual void OnCacheLoaded(AppCache* cache, int64 cache_id) {} | 44 virtual void OnCacheLoaded(AppCache* cache, int64 cache_id) {} |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 int64 NewCacheId() { | 174 int64 NewCacheId() { |
174 return ++last_cache_id_; | 175 return ++last_cache_id_; |
175 } | 176 } |
176 int64 NewGroupId() { | 177 int64 NewGroupId() { |
177 return ++last_group_id_; | 178 return ++last_group_id_; |
178 } | 179 } |
179 | 180 |
180 // The working set of object instances currently in memory. | 181 // The working set of object instances currently in memory. |
181 AppCacheWorkingSet* working_set() { return &working_set_; } | 182 AppCacheWorkingSet* working_set() { return &working_set_; } |
182 | 183 |
| 184 // A map of origins to usage. |
| 185 const UsageMap* usage_map() { return &usage_map_; } |
| 186 |
183 // Simple ptr back to the service object that owns us. | 187 // Simple ptr back to the service object that owns us. |
184 AppCacheService* service() { return service_; } | 188 AppCacheService* service() { return service_; } |
185 | 189 |
186 protected: | 190 protected: |
| 191 friend class AppCacheQuotaClientTest; |
187 friend class AppCacheResponseTest; | 192 friend class AppCacheResponseTest; |
188 friend class AppCacheStorageTest; | 193 friend class AppCacheStorageTest; |
189 | 194 |
190 // Helper to call a collection of delegates. | 195 // Helper to call a collection of delegates. |
191 #define FOR_EACH_DELEGATE(delegates, func_and_args) \ | 196 #define FOR_EACH_DELEGATE(delegates, func_and_args) \ |
192 do { \ | 197 do { \ |
193 for (DelegateReferenceVector::iterator it = delegates.begin(); \ | 198 for (DelegateReferenceVector::iterator it = delegates.begin(); \ |
194 it != delegates.end(); ++it) { \ | 199 it != delegates.end(); ++it) { \ |
195 if (it->get()->delegate) \ | 200 if (it->get()->delegate) \ |
196 it->get()->delegate->func_and_args; \ | 201 it->get()->delegate->func_and_args; \ |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 if (iter != pending_info_loads_.end()) | 278 if (iter != pending_info_loads_.end()) |
274 return iter->second; | 279 return iter->second; |
275 return new ResponseInfoLoadTask(manifest_url, response_id, this); | 280 return new ResponseInfoLoadTask(manifest_url, response_id, this); |
276 } | 281 } |
277 | 282 |
278 // Should only be called when creating a new response writer. | 283 // Should only be called when creating a new response writer. |
279 int64 NewResponseId() { | 284 int64 NewResponseId() { |
280 return ++last_response_id_; | 285 return ++last_response_id_; |
281 } | 286 } |
282 | 287 |
| 288 // Helpers to query and notify the QuotaManager. |
| 289 void UpdateUsageMapAndNotify(const GURL& origin, int64 new_usage); |
| 290 void ClearUsageMapAndNotify(); |
| 291 void NotifyStorageAccessed(const GURL& origin); |
| 292 |
283 // The last storage id used for different object types. | 293 // The last storage id used for different object types. |
284 int64 last_cache_id_; | 294 int64 last_cache_id_; |
285 int64 last_group_id_; | 295 int64 last_group_id_; |
286 int64 last_response_id_; | 296 int64 last_response_id_; |
287 | 297 |
| 298 UsageMap usage_map_; // maps origin to usage |
288 AppCacheWorkingSet working_set_; | 299 AppCacheWorkingSet working_set_; |
289 AppCacheService* service_; | 300 AppCacheService* service_; |
290 DelegateReferenceMap delegate_references_; | 301 DelegateReferenceMap delegate_references_; |
291 PendingResponseInfoLoads pending_info_loads_; | 302 PendingResponseInfoLoads pending_info_loads_; |
292 | 303 |
293 // The set of last ids must be retrieved from storage prior to being used. | 304 // The set of last ids must be retrieved from storage prior to being used. |
294 static const int64 kUnitializedId; | 305 static const int64 kUnitializedId; |
295 | 306 |
296 FRIEND_TEST_ALL_PREFIXES(AppCacheStorageTest, DelegateReferences); | 307 FRIEND_TEST_ALL_PREFIXES(AppCacheStorageTest, DelegateReferences); |
| 308 FRIEND_TEST_ALL_PREFIXES(AppCacheStorageTest, UsageMap); |
297 | 309 |
298 DISALLOW_COPY_AND_ASSIGN(AppCacheStorage); | 310 DISALLOW_COPY_AND_ASSIGN(AppCacheStorage); |
299 }; | 311 }; |
300 | 312 |
301 } // namespace appcache | 313 } // namespace appcache |
302 | 314 |
303 #endif // WEBKIT_APPCACHE_APPCACHE_STORAGE_H_ | 315 #endif // WEBKIT_APPCACHE_APPCACHE_STORAGE_H_ |
304 | 316 |
OLD | NEW |