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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // take place. The callbacks for subsequently scheduled operations are | 166 // take place. The callbacks for subsequently scheduled operations are |
167 // unaffected. | 167 // unaffected. |
168 void CancelDelegateCallbacks(Delegate* delegate) { | 168 void CancelDelegateCallbacks(Delegate* delegate) { |
169 DelegateReference* delegate_reference = GetDelegateReference(delegate); | 169 DelegateReference* delegate_reference = GetDelegateReference(delegate); |
170 if (delegate_reference) | 170 if (delegate_reference) |
171 delegate_reference->CancelReference(); | 171 delegate_reference->CancelReference(); |
172 } | 172 } |
173 | 173 |
174 // Creates a reader to read a response from storage. | 174 // Creates a reader to read a response from storage. |
175 virtual AppCacheResponseReader* CreateResponseReader(const GURL& manifest_url, | 175 virtual AppCacheResponseReader* CreateResponseReader(const GURL& manifest_url, |
176 int64_t group_id, | |
177 int64_t response_id) = 0; | 176 int64_t response_id) = 0; |
178 | 177 |
179 // Creates a writer to write a new response to storage. This call | 178 // Creates a writer to write a new response to storage. This call |
180 // establishes a new response id. | 179 // establishes a new response id. |
181 virtual AppCacheResponseWriter* CreateResponseWriter(const GURL& manifest_url, | 180 virtual AppCacheResponseWriter* CreateResponseWriter( |
182 int64_t group_id) = 0; | 181 const GURL& manifest_url) = 0; |
183 | 182 |
184 // Creates a metadata writer to write metadata of response to storage. | 183 // Creates a metadata writer to write metadata of response to storage. |
185 virtual AppCacheResponseMetadataWriter* CreateResponseMetadataWriter( | 184 virtual AppCacheResponseMetadataWriter* CreateResponseMetadataWriter( |
186 int64_t group_id, | |
187 int64_t response_id) = 0; | 185 int64_t response_id) = 0; |
188 | 186 |
189 // Schedules the lazy deletion of responses and saves the ids | 187 // Schedules the lazy deletion of responses and saves the ids |
190 // persistently such that the responses will be deleted upon restart | 188 // persistently such that the responses will be deleted upon restart |
191 // if they aren't deleted prior to shutdown. | 189 // if they aren't deleted prior to shutdown. |
192 virtual void DoomResponses(const GURL& manifest_url, | 190 virtual void DoomResponses(const GURL& manifest_url, |
193 const std::vector<int64_t>& response_ids) = 0; | 191 const std::vector<int64_t>& response_ids) = 0; |
194 | 192 |
195 // Schedules the lazy deletion of responses without persistently saving | 193 // Schedules the lazy deletion of responses without persistently saving |
196 // the response ids. | 194 // the response ids. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 }; | 245 }; |
248 typedef std::map<Delegate*, DelegateReference*> DelegateReferenceMap; | 246 typedef std::map<Delegate*, DelegateReference*> DelegateReferenceMap; |
249 typedef std::vector<scoped_refptr<DelegateReference> > | 247 typedef std::vector<scoped_refptr<DelegateReference> > |
250 DelegateReferenceVector; | 248 DelegateReferenceVector; |
251 | 249 |
252 // Helper used to manage an async LoadResponseInfo calls on behalf of | 250 // Helper used to manage an async LoadResponseInfo calls on behalf of |
253 // multiple callers. | 251 // multiple callers. |
254 class ResponseInfoLoadTask { | 252 class ResponseInfoLoadTask { |
255 public: | 253 public: |
256 ResponseInfoLoadTask(const GURL& manifest_url, | 254 ResponseInfoLoadTask(const GURL& manifest_url, |
257 int64_t group_id, | |
258 int64_t response_id, | 255 int64_t response_id, |
259 AppCacheStorage* storage); | 256 AppCacheStorage* storage); |
260 ~ResponseInfoLoadTask(); | 257 ~ResponseInfoLoadTask(); |
261 | 258 |
262 int64_t response_id() const { return response_id_; } | 259 int64_t response_id() const { return response_id_; } |
263 const GURL& manifest_url() const { return manifest_url_; } | 260 const GURL& manifest_url() const { return manifest_url_; } |
264 int64_t group_id() const { return group_id_; } | |
265 | 261 |
266 void AddDelegate(DelegateReference* delegate_reference) { | 262 void AddDelegate(DelegateReference* delegate_reference) { |
267 delegates_.push_back(delegate_reference); | 263 delegates_.push_back(delegate_reference); |
268 } | 264 } |
269 | 265 |
270 void StartIfNeeded(); | 266 void StartIfNeeded(); |
271 | 267 |
272 private: | 268 private: |
273 void OnReadComplete(int result); | 269 void OnReadComplete(int result); |
274 | 270 |
275 AppCacheStorage* storage_; | 271 AppCacheStorage* storage_; |
276 GURL manifest_url_; | 272 GURL manifest_url_; |
277 int64_t group_id_; | |
278 int64_t response_id_; | 273 int64_t response_id_; |
279 std::unique_ptr<AppCacheResponseReader> reader_; | 274 std::unique_ptr<AppCacheResponseReader> reader_; |
280 DelegateReferenceVector delegates_; | 275 DelegateReferenceVector delegates_; |
281 scoped_refptr<HttpResponseInfoIOBuffer> info_buffer_; | 276 scoped_refptr<HttpResponseInfoIOBuffer> info_buffer_; |
282 }; | 277 }; |
283 | 278 |
284 typedef std::map<int64_t, ResponseInfoLoadTask*> PendingResponseInfoLoads; | 279 typedef std::map<int64_t, ResponseInfoLoadTask*> PendingResponseInfoLoads; |
285 | 280 |
286 DelegateReference* GetDelegateReference(Delegate* delegate) { | 281 DelegateReference* GetDelegateReference(Delegate* delegate) { |
287 DelegateReferenceMap::iterator iter = | 282 DelegateReferenceMap::iterator iter = |
288 delegate_references_.find(delegate); | 283 delegate_references_.find(delegate); |
289 if (iter != delegate_references_.end()) | 284 if (iter != delegate_references_.end()) |
290 return iter->second; | 285 return iter->second; |
291 return NULL; | 286 return NULL; |
292 } | 287 } |
293 | 288 |
294 DelegateReference* GetOrCreateDelegateReference(Delegate* delegate) { | 289 DelegateReference* GetOrCreateDelegateReference(Delegate* delegate) { |
295 DelegateReference* reference = GetDelegateReference(delegate); | 290 DelegateReference* reference = GetDelegateReference(delegate); |
296 if (reference) | 291 if (reference) |
297 return reference; | 292 return reference; |
298 return new DelegateReference(delegate, this); | 293 return new DelegateReference(delegate, this); |
299 } | 294 } |
300 | 295 |
301 ResponseInfoLoadTask* GetOrCreateResponseInfoLoadTask( | 296 ResponseInfoLoadTask* GetOrCreateResponseInfoLoadTask( |
302 const GURL& manifest_url, | 297 const GURL& manifest_url, |
303 int64_t group_id, | |
304 int64_t response_id) { | 298 int64_t response_id) { |
305 PendingResponseInfoLoads::iterator iter = | 299 PendingResponseInfoLoads::iterator iter = |
306 pending_info_loads_.find(response_id); | 300 pending_info_loads_.find(response_id); |
307 if (iter != pending_info_loads_.end()) | 301 if (iter != pending_info_loads_.end()) |
308 return iter->second; | 302 return iter->second; |
309 return new ResponseInfoLoadTask(manifest_url, group_id, response_id, this); | 303 return new ResponseInfoLoadTask(manifest_url, response_id, this); |
310 } | 304 } |
311 | 305 |
312 // Should only be called when creating a new response writer. | 306 // Should only be called when creating a new response writer. |
313 int64_t NewResponseId() { return ++last_response_id_; } | 307 int64_t NewResponseId() { return ++last_response_id_; } |
314 | 308 |
315 // Helpers to query and notify the QuotaManager. | 309 // Helpers to query and notify the QuotaManager. |
316 void UpdateUsageMapAndNotify(const GURL& origin, int64_t new_usage); | 310 void UpdateUsageMapAndNotify(const GURL& origin, int64_t new_usage); |
317 void ClearUsageMapAndNotify(); | 311 void ClearUsageMapAndNotify(); |
318 void NotifyStorageAccessed(const GURL& origin); | 312 void NotifyStorageAccessed(const GURL& origin); |
319 | 313 |
(...skipping 13 matching lines...) Expand all Loading... |
333 | 327 |
334 FRIEND_TEST_ALL_PREFIXES(content::AppCacheStorageTest, DelegateReferences); | 328 FRIEND_TEST_ALL_PREFIXES(content::AppCacheStorageTest, DelegateReferences); |
335 FRIEND_TEST_ALL_PREFIXES(content::AppCacheStorageTest, UsageMap); | 329 FRIEND_TEST_ALL_PREFIXES(content::AppCacheStorageTest, UsageMap); |
336 | 330 |
337 DISALLOW_COPY_AND_ASSIGN(AppCacheStorage); | 331 DISALLOW_COPY_AND_ASSIGN(AppCacheStorage); |
338 }; | 332 }; |
339 | 333 |
340 } // namespace content | 334 } // namespace content |
341 | 335 |
342 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_STORAGE_H_ | 336 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_STORAGE_H_ |
OLD | NEW |