| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // If a load fails the 'response_info' will be NULL. | 59 // If a load fails the 'response_info' will be NULL. |
| 60 virtual void OnResponseInfoLoaded( | 60 virtual void OnResponseInfoLoaded( |
| 61 AppCacheResponseInfo* response_info, int64 response_id) {} | 61 AppCacheResponseInfo* response_info, int64 response_id) {} |
| 62 | 62 |
| 63 // If no response is found, entry.response_id() will be kNoResponseId. | 63 // If no response is found, entry.response_id() will be kNoResponseId. |
| 64 // If a response is found, the cache id and manifest url of the | 64 // If a response is found, the cache id and manifest url of the |
| 65 // containing cache and group are also returned. | 65 // containing cache and group are also returned. |
| 66 virtual void OnMainResponseFound( | 66 virtual void OnMainResponseFound( |
| 67 const GURL& url, const AppCacheEntry& entry, | 67 const GURL& url, const AppCacheEntry& entry, |
| 68 const GURL& fallback_url, const AppCacheEntry& fallback_entry, | 68 const GURL& fallback_url, const AppCacheEntry& fallback_entry, |
| 69 int64 cache_id, const GURL& mainfest_url) {} | 69 int64 cache_id, int64 group_id, const GURL& mainfest_url) {} |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 explicit AppCacheStorage(AppCacheService* service); | 72 explicit AppCacheStorage(AppCacheService* service); |
| 73 virtual ~AppCacheStorage(); | 73 virtual ~AppCacheStorage(); |
| 74 | 74 |
| 75 // Schedules a task to retrieve basic info about all groups and caches | 75 // Schedules a task to retrieve basic info about all groups and caches |
| 76 // stored in the system. Upon completion the delegate will be called | 76 // stored in the system. Upon completion the delegate will be called |
| 77 // with the results. | 77 // with the results. |
| 78 virtual void GetAllInfo(Delegate* delegate) = 0; | 78 virtual void GetAllInfo(Delegate* delegate) = 0; |
| 79 | 79 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 91 // the delegate will be called back with a NULL group pointer. | 91 // the delegate will be called back with a NULL group pointer. |
| 92 virtual void LoadOrCreateGroup( | 92 virtual void LoadOrCreateGroup( |
| 93 const GURL& manifest_url, Delegate* delegate) = 0; | 93 const GURL& manifest_url, Delegate* delegate) = 0; |
| 94 | 94 |
| 95 // Schedules response info to be loaded from storage. | 95 // Schedules response info to be loaded from storage. |
| 96 // Upon load completion the delegate will be called back. If the data | 96 // Upon load completion the delegate will be called back. If the data |
| 97 // already resides in memory, the delegate will be called back | 97 // already resides in memory, the delegate will be called back |
| 98 // immediately without returning to the message loop. If the load fails, | 98 // immediately without returning to the message loop. If the load fails, |
| 99 // the delegate will be called back with a NULL pointer. | 99 // the delegate will be called back with a NULL pointer. |
| 100 virtual void LoadResponseInfo( | 100 virtual void LoadResponseInfo( |
| 101 const GURL& manifest_url, int64 response_id, Delegate* delegate); | 101 const GURL& manifest_url, int64 group_id, int64 response_id, |
| 102 Delegate* delegate); |
| 102 | 103 |
| 103 // Schedules a group and its newest complete cache to be initially stored or | 104 // Schedules a group and its newest complete cache to be initially stored or |
| 104 // incrementally updated with new changes. Upon completion the delegate | 105 // incrementally updated with new changes. Upon completion the delegate |
| 105 // will be called back. A group without a newest cache cannot be stored. | 106 // will be called back. A group without a newest cache cannot be stored. |
| 106 // It's a programming error to call this method without a newest cache. A | 107 // It's a programming error to call this method without a newest cache. A |
| 107 // side effect of storing a new newest cache is the removal of the group's | 108 // side effect of storing a new newest cache is the removal of the group's |
| 108 // old caches and responses from persistent storage (although they may still | 109 // old caches and responses from persistent storage (although they may still |
| 109 // linger in the in-memory working set until no longer needed). The new | 110 // linger in the in-memory working set until no longer needed). The new |
| 110 // cache will be added as the group's newest complete cache only if storage | 111 // cache will be added as the group's newest complete cache only if storage |
| 111 // succeeds. | 112 // succeeds. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // take place. The callbacks for subsequently scheduled operations are | 144 // take place. The callbacks for subsequently scheduled operations are |
| 144 // unaffected. | 145 // unaffected. |
| 145 void CancelDelegateCallbacks(Delegate* delegate) { | 146 void CancelDelegateCallbacks(Delegate* delegate) { |
| 146 DelegateReference* delegate_reference = GetDelegateReference(delegate); | 147 DelegateReference* delegate_reference = GetDelegateReference(delegate); |
| 147 if (delegate_reference) | 148 if (delegate_reference) |
| 148 delegate_reference->CancelReference(); | 149 delegate_reference->CancelReference(); |
| 149 } | 150 } |
| 150 | 151 |
| 151 // Creates a reader to read a response from storage. | 152 // Creates a reader to read a response from storage. |
| 152 virtual AppCacheResponseReader* CreateResponseReader( | 153 virtual AppCacheResponseReader* CreateResponseReader( |
| 153 const GURL& manifest_url, int64 response_id) = 0; | 154 const GURL& manifest_url, int64 group_id, int64 response_id) = 0; |
| 154 | 155 |
| 155 // Creates a writer to write a new response to storage. This call | 156 // Creates a writer to write a new response to storage. This call |
| 156 // establishes a new response id. | 157 // establishes a new response id. |
| 157 virtual AppCacheResponseWriter* CreateResponseWriter( | 158 virtual AppCacheResponseWriter* CreateResponseWriter( |
| 158 const GURL& manifest_url) = 0; | 159 const GURL& manifest_url, int64 group_id) = 0; |
| 159 | 160 |
| 160 // Schedules the lazy deletion of responses and saves the ids | 161 // Schedules the lazy deletion of responses and saves the ids |
| 161 // persistently such that the responses will be deleted upon restart | 162 // persistently such that the responses will be deleted upon restart |
| 162 // if they aren't deleted prior to shutdown. | 163 // if they aren't deleted prior to shutdown. |
| 163 virtual void DoomResponses( | 164 virtual void DoomResponses( |
| 164 const GURL& manifest_url, const std::vector<int64>& response_ids) = 0; | 165 const GURL& manifest_url, const std::vector<int64>& response_ids) = 0; |
| 165 | 166 |
| 166 // Schedules the lazy deletion of responses without persistently saving | 167 // Schedules the lazy deletion of responses without persistently saving |
| 167 // the response ids. | 168 // the response ids. |
| 168 virtual void DeleteResponses( | 169 virtual void DeleteResponses( |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 virtual ~DelegateReference(); | 223 virtual ~DelegateReference(); |
| 223 }; | 224 }; |
| 224 typedef std::map<Delegate*, DelegateReference*> DelegateReferenceMap; | 225 typedef std::map<Delegate*, DelegateReference*> DelegateReferenceMap; |
| 225 typedef std::vector<scoped_refptr<DelegateReference> > | 226 typedef std::vector<scoped_refptr<DelegateReference> > |
| 226 DelegateReferenceVector; | 227 DelegateReferenceVector; |
| 227 | 228 |
| 228 // Helper used to manage an async LoadResponseInfo calls on behalf of | 229 // Helper used to manage an async LoadResponseInfo calls on behalf of |
| 229 // multiple callers. | 230 // multiple callers. |
| 230 class ResponseInfoLoadTask { | 231 class ResponseInfoLoadTask { |
| 231 public: | 232 public: |
| 232 ResponseInfoLoadTask(const GURL& manifest_url, int64 response_id, | 233 ResponseInfoLoadTask(const GURL& manifest_url, int64 group_id, |
| 233 AppCacheStorage* storage); | 234 int64 response_id, AppCacheStorage* storage); |
| 234 ~ResponseInfoLoadTask(); | 235 ~ResponseInfoLoadTask(); |
| 235 | 236 |
| 236 int64 response_id() const { return response_id_; } | 237 int64 response_id() const { return response_id_; } |
| 237 const GURL& manifest_url() const { return manifest_url_; } | 238 const GURL& manifest_url() const { return manifest_url_; } |
| 239 int64 group_id() const { return group_id_; } |
| 238 | 240 |
| 239 void AddDelegate(DelegateReference* delegate_reference) { | 241 void AddDelegate(DelegateReference* delegate_reference) { |
| 240 delegates_.push_back(delegate_reference); | 242 delegates_.push_back(delegate_reference); |
| 241 } | 243 } |
| 242 | 244 |
| 243 void StartIfNeeded(); | 245 void StartIfNeeded(); |
| 244 | 246 |
| 245 private: | 247 private: |
| 246 void OnReadComplete(int result); | 248 void OnReadComplete(int result); |
| 247 | 249 |
| 248 AppCacheStorage* storage_; | 250 AppCacheStorage* storage_; |
| 249 GURL manifest_url_; | 251 GURL manifest_url_; |
| 252 int64 group_id_; |
| 250 int64 response_id_; | 253 int64 response_id_; |
| 251 scoped_ptr<AppCacheResponseReader> reader_; | 254 scoped_ptr<AppCacheResponseReader> reader_; |
| 252 DelegateReferenceVector delegates_; | 255 DelegateReferenceVector delegates_; |
| 253 scoped_refptr<HttpResponseInfoIOBuffer> info_buffer_; | 256 scoped_refptr<HttpResponseInfoIOBuffer> info_buffer_; |
| 254 net::OldCompletionCallbackImpl<ResponseInfoLoadTask> read_callback_; | 257 net::OldCompletionCallbackImpl<ResponseInfoLoadTask> read_callback_; |
| 255 }; | 258 }; |
| 256 | 259 |
| 257 typedef std::map<int64, ResponseInfoLoadTask*> PendingResponseInfoLoads; | 260 typedef std::map<int64, ResponseInfoLoadTask*> PendingResponseInfoLoads; |
| 258 | 261 |
| 259 DelegateReference* GetDelegateReference(Delegate* delegate) { | 262 DelegateReference* GetDelegateReference(Delegate* delegate) { |
| 260 DelegateReferenceMap::iterator iter = | 263 DelegateReferenceMap::iterator iter = |
| 261 delegate_references_.find(delegate); | 264 delegate_references_.find(delegate); |
| 262 if (iter != delegate_references_.end()) | 265 if (iter != delegate_references_.end()) |
| 263 return iter->second; | 266 return iter->second; |
| 264 return NULL; | 267 return NULL; |
| 265 } | 268 } |
| 266 | 269 |
| 267 DelegateReference* GetOrCreateDelegateReference(Delegate* delegate) { | 270 DelegateReference* GetOrCreateDelegateReference(Delegate* delegate) { |
| 268 DelegateReference* reference = GetDelegateReference(delegate); | 271 DelegateReference* reference = GetDelegateReference(delegate); |
| 269 if (reference) | 272 if (reference) |
| 270 return reference; | 273 return reference; |
| 271 return new DelegateReference(delegate, this); | 274 return new DelegateReference(delegate, this); |
| 272 } | 275 } |
| 273 | 276 |
| 274 ResponseInfoLoadTask* GetOrCreateResponseInfoLoadTask( | 277 ResponseInfoLoadTask* GetOrCreateResponseInfoLoadTask( |
| 275 const GURL& manifest_url, int64 response_id) { | 278 const GURL& manifest_url, int64 group_id, int64 response_id) { |
| 276 PendingResponseInfoLoads::iterator iter = | 279 PendingResponseInfoLoads::iterator iter = |
| 277 pending_info_loads_.find(response_id); | 280 pending_info_loads_.find(response_id); |
| 278 if (iter != pending_info_loads_.end()) | 281 if (iter != pending_info_loads_.end()) |
| 279 return iter->second; | 282 return iter->second; |
| 280 return new ResponseInfoLoadTask(manifest_url, response_id, this); | 283 return new ResponseInfoLoadTask(manifest_url, group_id, response_id, this); |
| 281 } | 284 } |
| 282 | 285 |
| 283 // Should only be called when creating a new response writer. | 286 // Should only be called when creating a new response writer. |
| 284 int64 NewResponseId() { | 287 int64 NewResponseId() { |
| 285 return ++last_response_id_; | 288 return ++last_response_id_; |
| 286 } | 289 } |
| 287 | 290 |
| 288 // Helpers to query and notify the QuotaManager. | 291 // Helpers to query and notify the QuotaManager. |
| 289 void UpdateUsageMapAndNotify(const GURL& origin, int64 new_usage); | 292 void UpdateUsageMapAndNotify(const GURL& origin, int64 new_usage); |
| 290 void ClearUsageMapAndNotify(); | 293 void ClearUsageMapAndNotify(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 307 FRIEND_TEST_ALL_PREFIXES(AppCacheStorageTest, DelegateReferences); | 310 FRIEND_TEST_ALL_PREFIXES(AppCacheStorageTest, DelegateReferences); |
| 308 FRIEND_TEST_ALL_PREFIXES(AppCacheStorageTest, UsageMap); | 311 FRIEND_TEST_ALL_PREFIXES(AppCacheStorageTest, UsageMap); |
| 309 | 312 |
| 310 DISALLOW_COPY_AND_ASSIGN(AppCacheStorage); | 313 DISALLOW_COPY_AND_ASSIGN(AppCacheStorage); |
| 311 }; | 314 }; |
| 312 | 315 |
| 313 } // namespace appcache | 316 } // namespace appcache |
| 314 | 317 |
| 315 #endif // WEBKIT_APPCACHE_APPCACHE_STORAGE_H_ | 318 #endif // WEBKIT_APPCACHE_APPCACHE_STORAGE_H_ |
| 316 | 319 |
| OLD | NEW |