Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: content/browser/service_worker/service_worker_context_wrapper.h

Issue 1771283002: service worker: Observe when resource context is shutting down (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix unittests Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <string>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
16 #include "content/browser/service_worker/service_worker_context_core.h" 17 #include "content/browser/service_worker/service_worker_context_core.h"
17 #include "content/common/content_export.h" 18 #include "content/common/content_export.h"
18 #include "content/public/browser/service_worker_context.h" 19 #include "content/public/browser/service_worker_context.h"
20 #include "net/url_request/url_request_context_getter_observer.h"
19 21
20 namespace base { 22 namespace base {
21 class FilePath; 23 class FilePath;
22 class SequencedTaskRunner; 24 class SequencedTaskRunner;
23 class SingleThreadTaskRunner; 25 class SingleThreadTaskRunner;
24 } 26 }
25 27
26 namespace storage { 28 namespace storage {
27 class QuotaManagerProxy; 29 class QuotaManagerProxy;
28 class SpecialStoragePolicy; 30 class SpecialStoragePolicy;
29 } 31 }
30 32
31 namespace content { 33 namespace content {
32 34
33 class BrowserContext; 35 class BrowserContext;
34 class ResourceContext; 36 class ResourceContext;
35 class ServiceWorkerContextCore; 37 class ServiceWorkerContextCore;
36 class ServiceWorkerContextObserver; 38 class ServiceWorkerContextObserver;
37 class StoragePartitionImpl; 39 class StoragePartitionImpl;
38 40
39 // 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
40 // 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
41 // 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
42 // is what is used internally in the service worker lib. 44 // is what is used internally in the service worker lib.
43 class CONTENT_EXPORT ServiceWorkerContextWrapper 45 class CONTENT_EXPORT ServiceWorkerContextWrapper
44 : NON_EXPORTED_BASE(public ServiceWorkerContext), 46 : NON_EXPORTED_BASE(public ServiceWorkerContext),
47 public net::URLRequestContextGetterObserver,
45 public base::RefCountedThreadSafe<ServiceWorkerContextWrapper> { 48 public base::RefCountedThreadSafe<ServiceWorkerContextWrapper> {
46 public: 49 public:
47 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode)>; 50 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode)>;
48 using BoolCallback = base::Callback<void(bool)>; 51 using BoolCallback = base::Callback<void(bool)>;
49 using FindRegistrationCallback = 52 using FindRegistrationCallback =
50 ServiceWorkerStorage::FindRegistrationCallback; 53 ServiceWorkerStorage::FindRegistrationCallback;
51 using GetRegistrationsInfosCallback = 54 using GetRegistrationsInfosCallback =
52 ServiceWorkerStorage::GetRegistrationsInfosCallback; 55 ServiceWorkerStorage::GetRegistrationsInfosCallback;
53 using GetUserDataCallback = ServiceWorkerStorage::GetUserDataCallback; 56 using GetUserDataCallback = ServiceWorkerStorage::GetUserDataCallback;
54 using GetUserDataForAllRegistrationsCallback = 57 using GetUserDataForAllRegistrationsCallback =
55 ServiceWorkerStorage::GetUserDataForAllRegistrationsCallback; 58 ServiceWorkerStorage::GetUserDataForAllRegistrationsCallback;
56 59
57 ServiceWorkerContextWrapper(BrowserContext* browser_context); 60 ServiceWorkerContextWrapper(BrowserContext* browser_context);
58 61
59 // Init and Shutdown are for use on the UI thread when the profile, 62 // Init and Shutdown are for use on the UI thread when the profile,
60 // storagepartition is being setup and torn down. 63 // storagepartition is being setup and torn down.
61 void Init(const base::FilePath& user_data_directory, 64 void Init(const base::FilePath& user_data_directory,
62 storage::QuotaManagerProxy* quota_manager_proxy, 65 storage::QuotaManagerProxy* quota_manager_proxy,
63 storage::SpecialStoragePolicy* special_storage_policy); 66 storage::SpecialStoragePolicy* special_storage_policy);
64 void Shutdown(); 67 void Shutdown();
65 68
69 // Must be called on the IO thread.
70 void InitializeResourceContext(
71 ResourceContext* resource_context,
72 scoped_refptr<net::URLRequestContextGetter> request_context_getter);
73
74 // For net::URLRequestContextGetterObserver
75 void OnContextShuttingDown() override;
76
66 // Deletes all files on disk and restarts the system asynchronously. This 77 // Deletes all files on disk and restarts the system asynchronously. This
67 // leaves the system in a disabled state until it's done. This should be 78 // leaves the system in a disabled state until it's done. This should be
68 // called on the IO thread. 79 // called on the IO thread.
69 void DeleteAndStartOver(); 80 void DeleteAndStartOver();
70 81
71 // The StoragePartition should only be used on the UI thread. 82 // The StoragePartition should only be used on the UI thread.
72 // Can be null before/during init and during/after shutdown. 83 // Can be null before/during init and during/after shutdown.
73 StoragePartitionImpl* storage_partition() const; 84 StoragePartitionImpl* storage_partition() const;
74 85
75 void set_storage_partition(StoragePartitionImpl* storage_partition); 86 void set_storage_partition(StoragePartitionImpl* storage_partition);
76 87
77 // The ResourceContext for the associated BrowserContext. This should only 88 // The ResourceContext for the associated BrowserContext. This should only
78 // be accessed on the IO thread, and can be null during initialization and 89 // be accessed on the IO thread, and can be null during initialization and
79 // shutdown. 90 // shutdown.
80 ResourceContext* resource_context(); 91 ResourceContext* resource_context();
81 92
82 void set_resource_context(ResourceContext* resource_context);
83
84 // The process manager can be used on either UI or IO. 93 // The process manager can be used on either UI or IO.
85 ServiceWorkerProcessManager* process_manager() { 94 ServiceWorkerProcessManager* process_manager() {
86 return process_manager_.get(); 95 return process_manager_.get();
87 } 96 }
88 97
89 // ServiceWorkerContext implementation: 98 // ServiceWorkerContext implementation:
90 void RegisterServiceWorker(const GURL& pattern, 99 void RegisterServiceWorker(const GURL& pattern,
91 const GURL& script_url, 100 const GURL& script_url,
92 const ResultCallback& continuation) override; 101 const ResultCallback& continuation) override;
93 void UnregisterServiceWorker(const GURL& pattern, 102 void UnregisterServiceWorker(const GURL& pattern,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 const scoped_refptr<content::ServiceWorkerRegistration>& registration); 230 const scoped_refptr<content::ServiceWorkerRegistration>& registration);
222 231
223 // The core context is only for use on the IO thread. 232 // The core context is only for use on the IO thread.
224 // Can be null before/during init, during/after shutdown, and after 233 // Can be null before/during init, during/after shutdown, and after
225 // DeleteAndStartOver fails. 234 // DeleteAndStartOver fails.
226 ServiceWorkerContextCore* context(); 235 ServiceWorkerContextCore* context();
227 236
228 const scoped_refptr<base::ObserverListThreadSafe< 237 const scoped_refptr<base::ObserverListThreadSafe<
229 ServiceWorkerContextObserver>> observer_list_; 238 ServiceWorkerContextObserver>> observer_list_;
230 const scoped_ptr<ServiceWorkerProcessManager> process_manager_; 239 const scoped_ptr<ServiceWorkerProcessManager> process_manager_;
231 // Cleared in Shutdown(): 240 // Cleared in ShutdownOnIO():
232 scoped_ptr<ServiceWorkerContextCore> context_core_; 241 scoped_ptr<ServiceWorkerContextCore> context_core_;
233 242
234 // Initialized in Init(); true if the user data directory is empty. 243 // Initialized in Init(); true if the user data directory is empty.
235 bool is_incognito_; 244 bool is_incognito_;
236 245
237 // Raw pointer to the StoragePartitionImpl owning |this|. 246 // Raw pointer to the StoragePartitionImpl owning |this|.
238 StoragePartitionImpl* storage_partition_; 247 StoragePartitionImpl* storage_partition_;
239 248
240 // The ResourceContext associated with this context. 249 // The ResourceContext associated with this context.
241 ResourceContext* resource_context_; 250 ResourceContext* resource_context_;
242 251
252 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
253
243 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContextWrapper); 254 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContextWrapper);
244 }; 255 };
245 256
246 } // namespace content 257 } // namespace content
247 258
248 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ 259 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698