OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/files/file_path.h" | |
15 #include "base/macros.h" | 14 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/observer_list.h" |
| 17 #include "base/observer_list_threadsafe.h" |
17 #include "content/browser/service_worker/service_worker_context_core.h" | 18 #include "content/browser/service_worker/service_worker_context_core.h" |
| 19 #include "content/browser/service_worker/service_worker_context_core_observer.h" |
18 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
19 #include "content/common/worker_url_loader_factory_provider.mojom.h" | 21 #include "content/common/worker_url_loader_factory_provider.mojom.h" |
20 #include "content/public/browser/service_worker_context.h" | 22 #include "content/public/browser/service_worker_context.h" |
21 | 23 |
22 namespace base { | 24 namespace base { |
23 class FilePath; | 25 class FilePath; |
24 class SingleThreadTaskRunner; | 26 class SingleThreadTaskRunner; |
25 } | 27 } |
26 | 28 |
27 namespace storage { | 29 namespace storage { |
28 class QuotaManagerProxy; | 30 class QuotaManagerProxy; |
29 class SpecialStoragePolicy; | 31 class SpecialStoragePolicy; |
30 } | 32 } |
31 | 33 |
32 namespace content { | 34 namespace content { |
33 | 35 |
34 class BrowserContext; | 36 class BrowserContext; |
35 class ResourceContext; | 37 class ResourceContext; |
36 class ServiceWorkerContextCore; | 38 class ServiceWorkerContextObserver; |
37 class ServiceWorkerContextCoreObserver; | |
38 class StoragePartitionImpl; | 39 class StoragePartitionImpl; |
39 | 40 |
40 // A refcounted wrapper class for our core object. Higher level content lib | 41 // A refcounted wrapper class for our core object. Higher level content lib |
41 // classes keep references to this class on mutliple threads. The inner core | 42 // classes keep references to this class on mutliple threads. The inner core |
42 // instance is strictly single threaded and is not refcounted, the core object | 43 // instance is strictly single threaded and is not refcounted, the core object |
43 // is what is used internally in the service worker lib. | 44 // is what is used internally in the service worker lib. |
44 class CONTENT_EXPORT ServiceWorkerContextWrapper | 45 class CONTENT_EXPORT ServiceWorkerContextWrapper |
45 : NON_EXPORTED_BASE(public ServiceWorkerContext), | 46 : NON_EXPORTED_BASE(public ServiceWorkerContext), |
| 47 public ServiceWorkerContextCoreObserver, |
46 public base::RefCountedThreadSafe<ServiceWorkerContextWrapper> { | 48 public base::RefCountedThreadSafe<ServiceWorkerContextWrapper> { |
47 public: | 49 public: |
48 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode)>; | 50 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode)>; |
49 using BoolCallback = base::Callback<void(bool)>; | 51 using BoolCallback = base::Callback<void(bool)>; |
50 using FindRegistrationCallback = | 52 using FindRegistrationCallback = |
51 ServiceWorkerStorage::FindRegistrationCallback; | 53 ServiceWorkerStorage::FindRegistrationCallback; |
52 using GetRegistrationsInfosCallback = | 54 using GetRegistrationsInfosCallback = |
53 ServiceWorkerStorage::GetRegistrationsInfosCallback; | 55 ServiceWorkerStorage::GetRegistrationsInfosCallback; |
54 using GetUserDataCallback = ServiceWorkerStorage::GetUserDataCallback; | 56 using GetUserDataCallback = ServiceWorkerStorage::GetUserDataCallback; |
55 using GetUserDataForAllRegistrationsCallback = | 57 using GetUserDataForAllRegistrationsCallback = |
(...skipping 25 matching lines...) Expand all Loading... |
81 // The ResourceContext for the associated BrowserContext. This should only | 83 // The ResourceContext for the associated BrowserContext. This should only |
82 // be accessed on the IO thread, and can be null during initialization and | 84 // be accessed on the IO thread, and can be null during initialization and |
83 // shutdown. | 85 // shutdown. |
84 ResourceContext* resource_context(); | 86 ResourceContext* resource_context(); |
85 | 87 |
86 // The process manager can be used on either UI or IO. | 88 // The process manager can be used on either UI or IO. |
87 ServiceWorkerProcessManager* process_manager() { | 89 ServiceWorkerProcessManager* process_manager() { |
88 return process_manager_.get(); | 90 return process_manager_.get(); |
89 } | 91 } |
90 | 92 |
| 93 // ServiceWorkerContextCoreObserver implementation: |
| 94 void OnRegistrationStored(int64_t registration_id, |
| 95 const GURL& pattern) override; |
| 96 |
91 // ServiceWorkerContext implementation: | 97 // ServiceWorkerContext implementation: |
| 98 void AddObserver(ServiceWorkerContextObserver* observer) override; |
| 99 void RemoveObserver(ServiceWorkerContextObserver* observer) override; |
92 void RegisterServiceWorker(const GURL& pattern, | 100 void RegisterServiceWorker(const GURL& pattern, |
93 const GURL& script_url, | 101 const GURL& script_url, |
94 const ResultCallback& continuation) override; | 102 const ResultCallback& continuation) override; |
95 void UnregisterServiceWorker(const GURL& pattern, | 103 void UnregisterServiceWorker(const GURL& pattern, |
96 const ResultCallback& continuation) override; | 104 const ResultCallback& continuation) override; |
97 void GetAllOriginsInfo(const GetUsageInfoCallback& callback) override; | 105 void GetAllOriginsInfo(const GetUsageInfoCallback& callback) override; |
98 void DeleteForOrigin(const GURL& origin, | 106 void DeleteForOrigin(const GURL& origin, |
99 const ResultCallback& callback) override; | 107 const ResultCallback& callback) override; |
100 void CheckHasServiceWorker( | 108 void CheckHasServiceWorker( |
101 const GURL& url, | 109 const GURL& url, |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 285 |
278 void DidFindRegistrationForUpdate( | 286 void DidFindRegistrationForUpdate( |
279 ServiceWorkerStatusCode status, | 287 ServiceWorkerStatusCode status, |
280 scoped_refptr<content::ServiceWorkerRegistration> registration); | 288 scoped_refptr<content::ServiceWorkerRegistration> registration); |
281 | 289 |
282 // The core context is only for use on the IO thread. | 290 // The core context is only for use on the IO thread. |
283 // Can be null before/during init, during/after shutdown, and after | 291 // Can be null before/during init, during/after shutdown, and after |
284 // DeleteAndStartOver fails. | 292 // DeleteAndStartOver fails. |
285 ServiceWorkerContextCore* context(); | 293 ServiceWorkerContextCore* context(); |
286 | 294 |
| 295 // Observers of |context_core_| which live within content's implementation |
| 296 // boundary. Shared with |context_core_|. |
287 const scoped_refptr< | 297 const scoped_refptr< |
288 base::ObserverListThreadSafe<ServiceWorkerContextCoreObserver>> | 298 base::ObserverListThreadSafe<ServiceWorkerContextCoreObserver>> |
289 core_observer_list_; | 299 core_observer_list_; |
| 300 |
| 301 // Observers which live outside content's implementation boundary. Observer |
| 302 // methods will always be dispatched on the UI thread. |
| 303 base::ObserverList<ServiceWorkerContextObserver> observer_list_; |
| 304 |
290 const std::unique_ptr<ServiceWorkerProcessManager> process_manager_; | 305 const std::unique_ptr<ServiceWorkerProcessManager> process_manager_; |
291 // Cleared in ShutdownOnIO(): | 306 // Cleared in ShutdownOnIO(): |
292 std::unique_ptr<ServiceWorkerContextCore> context_core_; | 307 std::unique_ptr<ServiceWorkerContextCore> context_core_; |
293 | 308 |
294 // Initialized in Init(); true if the user data directory is empty. | 309 // Initialized in Init(); true if the user data directory is empty. |
295 bool is_incognito_; | 310 bool is_incognito_; |
296 | 311 |
297 // Raw pointer to the StoragePartitionImpl owning |this|. | 312 // Raw pointer to the StoragePartitionImpl owning |this|. |
298 StoragePartitionImpl* storage_partition_; | 313 StoragePartitionImpl* storage_partition_; |
299 | 314 |
300 // The ResourceContext associated with this context. | 315 // The ResourceContext associated with this context. |
301 ResourceContext* resource_context_; | 316 ResourceContext* resource_context_; |
302 | 317 |
303 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContextWrapper); | 318 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContextWrapper); |
304 }; | 319 }; |
305 | 320 |
306 } // namespace content | 321 } // namespace content |
307 | 322 |
308 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ | 323 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ |
OLD | NEW |