| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 it->get()->delegate->func_and_args; \ | 199 it->get()->delegate->func_and_args; \ |
| 200 } \ | 200 } \ |
| 201 } while (0) | 201 } while (0) |
| 202 | 202 |
| 203 // Helper used to manage multiple references to a 'delegate' and to | 203 // Helper used to manage multiple references to a 'delegate' and to |
| 204 // allow all pending callbacks to that delegate to be easily cancelled. | 204 // allow all pending callbacks to that delegate to be easily cancelled. |
| 205 struct DelegateReference : public base::RefCounted<DelegateReference> { | 205 struct DelegateReference : public base::RefCounted<DelegateReference> { |
| 206 Delegate* delegate; | 206 Delegate* delegate; |
| 207 AppCacheStorage* storage; | 207 AppCacheStorage* storage; |
| 208 | 208 |
| 209 DelegateReference(Delegate* delegate, AppCacheStorage* storage) | 209 DelegateReference(Delegate* delegate, AppCacheStorage* storage); |
| 210 : delegate(delegate), storage(storage) { | |
| 211 storage->delegate_references_.insert( | |
| 212 DelegateReferenceMap::value_type(delegate, this)); | |
| 213 } | |
| 214 | 210 |
| 215 void CancelReference() { | 211 void CancelReference() { |
| 216 storage->delegate_references_.erase(delegate); | 212 storage->delegate_references_.erase(delegate); |
| 217 storage = NULL; | 213 storage = NULL; |
| 218 delegate = NULL; | 214 delegate = NULL; |
| 219 } | 215 } |
| 220 | 216 |
| 221 private: | 217 private: |
| 222 friend class base::RefCounted<DelegateReference>; | 218 friend class base::RefCounted<DelegateReference>; |
| 223 | 219 |
| 224 ~DelegateReference() { | 220 virtual ~DelegateReference(); |
| 225 if (delegate) | |
| 226 storage->delegate_references_.erase(delegate); | |
| 227 } | |
| 228 }; | 221 }; |
| 229 typedef std::map<Delegate*, DelegateReference*> DelegateReferenceMap; | 222 typedef std::map<Delegate*, DelegateReference*> DelegateReferenceMap; |
| 230 typedef std::vector<scoped_refptr<DelegateReference> > | 223 typedef std::vector<scoped_refptr<DelegateReference> > |
| 231 DelegateReferenceVector; | 224 DelegateReferenceVector; |
| 232 | 225 |
| 233 // Helper used to manage an async LoadResponseInfo calls on behalf of | 226 // Helper used to manage an async LoadResponseInfo calls on behalf of |
| 234 // multiple callers. | 227 // multiple callers. |
| 235 class ResponseInfoLoadTask { | 228 class ResponseInfoLoadTask { |
| 236 public: | 229 public: |
| 237 ResponseInfoLoadTask(const GURL& manifest_url, int64 response_id, | 230 ResponseInfoLoadTask(const GURL& manifest_url, int64 response_id, |
| 238 AppCacheStorage* storage); | 231 AppCacheStorage* storage); |
| 232 ~ResponseInfoLoadTask(); |
| 239 | 233 |
| 240 int64 response_id() const { return response_id_; } | 234 int64 response_id() const { return response_id_; } |
| 241 const GURL& manifest_url() const { return manifest_url_; } | 235 const GURL& manifest_url() const { return manifest_url_; } |
| 242 | 236 |
| 243 void AddDelegate(DelegateReference* delegate_reference) { | 237 void AddDelegate(DelegateReference* delegate_reference) { |
| 244 delegates_.push_back(delegate_reference); | 238 delegates_.push_back(delegate_reference); |
| 245 } | 239 } |
| 246 | 240 |
| 247 void StartIfNeeded(); | 241 void StartIfNeeded(); |
| 248 | 242 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 303 |
| 310 FRIEND_TEST_ALL_PREFIXES(AppCacheStorageTest, DelegateReferences); | 304 FRIEND_TEST_ALL_PREFIXES(AppCacheStorageTest, DelegateReferences); |
| 311 | 305 |
| 312 DISALLOW_COPY_AND_ASSIGN(AppCacheStorage); | 306 DISALLOW_COPY_AND_ASSIGN(AppCacheStorage); |
| 313 }; | 307 }; |
| 314 | 308 |
| 315 } // namespace appcache | 309 } // namespace appcache |
| 316 | 310 |
| 317 #endif // WEBKIT_APPCACHE_APPCACHE_STORAGE_H_ | 311 #endif // WEBKIT_APPCACHE_APPCACHE_STORAGE_H_ |
| 318 | 312 |
| OLD | NEW |