| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
| 14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 #include "testing/gtest/include/gtest/gtest_prod.h" |
| 15 #include "webkit/appcache/appcache_response.h" | 16 #include "webkit/appcache/appcache_response.h" |
| 16 #include "webkit/appcache/appcache_working_set.h" | 17 #include "webkit/appcache/appcache_working_set.h" |
| 17 | 18 |
| 18 class GURL; | 19 class GURL; |
| 19 | 20 |
| 20 namespace appcache { | 21 namespace appcache { |
| 21 | 22 |
| 22 class AppCache; | 23 class AppCache; |
| 24 class AppCacheEntry; |
| 23 class AppCacheGroup; | 25 class AppCacheGroup; |
| 24 class AppCacheService; | 26 class AppCacheService; |
| 25 | 27 |
| 26 class AppCacheStorage { | 28 class AppCacheStorage { |
| 27 public: | 29 public: |
| 28 | 30 |
| 29 class Delegate { | 31 class Delegate { |
| 30 public: | 32 public: |
| 31 virtual ~Delegate() {} | 33 virtual ~Delegate() {} |
| 32 | 34 |
| 33 // If a load fails the 'cache' will be NULL. | 35 // If a load fails the 'cache' will be NULL. |
| 34 virtual void OnCacheLoaded(AppCache* cache, int64 cache_id) {} | 36 virtual void OnCacheLoaded(AppCache* cache, int64 cache_id) {} |
| 35 | 37 |
| 36 // If a load fails the 'group' will be NULL. | 38 // If a load fails the 'group' will be NULL. |
| 37 virtual void OnGroupLoaded( | 39 virtual void OnGroupLoaded( |
| 38 AppCacheGroup* group, const GURL& manifest_url) {} | 40 AppCacheGroup* group, const GURL& manifest_url) {} |
| 39 | 41 |
| 40 // If successfully stored 'success' will be true. | 42 // If successfully stored 'success' will be true. |
| 41 virtual void OnGroupAndNewestCacheStored( | 43 virtual void OnGroupAndNewestCacheStored( |
| 42 AppCacheGroup* group, bool success) {} | 44 AppCacheGroup* group, bool success) {} |
| 43 | 45 |
| 44 // If the update fails, success will be false. | 46 // If the operation fails, success will be false. |
| 45 virtual void OnGroupMarkedAsObsolete(GURL& manifest_url, bool success) {} | 47 virtual void OnGroupMadeObsolete(AppCacheGroup* group, bool success) {} |
| 46 | 48 |
| 47 // If a load fails the 'response_info' will be NULL. | 49 // If a load fails the 'response_info' will be NULL. |
| 48 virtual void OnResponseInfoLoaded( | 50 virtual void OnResponseInfoLoaded( |
| 49 AppCacheResponseInfo* response_info, int64 response_id) {} | 51 AppCacheResponseInfo* response_info, int64 response_id) {} |
| 50 | 52 |
| 51 // If no response is found, response_id will be kNoResponseId. | 53 // If no response is found, response_id will be kNoResponseId. |
| 52 // If a response is found, the cache id and manifest url of the | 54 // If a response is found, the cache id and manifest url of the |
| 53 // containing cache and group are also returned. | 55 // containing cache and group are also returned. |
| 54 virtual void OnMainResponseFound( | 56 virtual void OnMainResponseFound( |
| 55 const GURL& url, int64 response_id, bool is_fallback, | 57 const GURL& url, const AppCacheEntry& entry, |
| 56 int64 cache_id, const GURL& mainfest_url) {} | 58 int64 cache_id, const GURL& mainfest_url) {} |
| 57 }; | 59 }; |
| 58 | 60 |
| 59 explicit AppCacheStorage(AppCacheService* service); | 61 explicit AppCacheStorage(AppCacheService* service); |
| 60 virtual ~AppCacheStorage(); | 62 virtual ~AppCacheStorage(); |
| 61 | 63 |
| 62 // Schedules a cache to be loaded from storage. Upon load completion | 64 // Schedules a cache to be loaded from storage. Upon load completion |
| 63 // the delegate will be called back. If the cache already resides in | 65 // the delegate will be called back. If the cache already resides in |
| 64 // memory, the delegate will be called back immediately without returning | 66 // memory, the delegate will be called back immediately without returning |
| 65 // to the message loop. If the load fails, the delegate will be called | 67 // to the message loop. If the load fails, the delegate will be called |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 101 |
| 100 // Immediately updates in-memory storage, if the cache is in memory, | 102 // Immediately updates in-memory storage, if the cache is in memory, |
| 101 // and schedules a task to update persistent storage. If the cache is | 103 // and schedules a task to update persistent storage. If the cache is |
| 102 // already scheduled to be loaded, upon loading completion the entry | 104 // already scheduled to be loaded, upon loading completion the entry |
| 103 // will be marked. There is no delegate completion callback. | 105 // will be marked. There is no delegate completion callback. |
| 104 virtual void MarkEntryAsForeign(const GURL& entry_url, int64 cache_id) = 0; | 106 virtual void MarkEntryAsForeign(const GURL& entry_url, int64 cache_id) = 0; |
| 105 | 107 |
| 106 // Schedules a task to update persistent storage and doom the group and all | 108 // Schedules a task to update persistent storage and doom the group and all |
| 107 // related caches and responses for deletion. Upon completion the in-memory | 109 // related caches and responses for deletion. Upon completion the in-memory |
| 108 // instance is marked as obsolete and the delegate callback is called. | 110 // instance is marked as obsolete and the delegate callback is called. |
| 109 virtual void MarkGroupAsObsolete( | 111 virtual void MakeGroupObsolete( |
| 110 AppCacheGroup* group, Delegate* delegate) = 0; | 112 AppCacheGroup* group, Delegate* delegate) = 0; |
| 111 | 113 |
| 112 // Cancels all pending callbacks for the delegate. The delegate callbacks | 114 // Cancels all pending callbacks for the delegate. The delegate callbacks |
| 113 // will not be invoked after, however any scheduled operations will still | 115 // will not be invoked after, however any scheduled operations will still |
| 114 // take place. The callbacks for subsequently scheduled operations are | 116 // take place. The callbacks for subsequently scheduled operations are |
| 115 // unaffected. | 117 // unaffected. |
| 116 void CancelDelegateCallbacks(Delegate* delegate) { | 118 void CancelDelegateCallbacks(Delegate* delegate) { |
| 117 DelegateReference* delegate_reference = GetDelegateReference(delegate); | 119 DelegateReference* delegate_reference = GetDelegateReference(delegate); |
| 118 if (delegate_reference) | 120 if (delegate_reference) |
| 119 delegate_reference->CancelReference(); | 121 delegate_reference->CancelReference(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 144 } | 146 } |
| 145 | 147 |
| 146 // The working set of object instances currently in memory. | 148 // The working set of object instances currently in memory. |
| 147 AppCacheWorkingSet* working_set() { return &working_set_; } | 149 AppCacheWorkingSet* working_set() { return &working_set_; } |
| 148 | 150 |
| 149 // Simple ptr back to the service object that owns us. | 151 // Simple ptr back to the service object that owns us. |
| 150 AppCacheService* service() { return service_; } | 152 AppCacheService* service() { return service_; } |
| 151 | 153 |
| 152 protected: | 154 protected: |
| 153 friend class AppCacheResponseTest; | 155 friend class AppCacheResponseTest; |
| 156 friend class AppCacheStorageTest; |
| 154 | 157 |
| 155 // Helper to call a collection of delegates. | 158 // Helper to call a collection of delegates. |
| 156 #define FOR_EACH_DELEGATE(delegates, func_and_args) \ | 159 #define FOR_EACH_DELEGATE(delegates, func_and_args) \ |
| 157 do { \ | 160 do { \ |
| 158 for (DelegateReferenceVector::iterator it = delegates.begin(); \ | 161 for (DelegateReferenceVector::iterator it = delegates.begin(); \ |
| 159 it != delegates.end(); ++it) { \ | 162 it != delegates.end(); ++it) { \ |
| 160 if (it->get()->delegate) \ | 163 if (it->get()->delegate) \ |
| 161 it->get()->delegate->func_and_args; \ | 164 it->get()->delegate->func_and_args; \ |
| 162 } \ | 165 } \ |
| 163 } while (0) | 166 } while (0) |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 int64 last_response_id_; | 285 int64 last_response_id_; |
| 283 | 286 |
| 284 AppCacheWorkingSet working_set_; | 287 AppCacheWorkingSet working_set_; |
| 285 AppCacheService* service_; | 288 AppCacheService* service_; |
| 286 DelegateReferenceMap delegate_references_; | 289 DelegateReferenceMap delegate_references_; |
| 287 PendingResponseInfoLoads pending_info_loads_; | 290 PendingResponseInfoLoads pending_info_loads_; |
| 288 | 291 |
| 289 // The set of last ids must be retrieved from storage prior to being used. | 292 // The set of last ids must be retrieved from storage prior to being used. |
| 290 static const int64 kUnitializedId = -1; | 293 static const int64 kUnitializedId = -1; |
| 291 | 294 |
| 295 FRIEND_TEST(AppCacheStorageTest, DelegateReferences); |
| 292 DISALLOW_COPY_AND_ASSIGN(AppCacheStorage); | 296 DISALLOW_COPY_AND_ASSIGN(AppCacheStorage); |
| 293 }; | 297 }; |
| 294 | 298 |
| 295 // TODO(michaeln): Maybe? | |
| 296 class AppCacheStoredItem { | |
| 297 public: | |
| 298 bool is_doomed() const { return is_doomed_; } | |
| 299 bool is_stored() const { return is_stored_; } | |
| 300 | |
| 301 protected: | |
| 302 AppCacheStoredItem() : is_doomed_(false), is_stored_(false) {} | |
| 303 | |
| 304 private: | |
| 305 friend class AppCacheStorage; | |
| 306 friend class MockAppCacheStorage; | |
| 307 | |
| 308 void set_is_doomed(bool b) { is_doomed_ = b; } | |
| 309 void set_is_stored(bool b) { is_stored_ = b; } | |
| 310 | |
| 311 bool is_doomed_; | |
| 312 bool is_stored_; | |
| 313 }; | |
| 314 | |
| 315 } // namespace appcache | 299 } // namespace appcache |
| 316 | 300 |
| 317 #endif // WEBKIT_APPCACHE_APPCACHE_STORAGE_H_ | 301 #endif // WEBKIT_APPCACHE_APPCACHE_STORAGE_H_ |
| 318 | 302 |
| OLD | NEW |