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