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

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

Issue 1079923002: ServiceWorker: Stop exposing ServiceWorkerContextCore (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 8 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 <vector> 8 #include <vector>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 22 matching lines...) Expand all
33 class StoragePartitionImpl; 33 class StoragePartitionImpl;
34 34
35 // A refcounted wrapper class for our core object. Higher level content lib 35 // A refcounted wrapper class for our core object. Higher level content lib
36 // classes keep references to this class on mutliple threads. The inner core 36 // classes keep references to this class on mutliple threads. The inner core
37 // instance is strictly single threaded and is not refcounted, the core object 37 // instance is strictly single threaded and is not refcounted, the core object
38 // is what is used internally in the service worker lib. 38 // is what is used internally in the service worker lib.
39 class CONTENT_EXPORT ServiceWorkerContextWrapper 39 class CONTENT_EXPORT ServiceWorkerContextWrapper
40 : NON_EXPORTED_BASE(public ServiceWorkerContext), 40 : NON_EXPORTED_BASE(public ServiceWorkerContext),
41 public base::RefCountedThreadSafe<ServiceWorkerContextWrapper> { 41 public base::RefCountedThreadSafe<ServiceWorkerContextWrapper> {
42 public: 42 public:
43 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; 43 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode)>;
44 using FindRegistrationCallback =
45 ServiceWorkerStorage::FindRegistrationCallback;
46 using GetRegistrationsInfosCallback =
47 ServiceWorkerStorage::GetRegistrationsInfosCallback;
48 using GetUserDataCallback = ServiceWorkerStorage::GetUserDataCallback;
49 using GetUserDataForAllRegistrationsCallback =
50 ServiceWorkerStorage::GetUserDataForAllRegistrationsCallback;
51
44 ServiceWorkerContextWrapper(BrowserContext* browser_context); 52 ServiceWorkerContextWrapper(BrowserContext* browser_context);
45 53
46 // Init and Shutdown are for use on the UI thread when the profile, 54 // Init and Shutdown are for use on the UI thread when the profile,
47 // storagepartition is being setup and torn down. 55 // storagepartition is being setup and torn down.
48 void Init(const base::FilePath& user_data_directory, 56 void Init(const base::FilePath& user_data_directory,
49 storage::QuotaManagerProxy* quota_manager_proxy, 57 storage::QuotaManagerProxy* quota_manager_proxy,
50 storage::SpecialStoragePolicy* special_storage_policy); 58 storage::SpecialStoragePolicy* special_storage_policy);
51 void Shutdown(); 59 void Shutdown();
52 60
53 // Deletes all files on disk and restarts the system asynchronously. This 61 // Deletes all files on disk and restarts the system asynchronously. This
54 // leaves the system in a disabled state until it's done. This should be 62 // leaves the system in a disabled state until it's done. This should be
55 // called on the IO thread. 63 // called on the IO thread.
56 void DeleteAndStartOver(); 64 void DeleteAndStartOver();
57 65
58 // The core context is only for use on the IO thread.
59 // Can be null before/during init, during/after shutdown, and after
60 // DeleteAndStartOver fails.
61 ServiceWorkerContextCore* context();
62
63 // The StoragePartition should only be used on the UI thread. 66 // The StoragePartition should only be used on the UI thread.
64 // Can be null before/during init and during/after shutdown. 67 // Can be null before/during init and during/after shutdown.
65 StoragePartitionImpl* storage_partition() const; 68 StoragePartitionImpl* storage_partition() const;
66 69
67 void set_storage_partition(StoragePartitionImpl* storage_partition); 70 void set_storage_partition(StoragePartitionImpl* storage_partition);
68 71
69 // The process manager can be used on either UI or IO. 72 // The process manager can be used on either UI or IO.
70 ServiceWorkerProcessManager* process_manager() { 73 ServiceWorkerProcessManager* process_manager() {
71 return process_manager_.get(); 74 return process_manager_.get();
72 } 75 }
73 76
74 // ServiceWorkerContext implementation: 77 // ServiceWorkerContext implementation:
75 void RegisterServiceWorker(const GURL& pattern, 78 void RegisterServiceWorker(const GURL& pattern,
76 const GURL& script_url, 79 const GURL& script_url,
77 const ResultCallback& continuation) override; 80 const ResultCallback& continuation) override;
78 void UnregisterServiceWorker(const GURL& pattern, 81 void UnregisterServiceWorker(const GURL& pattern,
79 const ResultCallback& continuation) override; 82 const ResultCallback& continuation) override;
80 void CanHandleMainResourceOffline( 83 void CanHandleMainResourceOffline(
81 const GURL& url, 84 const GURL& url,
82 const GURL& first_party, 85 const GURL& first_party,
83 const net::CompletionCallback& callback) override; 86 const net::CompletionCallback& callback) override;
84 void GetAllOriginsInfo(const GetUsageInfoCallback& callback) override; 87 void GetAllOriginsInfo(const GetUsageInfoCallback& callback) override;
85 void DeleteForOrigin(const GURL& origin_url) override; 88 void DeleteForOrigin(const GURL& origin_url) override;
86 void CheckHasServiceWorker( 89 void CheckHasServiceWorker(
87 const GURL& url, 90 const GURL& url,
88 const GURL& other_url, 91 const GURL& other_url,
89 const CheckHasServiceWorkerCallback& callback) override; 92 const CheckHasServiceWorkerCallback& callback) override;
90 93
94 ServiceWorkerRegistration* GetLiveRegistration(int64_t registration_id);
95 ServiceWorkerVersion* GetLiveVersion(int64_t version_id);
96 std::vector<ServiceWorkerRegistrationInfo> GetAllLiveRegistrationInfo();
97 std::vector<ServiceWorkerVersionInfo> GetAllLiveVersionInfo();
98
99 void FindRegistrationForDocument(const GURL& document_url,
100 const FindRegistrationCallback& callback);
101 void FindRegistrationForId(int64_t registration_id,
102 const GURL& origin,
103 const FindRegistrationCallback& callback);
104 void GetAllRegistrations(const GetRegistrationsInfosCallback& callback);
105 void GetRegistrationUserData(int64_t registration_id,
106 const std::string& key,
107 const GetUserDataCallback& callback);
108 void StoreRegistrationUserData(int64_t registration_id,
109 const GURL& origin,
110 const std::string& key,
111 const std::string& data,
112 const StatusCallback& callback);
113 void ClearRegistrationUserData(int64_t registration_id,
114 const std::string& key,
115 const StatusCallback& callback);
116 void GetUserDataForAllRegistrations(
117 const std::string& key,
118 const GetUserDataForAllRegistrationsCallback& callback);
119
91 // DeleteForOrigin with completion callback. Does not exit early, and returns 120 // DeleteForOrigin with completion callback. Does not exit early, and returns
92 // false if one or more of the deletions fail. 121 // false if one or more of the deletions fail.
93 virtual void DeleteForOrigin(const GURL& origin_url, 122 virtual void DeleteForOrigin(const GURL& origin_url,
94 const ResultCallback& done); 123 const ResultCallback& done);
95 124
96 void StartServiceWorker(const GURL& pattern, const StatusCallback& callback); 125 void StartServiceWorker(const GURL& pattern, const StatusCallback& callback);
97 void UpdateRegistration(const GURL& pattern); 126 void UpdateRegistration(const GURL& pattern);
98 void AddObserver(ServiceWorkerContextObserver* observer); 127 void AddObserver(ServiceWorkerContextObserver* observer);
99 void RemoveObserver(ServiceWorkerContextObserver* observer); 128 void RemoveObserver(ServiceWorkerContextObserver* observer);
100 129
101 bool is_incognito() const { return is_incognito_; } 130 bool is_incognito() const { return is_incognito_; }
102 131
103 private: 132 private:
104 friend class BackgroundSyncManagerTest; 133 friend class BackgroundSyncManagerTest;
105 friend class base::RefCountedThreadSafe<ServiceWorkerContextWrapper>; 134 friend class base::RefCountedThreadSafe<ServiceWorkerContextWrapper>;
106 friend class EmbeddedWorkerTestHelper; 135 friend class EmbeddedWorkerTestHelper;
136 friend class EmbeddedWorkerBrowserTest;
137 friend class ServiceWorkerDispatcherHost;
138 friend class ServiceWorkerInternalsUI;
107 friend class ServiceWorkerProcessManager; 139 friend class ServiceWorkerProcessManager;
140 friend class ServiceWorkerRequestHandler;
141 friend class ServiceWorkerVersionBrowserTest;
108 friend class MockServiceWorkerContextWrapper; 142 friend class MockServiceWorkerContextWrapper;
109 143
110 ~ServiceWorkerContextWrapper() override; 144 ~ServiceWorkerContextWrapper() override;
111 145
112 void InitInternal( 146 void InitInternal(
113 const base::FilePath& user_data_directory, 147 const base::FilePath& user_data_directory,
114 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager, 148 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager,
115 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, 149 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread,
116 storage::QuotaManagerProxy* quota_manager_proxy, 150 storage::QuotaManagerProxy* quota_manager_proxy,
117 storage::SpecialStoragePolicy* special_storage_policy); 151 storage::SpecialStoragePolicy* special_storage_policy);
118 void ShutdownOnIO(); 152 void ShutdownOnIO();
119 153
120 void DidDeleteAndStartOver(ServiceWorkerStatusCode status); 154 void DidDeleteAndStartOver(ServiceWorkerStatusCode status);
121 155
122 void DidGetAllRegistrationsForGetAllOrigins( 156 void DidGetAllRegistrationsForGetAllOrigins(
123 const GetUsageInfoCallback& callback, 157 const GetUsageInfoCallback& callback,
124 const std::vector<ServiceWorkerRegistrationInfo>& registrations); 158 const std::vector<ServiceWorkerRegistrationInfo>& registrations);
125 159
126 void DidFindRegistrationForCheckHasServiceWorker( 160 void DidFindRegistrationForCheckHasServiceWorker(
127 const GURL& other_url, 161 const GURL& other_url,
128 const CheckHasServiceWorkerCallback& callback, 162 const CheckHasServiceWorkerCallback& callback,
129 ServiceWorkerStatusCode status, 163 ServiceWorkerStatusCode status,
130 const scoped_refptr<ServiceWorkerRegistration>& registration); 164 const scoped_refptr<ServiceWorkerRegistration>& registration);
131 165
132 void DidFindRegistrationForUpdate( 166 void DidFindRegistrationForUpdate(
133 ServiceWorkerStatusCode status, 167 ServiceWorkerStatusCode status,
134 const scoped_refptr<content::ServiceWorkerRegistration>& registration); 168 const scoped_refptr<content::ServiceWorkerRegistration>& registration);
135 169
170 // The core context is only for use on the IO thread.
171 // Can be null before/during init, during/after shutdown, and after
172 // DeleteAndStartOver fails.
173 ServiceWorkerContextCore* context();
174
136 const scoped_refptr<ObserverListThreadSafe<ServiceWorkerContextObserver> > 175 const scoped_refptr<ObserverListThreadSafe<ServiceWorkerContextObserver> >
137 observer_list_; 176 observer_list_;
138 const scoped_ptr<ServiceWorkerProcessManager> process_manager_; 177 const scoped_ptr<ServiceWorkerProcessManager> process_manager_;
139 // Cleared in Shutdown(): 178 // Cleared in Shutdown():
140 scoped_ptr<ServiceWorkerContextCore> context_core_; 179 scoped_ptr<ServiceWorkerContextCore> context_core_;
141 180
142 // Initialized in Init(); true if the user data directory is empty. 181 // Initialized in Init(); true if the user data directory is empty.
143 bool is_incognito_; 182 bool is_incognito_;
144 183
145 // Raw pointer to the StoragePartitionImpl owning |this|. 184 // Raw pointer to the StoragePartitionImpl owning |this|.
146 StoragePartitionImpl* storage_partition_; 185 StoragePartitionImpl* storage_partition_;
147 }; 186 };
148 187
149 } // namespace content 188 } // namespace content
150 189
151 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ 190 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698