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 CONTENT_BROWSER_APPCACHE_APPCACHE_STORAGE_H_ | 5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_STORAGE_H_ |
6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_STORAGE_H_ | 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_STORAGE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 void OnReadComplete(int result); | 268 void OnReadComplete(int result); |
269 | 269 |
270 AppCacheStorage* storage_; | 270 AppCacheStorage* storage_; |
271 GURL manifest_url_; | 271 GURL manifest_url_; |
272 int64_t response_id_; | 272 int64_t response_id_; |
273 std::unique_ptr<AppCacheResponseReader> reader_; | 273 std::unique_ptr<AppCacheResponseReader> reader_; |
274 DelegateReferenceVector delegates_; | 274 DelegateReferenceVector delegates_; |
275 scoped_refptr<HttpResponseInfoIOBuffer> info_buffer_; | 275 scoped_refptr<HttpResponseInfoIOBuffer> info_buffer_; |
276 }; | 276 }; |
277 | 277 |
278 typedef std::map<int64_t, ResponseInfoLoadTask*> PendingResponseInfoLoads; | |
279 | |
280 DelegateReference* GetDelegateReference(Delegate* delegate) { | 278 DelegateReference* GetDelegateReference(Delegate* delegate) { |
281 DelegateReferenceMap::iterator iter = | 279 DelegateReferenceMap::iterator iter = |
282 delegate_references_.find(delegate); | 280 delegate_references_.find(delegate); |
283 if (iter != delegate_references_.end()) | 281 if (iter != delegate_references_.end()) |
284 return iter->second; | 282 return iter->second; |
285 return NULL; | 283 return NULL; |
286 } | 284 } |
287 | 285 |
288 DelegateReference* GetOrCreateDelegateReference(Delegate* delegate) { | 286 DelegateReference* GetOrCreateDelegateReference(Delegate* delegate) { |
289 DelegateReference* reference = GetDelegateReference(delegate); | 287 DelegateReference* reference = GetDelegateReference(delegate); |
290 if (reference) | 288 if (reference) |
291 return reference; | 289 return reference; |
292 return new DelegateReference(delegate, this); | 290 return new DelegateReference(delegate, this); |
293 } | 291 } |
294 | 292 |
295 ResponseInfoLoadTask* GetOrCreateResponseInfoLoadTask( | 293 ResponseInfoLoadTask* GetOrCreateResponseInfoLoadTask( |
296 const GURL& manifest_url, | 294 const GURL& manifest_url, |
297 int64_t response_id) { | 295 int64_t response_id) { |
298 PendingResponseInfoLoads::iterator iter = | 296 auto iter = pending_info_loads_.find(response_id); |
299 pending_info_loads_.find(response_id); | |
300 if (iter != pending_info_loads_.end()) | 297 if (iter != pending_info_loads_.end()) |
301 return iter->second; | 298 return iter->second.get(); |
302 return new ResponseInfoLoadTask(manifest_url, response_id, this); | 299 return new ResponseInfoLoadTask(manifest_url, response_id, this); |
303 } | 300 } |
304 | 301 |
305 // Should only be called when creating a new response writer. | 302 // Should only be called when creating a new response writer. |
306 int64_t NewResponseId() { return ++last_response_id_; } | 303 int64_t NewResponseId() { return ++last_response_id_; } |
307 | 304 |
308 // Helpers to query and notify the QuotaManager. | 305 // Helpers to query and notify the QuotaManager. |
309 void UpdateUsageMapAndNotify(const GURL& origin, int64_t new_usage); | 306 void UpdateUsageMapAndNotify(const GURL& origin, int64_t new_usage); |
310 void ClearUsageMapAndNotify(); | 307 void ClearUsageMapAndNotify(); |
311 void NotifyStorageAccessed(const GURL& origin); | 308 void NotifyStorageAccessed(const GURL& origin); |
312 | 309 |
313 // The last storage id used for different object types. | 310 // The last storage id used for different object types. |
314 int64_t last_cache_id_; | 311 int64_t last_cache_id_; |
315 int64_t last_group_id_; | 312 int64_t last_group_id_; |
316 int64_t last_response_id_; | 313 int64_t last_response_id_; |
317 | 314 |
318 UsageMap usage_map_; // maps origin to usage | 315 UsageMap usage_map_; // maps origin to usage |
319 AppCacheWorkingSet working_set_; | 316 AppCacheWorkingSet working_set_; |
320 AppCacheServiceImpl* service_; | 317 AppCacheServiceImpl* service_; |
321 DelegateReferenceMap delegate_references_; | 318 DelegateReferenceMap delegate_references_; |
322 PendingResponseInfoLoads pending_info_loads_; | 319 |
| 320 // Note that the ResponseInfoLoadTask items add themselves to this map. |
| 321 std::map<int64_t, std::unique_ptr<ResponseInfoLoadTask>> pending_info_loads_; |
323 | 322 |
324 // The set of last ids must be retrieved from storage prior to being used. | 323 // The set of last ids must be retrieved from storage prior to being used. |
325 static const int64_t kUnitializedId; | 324 static const int64_t kUnitializedId; |
326 | 325 |
327 FRIEND_TEST_ALL_PREFIXES(content::AppCacheStorageTest, DelegateReferences); | 326 FRIEND_TEST_ALL_PREFIXES(content::AppCacheStorageTest, DelegateReferences); |
328 FRIEND_TEST_ALL_PREFIXES(content::AppCacheStorageTest, UsageMap); | 327 FRIEND_TEST_ALL_PREFIXES(content::AppCacheStorageTest, UsageMap); |
329 | 328 |
330 DISALLOW_COPY_AND_ASSIGN(AppCacheStorage); | 329 DISALLOW_COPY_AND_ASSIGN(AppCacheStorage); |
331 }; | 330 }; |
332 | 331 |
333 } // namespace content | 332 } // namespace content |
334 | 333 |
335 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_STORAGE_H_ | 334 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_STORAGE_H_ |
OLD | NEW |