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

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: clean up 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);
Marijn Kruisselbrink 2015/04/15 23:57:01 If you're trying to mirror ServiceWorkerStorage me
nhiroki 2015/04/23 05:01:04 Thank you for pointing it out. Currently there is
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 AddObserver(ServiceWorkerContextObserver* observer); 126 void AddObserver(ServiceWorkerContextObserver* observer);
98 void RemoveObserver(ServiceWorkerContextObserver* observer); 127 void RemoveObserver(ServiceWorkerContextObserver* observer);
99 128
100 bool is_incognito() const { return is_incognito_; } 129 bool is_incognito() const { return is_incognito_; }
101 130
102 private: 131 private:
103 friend class BackgroundSyncManagerTest; 132 friend class BackgroundSyncManagerTest;
104 friend class base::RefCountedThreadSafe<ServiceWorkerContextWrapper>; 133 friend class base::RefCountedThreadSafe<ServiceWorkerContextWrapper>;
105 friend class EmbeddedWorkerTestHelper; 134 friend class EmbeddedWorkerTestHelper;
135 friend class EmbeddedWorkerBrowserTest;
136 friend class ServiceWorkerDispatcherHost;
137 friend class ServiceWorkerInternalsUI;
106 friend class ServiceWorkerProcessManager; 138 friend class ServiceWorkerProcessManager;
139 friend class ServiceWorkerRequestHandler;
140 friend class ServiceWorkerVersionBrowserTest;
107 friend class MockServiceWorkerContextWrapper; 141 friend class MockServiceWorkerContextWrapper;
108 142
109 ~ServiceWorkerContextWrapper() override; 143 ~ServiceWorkerContextWrapper() override;
110 144
111 void InitInternal( 145 void InitInternal(
112 const base::FilePath& user_data_directory, 146 const base::FilePath& user_data_directory,
113 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager, 147 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager,
114 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread, 148 const scoped_refptr<base::SingleThreadTaskRunner>& disk_cache_thread,
115 storage::QuotaManagerProxy* quota_manager_proxy, 149 storage::QuotaManagerProxy* quota_manager_proxy,
116 storage::SpecialStoragePolicy* special_storage_policy); 150 storage::SpecialStoragePolicy* special_storage_policy);
117 void ShutdownOnIO(); 151 void ShutdownOnIO();
118 152
119 void DidDeleteAndStartOver(ServiceWorkerStatusCode status); 153 void DidDeleteAndStartOver(ServiceWorkerStatusCode status);
120 154
121 void DidGetAllRegistrationsForGetAllOrigins( 155 void DidGetAllRegistrationsForGetAllOrigins(
122 const GetUsageInfoCallback& callback, 156 const GetUsageInfoCallback& callback,
123 const std::vector<ServiceWorkerRegistrationInfo>& registrations); 157 const std::vector<ServiceWorkerRegistrationInfo>& registrations);
124 158
125 void DidFindRegistrationForCheckHasServiceWorker( 159 void DidFindRegistrationForCheckHasServiceWorker(
126 const GURL& other_url, 160 const GURL& other_url,
127 const CheckHasServiceWorkerCallback& callback, 161 const CheckHasServiceWorkerCallback& callback,
128 ServiceWorkerStatusCode status, 162 ServiceWorkerStatusCode status,
129 const scoped_refptr<ServiceWorkerRegistration>& registration); 163 const scoped_refptr<ServiceWorkerRegistration>& registration);
130 164
165 // The core context is only for use on the IO thread.
166 // Can be null before/during init, during/after shutdown, and after
167 // DeleteAndStartOver fails.
168 ServiceWorkerContextCore* context();
169
131 const scoped_refptr<ObserverListThreadSafe<ServiceWorkerContextObserver> > 170 const scoped_refptr<ObserverListThreadSafe<ServiceWorkerContextObserver> >
132 observer_list_; 171 observer_list_;
133 const scoped_ptr<ServiceWorkerProcessManager> process_manager_; 172 const scoped_ptr<ServiceWorkerProcessManager> process_manager_;
134 // Cleared in Shutdown(): 173 // Cleared in Shutdown():
135 scoped_ptr<ServiceWorkerContextCore> context_core_; 174 scoped_ptr<ServiceWorkerContextCore> context_core_;
136 175
137 // Initialized in Init(); true if the user data directory is empty. 176 // Initialized in Init(); true if the user data directory is empty.
138 bool is_incognito_; 177 bool is_incognito_;
139 178
140 // Raw pointer to the StoragePartitionImpl owning |this|. 179 // Raw pointer to the StoragePartitionImpl owning |this|.
141 StoragePartitionImpl* storage_partition_; 180 StoragePartitionImpl* storage_partition_;
142 }; 181 };
143 182
144 } // namespace content 183 } // namespace content
145 184
146 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ 185 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698