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

Side by Side Diff: content/browser/service_worker/service_worker_provider_host.cc

Issue 825383004: ServiceWorker: Send state change events via SWProviderHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 11 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 #include "content/browser/service_worker/service_worker_provider_host.h" 5 #include "content/browser/service_worker/service_worker_provider_host.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "content/browser/message_port_message_filter.h" 8 #include "content/browser/message_port_message_filter.h"
9 #include "content/browser/service_worker/service_worker_context_core.h" 9 #include "content/browser/service_worker/service_worker_context_core.h"
10 #include "content/browser/service_worker/service_worker_context_request_handler. h" 10 #include "content/browser/service_worker/service_worker_context_request_handler. h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 previous_version->RemoveControllee(this); 114 previous_version->RemoveControllee(this);
115 115
116 if (!dispatcher_host_) 116 if (!dispatcher_host_)
117 return; // Could be NULL in some tests. 117 return; // Could be NULL in some tests.
118 118
119 bool should_notify_controllerchange = 119 bool should_notify_controllerchange =
120 previous_version && version && version->skip_waiting(); 120 previous_version && version && version->skip_waiting();
121 121
122 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker( 122 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker(
123 kDocumentMainThreadId, provider_id(), 123 kDocumentMainThreadId, provider_id(),
124 dispatcher_host_->CreateAndRegisterServiceWorkerHandle(version), 124 CreateAndRegisterServiceWorkerHandle(version),
125 should_notify_controllerchange)); 125 should_notify_controllerchange));
126 } 126 }
127 127
128 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { 128 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) {
129 if (!context_) 129 if (!context_)
130 return true; // System is shutting down. 130 return true; // System is shutting down.
131 if (active_version()) 131 if (active_version())
132 return false; // Unexpected bad message. 132 return false; // Unexpected bad message.
133 133
134 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id); 134 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 request_mode, 197 request_mode,
198 credentials_mode, 198 credentials_mode,
199 resource_type, 199 resource_type,
200 request_context_type, 200 request_context_type,
201 frame_type, 201 frame_type,
202 body)); 202 body));
203 } 203 }
204 return scoped_ptr<ServiceWorkerRequestHandler>(); 204 return scoped_ptr<ServiceWorkerRequestHandler>();
205 } 205 }
206 206
207 ServiceWorkerObjectInfo
208 ServiceWorkerProviderHost::CreateAndRegisterServiceWorkerHandle(
209 ServiceWorkerVersion* version) {
210 DCHECK(dispatcher_host_);
211 ServiceWorkerObjectInfo info;
212 if (context_ && version) {
213 scoped_ptr<ServiceWorkerHandle> handle =
214 ServiceWorkerHandle::Create(context_, AsWeakPtr(), version);
215 info = handle->GetObjectInfo();
216 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass());
217 }
218 return info;
219 }
220
207 bool ServiceWorkerProviderHost::CanAssociateRegistration( 221 bool ServiceWorkerProviderHost::CanAssociateRegistration(
208 ServiceWorkerRegistration* registration) { 222 ServiceWorkerRegistration* registration) {
209 if (!context_) 223 if (!context_)
210 return false; 224 return false;
211 if (running_hosted_version_.get()) 225 if (running_hosted_version_.get())
212 return false; 226 return false;
213 if (!registration || associated_registration_.get() || !allow_association_) 227 if (!registration || associated_registration_.get() || !allow_association_)
214 return false; 228 return false;
215 return true; 229 return true;
216 } 230 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 305
292 for (const GURL& pattern : associated_patterns_) 306 for (const GURL& pattern : associated_patterns_)
293 IncreaseProcessReference(pattern); 307 IncreaseProcessReference(pattern);
294 308
295 if (associated_registration_.get()) { 309 if (associated_registration_.get()) {
296 IncreaseProcessReference(associated_registration_->pattern()); 310 IncreaseProcessReference(associated_registration_->pattern());
297 SendAssociateRegistrationMessage(); 311 SendAssociateRegistrationMessage();
298 if (dispatcher_host_ && associated_registration_->active_version()) { 312 if (dispatcher_host_ && associated_registration_->active_version()) {
299 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker( 313 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker(
300 kDocumentMainThreadId, provider_id(), 314 kDocumentMainThreadId, provider_id(),
301 dispatcher_host_->CreateAndRegisterServiceWorkerHandle( 315 CreateAndRegisterServiceWorkerHandle(
302 associated_registration_->active_version()), 316 associated_registration_->active_version()),
303 false /* shouldNotifyControllerChange */)); 317 false /* shouldNotifyControllerChange */));
304 } 318 }
305 } 319 }
306 } 320 }
307 321
322 void ServiceWorkerProviderHost::SendUpdateFoundMessage(
323 const ServiceWorkerRegistrationObjectInfo& object_info) {
324 if (!dispatcher_host_)
325 return; // Could be nullptr in some tests.
326
327 // TODO(nhiroki): Queue the message if a receiver's thread is not ready yet
328 // (http://crbug.com/437677).
329 dispatcher_host_->Send(new ServiceWorkerMsg_UpdateFound(
330 kDocumentMainThreadId, object_info));
331 }
332
333 void ServiceWorkerProviderHost::SendSetVersionAttributesMessage(
334 int registration_handle_id,
335 ChangedVersionAttributesMask changed_mask,
336 ServiceWorkerVersion* installing_version,
337 ServiceWorkerVersion* waiting_version,
338 ServiceWorkerVersion* active_version) {
339 if (!dispatcher_host_)
340 return; // Could be nullptr in some tests.
341 if (!changed_mask.changed())
342 return;
343
344 ServiceWorkerVersionAttributes attrs;
345 if (changed_mask.installing_changed())
346 attrs.installing = CreateAndRegisterServiceWorkerHandle(installing_version);
347 if (changed_mask.waiting_changed())
348 attrs.waiting = CreateAndRegisterServiceWorkerHandle(waiting_version);
349 if (changed_mask.active_changed())
350 attrs.active = CreateAndRegisterServiceWorkerHandle(active_version);
351
352 // TODO(nhiroki): Queue the message if a receiver's thread is not ready yet
353 // (http://crbug.com/437677).
354 dispatcher_host_->Send(new ServiceWorkerMsg_SetVersionAttributes(
355 kDocumentMainThreadId, provider_id_, registration_handle_id,
356 changed_mask.changed(), attrs));
357 }
358
359 void ServiceWorkerProviderHost::SendServiceWorkerStateChangedMessage(
360 int worker_handle_id,
361 blink::WebServiceWorkerState state) {
362 if (!dispatcher_host_)
363 return;
364
365 // TODO(nhiroki): Queue the message if a receiver's thread is not ready yet
366 // (http://crbug.com/437677).
367 dispatcher_host_->Send(new ServiceWorkerMsg_ServiceWorkerStateChanged(
368 kDocumentMainThreadId, worker_handle_id, state));
369 }
370
308 void ServiceWorkerProviderHost::SendAssociateRegistrationMessage() { 371 void ServiceWorkerProviderHost::SendAssociateRegistrationMessage() {
309 if (!dispatcher_host_) 372 if (!dispatcher_host_)
310 return; 373 return;
311 374
312 ServiceWorkerRegistrationHandle* handle = 375 ServiceWorkerRegistrationHandle* handle =
313 dispatcher_host_->GetOrCreateRegistrationHandle( 376 dispatcher_host_->GetOrCreateRegistrationHandle(
314 provider_id(), associated_registration_.get()); 377 AsWeakPtr(), associated_registration_.get());
315 378
316 ServiceWorkerVersionAttributes attrs; 379 ServiceWorkerVersionAttributes attrs;
317 attrs.installing = dispatcher_host_->CreateAndRegisterServiceWorkerHandle( 380 attrs.installing = CreateAndRegisterServiceWorkerHandle(
318 associated_registration_->installing_version()); 381 associated_registration_->installing_version());
319 attrs.waiting = dispatcher_host_->CreateAndRegisterServiceWorkerHandle( 382 attrs.waiting = CreateAndRegisterServiceWorkerHandle(
320 associated_registration_->waiting_version()); 383 associated_registration_->waiting_version());
321 attrs.active = dispatcher_host_->CreateAndRegisterServiceWorkerHandle( 384 attrs.active = CreateAndRegisterServiceWorkerHandle(
322 associated_registration_->active_version()); 385 associated_registration_->active_version());
323 386
324 dispatcher_host_->Send(new ServiceWorkerMsg_AssociateRegistration( 387 dispatcher_host_->Send(new ServiceWorkerMsg_AssociateRegistration(
325 kDocumentMainThreadId, provider_id(), handle->GetObjectInfo(), attrs)); 388 kDocumentMainThreadId, provider_id(), handle->GetObjectInfo(), attrs));
326 } 389 }
327 390
328 void ServiceWorkerProviderHost::IncreaseProcessReference( 391 void ServiceWorkerProviderHost::IncreaseProcessReference(
329 const GURL& pattern) { 392 const GURL& pattern) {
330 if (context_ && context_->process_manager()) { 393 if (context_ && context_->process_manager()) {
331 context_->process_manager()->AddProcessReferenceToPattern( 394 context_->process_manager()->AddProcessReferenceToPattern(
332 pattern, render_process_id_); 395 pattern, render_process_id_);
333 } 396 }
334 } 397 }
335 398
336 void ServiceWorkerProviderHost::DecreaseProcessReference( 399 void ServiceWorkerProviderHost::DecreaseProcessReference(
337 const GURL& pattern) { 400 const GURL& pattern) {
338 if (context_ && context_->process_manager()) { 401 if (context_ && context_->process_manager()) {
339 context_->process_manager()->RemoveProcessReferenceFromPattern( 402 context_->process_manager()->RemoveProcessReferenceFromPattern(
340 pattern, render_process_id_); 403 pattern, render_process_id_);
341 } 404 }
342 } 405 }
343 406
344 bool ServiceWorkerProviderHost::IsContextAlive() { 407 bool ServiceWorkerProviderHost::IsContextAlive() {
345 return context_ != NULL; 408 return context_ != NULL;
346 } 409 }
347 410
348 } // namespace content 411 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698