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_PROVIDER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... | |
41 // | 41 // |
42 // Note this class can also host a running service worker, in which | 42 // Note this class can also host a running service worker, in which |
43 // case it will observe resource loads made directly by the service worker. | 43 // case it will observe resource loads made directly by the service worker. |
44 class CONTENT_EXPORT ServiceWorkerProviderHost | 44 class CONTENT_EXPORT ServiceWorkerProviderHost |
45 : public NON_EXPORTED_BASE(ServiceWorkerRegistration::Listener), | 45 : public NON_EXPORTED_BASE(ServiceWorkerRegistration::Listener), |
46 public base::SupportsWeakPtr<ServiceWorkerProviderHost> { | 46 public base::SupportsWeakPtr<ServiceWorkerProviderHost> { |
47 public: | 47 public: |
48 using FocusCallback = base::Callback<void(bool)>; | 48 using FocusCallback = base::Callback<void(bool)>; |
49 using GetClientInfoCallback = | 49 using GetClientInfoCallback = |
50 base::Callback<void(const ServiceWorkerClientInfo&)>; | 50 base::Callback<void(const ServiceWorkerClientInfo&)>; |
51 using GetReadyRegistrationCallback = | |
52 base::Callback<void(ServiceWorkerRegistration* reigstration)>; | |
51 | 53 |
52 // If |render_frame_id| is MSG_ROUTING_NONE, this provider host works for the | 54 // If |render_frame_id| is MSG_ROUTING_NONE, this provider host works for the |
53 // worker context. | 55 // worker context. |
54 ServiceWorkerProviderHost(int render_process_id, | 56 ServiceWorkerProviderHost(int render_process_id, |
55 int render_frame_id, | 57 int render_frame_id, |
56 int provider_id, | 58 int provider_id, |
57 base::WeakPtr<ServiceWorkerContextCore> context, | 59 base::WeakPtr<ServiceWorkerContextCore> context, |
58 ServiceWorkerDispatcherHost* dispatcher_host); | 60 ServiceWorkerDispatcherHost* dispatcher_host); |
59 virtual ~ServiceWorkerProviderHost(); | 61 virtual ~ServiceWorkerProviderHost(); |
60 | 62 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 // Asks the renderer to send back the document information. | 152 // Asks the renderer to send back the document information. |
151 void GetClientInfo(const GetClientInfoCallback& callback) const; | 153 void GetClientInfo(const GetClientInfoCallback& callback) const; |
152 | 154 |
153 // Adds reference of this host's process to the |pattern|, the reference will | 155 // Adds reference of this host's process to the |pattern|, the reference will |
154 // be removed in destructor. | 156 // be removed in destructor. |
155 void AddScopedProcessReferenceToPattern(const GURL& pattern); | 157 void AddScopedProcessReferenceToPattern(const GURL& pattern); |
156 | 158 |
157 // |registration| claims the document to be controlled. | 159 // |registration| claims the document to be controlled. |
158 void ClaimedByRegistration(ServiceWorkerRegistration* registration); | 160 void ClaimedByRegistration(ServiceWorkerRegistration* registration); |
159 | 161 |
162 // Calls by dispatcher host to get "ready" registration. | |
dominicc (has gone to gerrit)
2015/02/10 04:10:53
Calls -> Called
"ready" registration -> the regis
xiang
2015/02/12 07:14:22
Done.
| |
163 void GetReadyRegistration(const GetReadyRegistrationCallback& callback); | |
164 | |
160 // Methods to support cross site navigations. | 165 // Methods to support cross site navigations. |
161 void PrepareForCrossSiteTransfer(); | 166 void PrepareForCrossSiteTransfer(); |
162 void CompleteCrossSiteTransfer( | 167 void CompleteCrossSiteTransfer( |
163 int new_process_id, | 168 int new_process_id, |
164 int new_frame_id, | 169 int new_frame_id, |
165 int new_provider_id, | 170 int new_provider_id, |
166 ServiceWorkerDispatcherHost* dispatcher_host); | 171 ServiceWorkerDispatcherHost* dispatcher_host); |
167 ServiceWorkerDispatcherHost* dispatcher_host() const { | 172 ServiceWorkerDispatcherHost* dispatcher_host() const { |
168 return dispatcher_host_; | 173 return dispatcher_host_; |
169 } | 174 } |
170 | 175 |
171 // Sends event messages to the renderer. Events for the worker are queued up | 176 // Sends event messages to the renderer. Events for the worker are queued up |
172 // until the worker thread id is known via SetReadyToSendMessagesToWorker(). | 177 // until the worker thread id is known via SetReadyToSendMessagesToWorker(). |
173 void SendUpdateFoundMessage( | 178 void SendUpdateFoundMessage( |
174 const ServiceWorkerRegistrationObjectInfo& object_info); | 179 const ServiceWorkerRegistrationObjectInfo& object_info); |
175 void SendSetVersionAttributesMessage( | 180 void SendSetVersionAttributesMessage( |
176 int registration_handle_id, | 181 int registration_handle_id, |
177 ChangedVersionAttributesMask changed_mask, | 182 ChangedVersionAttributesMask changed_mask, |
178 ServiceWorkerVersion* installing_version, | 183 ServiceWorkerVersion* installing_version, |
179 ServiceWorkerVersion* waiting_version, | 184 ServiceWorkerVersion* waiting_version, |
180 ServiceWorkerVersion* active_version); | 185 ServiceWorkerVersion* active_version); |
181 void SendServiceWorkerStateChangedMessage( | 186 void SendServiceWorkerStateChangedMessage( |
182 int worker_handle_id, | 187 int worker_handle_id, |
183 blink::WebServiceWorkerState state); | 188 blink::WebServiceWorkerState state); |
184 | 189 |
185 // Sets the worker thread id and flushes queued events. | 190 // Sets the worker thread id and flushes queued events. |
186 void SetReadyToSendMessagesToWorker(int render_thread_id); | 191 void SetReadyToSendMessagesToWorker(int render_thread_id); |
187 | 192 |
193 // Potential registrations contain all registrations match this document URL. | |
194 void AddPotentialRegistration(ServiceWorkerRegistration* registration); | |
195 void RemovePotentialRegistration(ServiceWorkerRegistration* registration); | |
196 ServiceWorkerRegistration* GetMatchedRegistration() const; | |
dominicc (has gone to gerrit)
2015/02/10 04:10:54
I think it would be helpful to reference https://s
xiang
2015/02/12 07:14:22
Done. It's an optimized impl of the algorithm for
| |
197 | |
188 private: | 198 private: |
189 friend class ServiceWorkerProviderHostTest; | 199 friend class ServiceWorkerProviderHostTest; |
190 friend class ServiceWorkerWriteToCacheJobTest; | 200 friend class ServiceWorkerWriteToCacheJobTest; |
191 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, | 201 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, |
192 UpdateBefore24Hours); | 202 UpdateBefore24Hours); |
193 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, | 203 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, |
194 UpdateAfter24Hours); | 204 UpdateAfter24Hours); |
195 | 205 |
196 // ServiceWorkerRegistration::Listener overrides. | 206 // ServiceWorkerRegistration::Listener overrides. |
207 void OnVersionAttributesChanged( | |
208 ServiceWorkerRegistration* registration, | |
209 ChangedVersionAttributesMask changed_mask, | |
210 const ServiceWorkerRegistrationInfo& info) override; | |
197 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; | 211 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; |
212 void OnRegistrationFinishedUninstalling( | |
213 ServiceWorkerRegistration* registration) override; | |
198 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override; | 214 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override; |
199 | 215 |
200 // Sets the controller version field to |version| or if |version| is NULL, | 216 // Sets the controller version field to |version| or if |version| is NULL, |
201 // clears the field. | 217 // clears the field. |
202 void SetControllerVersionAttribute(ServiceWorkerVersion* version); | 218 void SetControllerVersionAttribute(ServiceWorkerVersion* version); |
203 | 219 |
204 void SendAssociateRegistrationMessage(); | 220 void SendAssociateRegistrationMessage(); |
205 | 221 |
206 // Increase/decrease this host's process reference for |pattern|. | 222 // Increase/decrease this host's process reference for |pattern|. |
207 void IncreaseProcessReference(const GURL& pattern); | 223 void IncreaseProcessReference(const GURL& pattern); |
208 void DecreaseProcessReference(const GURL& pattern); | 224 void DecreaseProcessReference(const GURL& pattern); |
209 | 225 |
226 void ReturnReadyRegistrationIfNeeded(); | |
227 | |
210 bool IsReadyToSendMessages() const; | 228 bool IsReadyToSendMessages() const; |
211 void Send(IPC::Message* message) const; | 229 void Send(IPC::Message* message) const; |
212 | 230 |
213 int render_process_id_; | 231 int render_process_id_; |
214 int render_frame_id_; | 232 int render_frame_id_; |
215 int render_thread_id_; | 233 int render_thread_id_; |
216 int provider_id_; | 234 int provider_id_; |
217 GURL document_url_; | 235 GURL document_url_; |
218 GURL topmost_frame_url_; | 236 GURL topmost_frame_url_; |
219 | 237 |
220 std::vector<GURL> associated_patterns_; | 238 std::vector<GURL> associated_patterns_; |
221 scoped_refptr<ServiceWorkerRegistration> associated_registration_; | 239 scoped_refptr<ServiceWorkerRegistration> associated_registration_; |
222 | 240 |
241 // Keyed by registration scope URL length. | |
242 typedef std::map<size_t, scoped_refptr<ServiceWorkerRegistration>> | |
243 ServiceWorkerRegistrationMap; | |
244 // Contains associated registration and matched registartions created | |
dominicc (has gone to gerrit)
2015/02/10 04:10:53
Spelling: registrations
I think this is too confu
xiang
2015/02/12 07:14:22
Done, I tweaked these comments and names, please t
| |
245 // during the document's lifetime. | |
246 ServiceWorkerRegistrationMap potential_registrations_; | |
247 | |
248 GetReadyRegistrationCallback registration_ready_callback_; | |
223 scoped_refptr<ServiceWorkerVersion> controlling_version_; | 249 scoped_refptr<ServiceWorkerVersion> controlling_version_; |
224 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; | 250 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; |
225 base::WeakPtr<ServiceWorkerContextCore> context_; | 251 base::WeakPtr<ServiceWorkerContextCore> context_; |
226 ServiceWorkerDispatcherHost* dispatcher_host_; | 252 ServiceWorkerDispatcherHost* dispatcher_host_; |
227 bool allow_association_; | 253 bool allow_association_; |
228 bool is_claiming_; | 254 bool is_claiming_; |
229 | 255 |
230 std::vector<base::Closure> queued_events_; | 256 std::vector<base::Closure> queued_events_; |
231 | 257 |
232 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); | 258 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); |
233 }; | 259 }; |
234 | 260 |
235 } // namespace content | 261 } // namespace content |
236 | 262 |
237 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 263 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
OLD | NEW |