| 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 CONTENT_BROWSER_APPCACHE_APPCACHE_HOST_H_ | 5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_HOST_H_ |
| 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_HOST_H_ | 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_HOST_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 9 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 11 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 12 #include "content/browser/appcache/appcache_group.h" | 15 #include "content/browser/appcache/appcache_group.h" |
| 13 #include "content/browser/appcache/appcache_service_impl.h" | 16 #include "content/browser/appcache/appcache_service_impl.h" |
| 14 #include "content/browser/appcache/appcache_storage.h" | 17 #include "content/browser/appcache/appcache_storage.h" |
| 15 #include "content/common/appcache_interfaces.h" | 18 #include "content/common/appcache_interfaces.h" |
| 16 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
| 17 #include "content/public/common/resource_type.h" | 20 #include "content/public/common/resource_type.h" |
| 18 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 19 | 22 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 AppCacheServiceImpl* service); | 74 AppCacheServiceImpl* service); |
| 72 ~AppCacheHost() override; | 75 ~AppCacheHost() override; |
| 73 | 76 |
| 74 // Adds/removes an observer, the AppCacheHost does not take | 77 // Adds/removes an observer, the AppCacheHost does not take |
| 75 // ownership of the observer. | 78 // ownership of the observer. |
| 76 void AddObserver(Observer* observer); | 79 void AddObserver(Observer* observer); |
| 77 void RemoveObserver(Observer* observer); | 80 void RemoveObserver(Observer* observer); |
| 78 | 81 |
| 79 // Support for cache selection and scriptable method calls. | 82 // Support for cache selection and scriptable method calls. |
| 80 bool SelectCache(const GURL& document_url, | 83 bool SelectCache(const GURL& document_url, |
| 81 const int64 cache_document_was_loaded_from, | 84 const int64_t cache_document_was_loaded_from, |
| 82 const GURL& manifest_url); | 85 const GURL& manifest_url); |
| 83 bool SelectCacheForWorker(int parent_process_id, | 86 bool SelectCacheForWorker(int parent_process_id, |
| 84 int parent_host_id); | 87 int parent_host_id); |
| 85 bool SelectCacheForSharedWorker(int64 appcache_id); | 88 bool SelectCacheForSharedWorker(int64_t appcache_id); |
| 86 bool MarkAsForeignEntry(const GURL& document_url, | 89 bool MarkAsForeignEntry(const GURL& document_url, |
| 87 int64 cache_document_was_loaded_from); | 90 int64_t cache_document_was_loaded_from); |
| 88 void GetStatusWithCallback(const GetStatusCallback& callback, | 91 void GetStatusWithCallback(const GetStatusCallback& callback, |
| 89 void* callback_param); | 92 void* callback_param); |
| 90 void StartUpdateWithCallback(const StartUpdateCallback& callback, | 93 void StartUpdateWithCallback(const StartUpdateCallback& callback, |
| 91 void* callback_param); | 94 void* callback_param); |
| 92 void SwapCacheWithCallback(const SwapCacheCallback& callback, | 95 void SwapCacheWithCallback(const SwapCacheCallback& callback, |
| 93 void* callback_param); | 96 void* callback_param); |
| 94 | 97 |
| 95 // Called prior to the main resource load. When the system contains multiple | 98 // Called prior to the main resource load. When the system contains multiple |
| 96 // candidates for a main resource load, the appcache preferred by the host | 99 // candidates for a main resource load, the appcache preferred by the host |
| 97 // that created this host is used to break ties. | 100 // that created this host is used to break ties. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 // Associations with complete caches are established either thru the cache | 139 // Associations with complete caches are established either thru the cache |
| 137 // selection algorithm implemented (in this class), or by the update algorithm | 140 // selection algorithm implemented (in this class), or by the update algorithm |
| 138 // (see AppCacheUpdateJob). | 141 // (see AppCacheUpdateJob). |
| 139 void AssociateCompleteCache(AppCache* cache); | 142 void AssociateCompleteCache(AppCache* cache); |
| 140 | 143 |
| 141 // Adds a reference to the newest complete cache in a group, unless it's the | 144 // Adds a reference to the newest complete cache in a group, unless it's the |
| 142 // same as the cache that is currently associated with the host. | 145 // same as the cache that is currently associated with the host. |
| 143 void SetSwappableCache(AppCacheGroup* group); | 146 void SetSwappableCache(AppCacheGroup* group); |
| 144 | 147 |
| 145 // Used to ensure that a loaded appcache survives a frame navigation. | 148 // Used to ensure that a loaded appcache survives a frame navigation. |
| 146 void LoadMainResourceCache(int64 cache_id); | 149 void LoadMainResourceCache(int64_t cache_id); |
| 147 | 150 |
| 148 // Used to notify the host that a namespace resource is being delivered as | 151 // Used to notify the host that a namespace resource is being delivered as |
| 149 // the main resource of the page and to provide its url. | 152 // the main resource of the page and to provide its url. |
| 150 void NotifyMainResourceIsNamespaceEntry(const GURL& namespace_entry_url); | 153 void NotifyMainResourceIsNamespaceEntry(const GURL& namespace_entry_url); |
| 151 | 154 |
| 152 // Used to notify the host that the main resource was blocked by a policy. To | 155 // Used to notify the host that the main resource was blocked by a policy. To |
| 153 // work properly, this method needs to by invoked prior to cache selection. | 156 // work properly, this method needs to by invoked prior to cache selection. |
| 154 void NotifyMainResourceBlocked(const GURL& manifest_url); | 157 void NotifyMainResourceBlocked(const GURL& manifest_url); |
| 155 | 158 |
| 156 // Used by the update job to keep track of which hosts are associated | 159 // Used by the update job to keep track of which hosts are associated |
| (...skipping 23 matching lines...) Expand all Loading... |
| 180 void PrepareForTransfer(); | 183 void PrepareForTransfer(); |
| 181 void CompleteTransfer(int host_id, AppCacheFrontend* frontend); | 184 void CompleteTransfer(int host_id, AppCacheFrontend* frontend); |
| 182 | 185 |
| 183 private: | 186 private: |
| 184 friend class content::AppCacheHostTest; | 187 friend class content::AppCacheHostTest; |
| 185 friend class content::AppCacheStorageImplTest; | 188 friend class content::AppCacheStorageImplTest; |
| 186 friend class content::AppCacheRequestHandlerTest; | 189 friend class content::AppCacheRequestHandlerTest; |
| 187 friend class content::AppCacheUpdateJobTest; | 190 friend class content::AppCacheUpdateJobTest; |
| 188 | 191 |
| 189 AppCacheStatus GetStatus(); | 192 AppCacheStatus GetStatus(); |
| 190 void LoadSelectedCache(int64 cache_id); | 193 void LoadSelectedCache(int64_t cache_id); |
| 191 void LoadOrCreateGroup(const GURL& manifest_url); | 194 void LoadOrCreateGroup(const GURL& manifest_url); |
| 192 | 195 |
| 193 // See public Associate*Host() methods above. | 196 // See public Associate*Host() methods above. |
| 194 void AssociateCacheHelper(AppCache* cache, const GURL& manifest_url); | 197 void AssociateCacheHelper(AppCache* cache, const GURL& manifest_url); |
| 195 | 198 |
| 196 // AppCacheStorage::Delegate impl | 199 // AppCacheStorage::Delegate impl |
| 197 void OnCacheLoaded(AppCache* cache, int64 cache_id) override; | 200 void OnCacheLoaded(AppCache* cache, int64_t cache_id) override; |
| 198 void OnGroupLoaded(AppCacheGroup* group, const GURL& manifest_url) override; | 201 void OnGroupLoaded(AppCacheGroup* group, const GURL& manifest_url) override; |
| 199 // AppCacheServiceImpl::Observer impl | 202 // AppCacheServiceImpl::Observer impl |
| 200 void OnServiceReinitialized( | 203 void OnServiceReinitialized( |
| 201 AppCacheStorageReference* old_storage_ref) override; | 204 AppCacheStorageReference* old_storage_ref) override; |
| 202 | 205 |
| 203 void FinishCacheSelection(AppCache* cache, AppCacheGroup* group); | 206 void FinishCacheSelection(AppCache* cache, AppCacheGroup* group); |
| 204 void DoPendingGetStatus(); | 207 void DoPendingGetStatus(); |
| 205 void DoPendingStartUpdate(); | 208 void DoPendingStartUpdate(); |
| 206 void DoPendingSwapCache(); | 209 void DoPendingSwapCache(); |
| 207 | 210 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 scoped_refptr<AppCacheGroup> group_being_updated_; | 258 scoped_refptr<AppCacheGroup> group_being_updated_; |
| 256 | 259 |
| 257 // Similarly, keep a reference to the newest cache of the group until the | 260 // Similarly, keep a reference to the newest cache of the group until the |
| 258 // update completes. When adding a new master entry to a cache that is not | 261 // update completes. When adding a new master entry to a cache that is not |
| 259 // in use in any other host, this reference keeps the cache in memory. | 262 // in use in any other host, this reference keeps the cache in memory. |
| 260 scoped_refptr<AppCache> newest_cache_of_group_being_updated_; | 263 scoped_refptr<AppCache> newest_cache_of_group_being_updated_; |
| 261 | 264 |
| 262 // Keep a reference to the cache of the main resource so it survives frame | 265 // Keep a reference to the cache of the main resource so it survives frame |
| 263 // navigations. | 266 // navigations. |
| 264 scoped_refptr<AppCache> main_resource_cache_; | 267 scoped_refptr<AppCache> main_resource_cache_; |
| 265 int64 pending_main_resource_cache_id_; | 268 int64_t pending_main_resource_cache_id_; |
| 266 | 269 |
| 267 // Cache loading is async, if we're loading a specific cache or group | 270 // Cache loading is async, if we're loading a specific cache or group |
| 268 // for the purposes of cache selection, one or the other of these will | 271 // for the purposes of cache selection, one or the other of these will |
| 269 // indicate which cache or group is being loaded. | 272 // indicate which cache or group is being loaded. |
| 270 int64 pending_selected_cache_id_; | 273 int64_t pending_selected_cache_id_; |
| 271 GURL pending_selected_manifest_url_; | 274 GURL pending_selected_manifest_url_; |
| 272 | 275 |
| 273 // Used to defend against bad IPC messages. | 276 // Used to defend against bad IPC messages. |
| 274 bool was_select_cache_called_; | 277 bool was_select_cache_called_; |
| 275 | 278 |
| 276 // Used to avoid stepping on pages controlled by ServiceWorkers. | 279 // Used to avoid stepping on pages controlled by ServiceWorkers. |
| 277 bool is_cache_selection_enabled_; | 280 bool is_cache_selection_enabled_; |
| 278 | 281 |
| 279 // A new master entry to be added to the cache, may be empty. | 282 // A new master entry to be added to the cache, may be empty. |
| 280 GURL new_master_entry_url_; | 283 GURL new_master_entry_url_; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 FRIEND_TEST_ALL_PREFIXES(content::AppCacheHostTest, SelectCacheBlocked); | 341 FRIEND_TEST_ALL_PREFIXES(content::AppCacheHostTest, SelectCacheBlocked); |
| 339 FRIEND_TEST_ALL_PREFIXES(content::AppCacheHostTest, SelectCacheTwice); | 342 FRIEND_TEST_ALL_PREFIXES(content::AppCacheHostTest, SelectCacheTwice); |
| 340 FRIEND_TEST_ALL_PREFIXES(content::AppCacheTest, CleanupUnusedCache); | 343 FRIEND_TEST_ALL_PREFIXES(content::AppCacheTest, CleanupUnusedCache); |
| 341 | 344 |
| 342 DISALLOW_COPY_AND_ASSIGN(AppCacheHost); | 345 DISALLOW_COPY_AND_ASSIGN(AppCacheHost); |
| 343 }; | 346 }; |
| 344 | 347 |
| 345 } // namespace content | 348 } // namespace content |
| 346 | 349 |
| 347 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_HOST_H_ | 350 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_HOST_H_ |
| OLD | NEW |