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

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

Issue 1175823002: ServiceWorker: Implement ServiceWorkerRegistration.update() (2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: trivial fix Created 5 years, 6 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_dispatcher_host.h" 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/profiler/scoped_tracker.h" 8 #include "base/profiler/scoped_tracker.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 void ServiceWorkerDispatcherHost::OnDestruct() const { 151 void ServiceWorkerDispatcherHost::OnDestruct() const {
152 BrowserThread::DeleteOnIOThread::Destruct(this); 152 BrowserThread::DeleteOnIOThread::Destruct(this);
153 } 153 }
154 154
155 bool ServiceWorkerDispatcherHost::OnMessageReceived( 155 bool ServiceWorkerDispatcherHost::OnMessageReceived(
156 const IPC::Message& message) { 156 const IPC::Message& message) {
157 bool handled = true; 157 bool handled = true;
158 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message) 158 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message)
159 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, 159 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker,
160 OnRegisterServiceWorker) 160 OnRegisterServiceWorker)
161 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UpdateServiceWorker,
162 OnUpdateServiceWorker)
161 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, 163 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker,
162 OnUnregisterServiceWorker) 164 OnUnregisterServiceWorker)
163 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration, 165 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration,
164 OnGetRegistration) 166 OnGetRegistration)
165 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrationForReady, 167 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrationForReady,
166 OnGetRegistrationForReady) 168 OnGetRegistrationForReady)
167 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated, 169 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated,
168 OnProviderCreated) 170 OnProviderCreated)
169 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed, 171 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed,
170 OnProviderDestroyed) 172 OnProviderDestroyed)
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 pattern, 353 pattern,
352 script_url, 354 script_url,
353 provider_host, 355 provider_host,
354 base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete, 356 base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete,
355 this, 357 this,
356 thread_id, 358 thread_id,
357 provider_id, 359 provider_id,
358 request_id)); 360 request_id));
359 } 361 }
360 362
363 void ServiceWorkerDispatcherHost::OnUpdateServiceWorker(int provider_id,
364 int64 registration_id) {
365 TRACE_EVENT0("ServiceWorker",
366 "ServiceWorkerDispatcherHost::OnUpdateServiceWorker");
367 if (!GetContext())
368 return;
369
370 ServiceWorkerProviderHost* provider_host =
371 GetContext()->GetProviderHost(render_process_id_, provider_id);
372 if (!provider_host) {
373 bad_message::ReceivedBadMessage(this, bad_message::SWDH_UPDATE_NO_HOST);
374 return;
375 }
376 if (!provider_host->IsContextAlive())
377 return;
378
379 // TODO(ksakamoto): This check can be removed once crbug.com/439697 is fixed.
380 if (provider_host->document_url().is_empty())
381 return;
382
383 if (!OriginCanAccessServiceWorkers(provider_host->document_url())) {
kinuko 2015/06/11 03:50:36 This check's not necessary now?
nhiroki 2015/06/11 05:48:33 Removed.
384 bad_message::ReceivedBadMessage(this, bad_message::SWDH_UPDATE_CANNOT);
385 return;
386 }
387
388 if (!GetContentClient()->browser()->AllowServiceWorker(
389 provider_host->document_url(), provider_host->topmost_frame_url(),
390 resource_context_, render_process_id_, provider_host->frame_id())) {
391 return;
392 }
kinuko 2015/06/11 03:50:36 This check's not necessary now?
nhiroki 2015/06/11 05:48:33 Hmm... we may have to respect Cookie setting chang
kinuko 2015/06/11 06:33:05 Um, wasn't really reading the code. Let's keep it.
393
394 GetContext()->storage()->FindRegistrationForId(
395 registration_id, provider_host->document_url().GetOrigin(),
396 base::Bind(&ServiceWorkerDispatcherHost::DidFindRegistrationForUpdate,
397 this));
398 }
399
361 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( 400 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(
362 int thread_id, 401 int thread_id,
363 int request_id, 402 int request_id,
364 int provider_id, 403 int provider_id,
365 const GURL& pattern) { 404 const GURL& pattern) {
366 TRACE_EVENT0("ServiceWorker", 405 TRACE_EVENT0("ServiceWorker",
367 "ServiceWorkerDispatcherHost::OnUnregisterServiceWorker"); 406 "ServiceWorkerDispatcherHost::OnUnregisterServiceWorker");
368 if (!GetContext()) { 407 if (!GetContext()) {
369 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( 408 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
370 thread_id, 409 thread_id,
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 return; 515 return;
477 } 516 }
478 517
479 if (!CanGetRegistration(provider_host->document_url(), document_url)) { 518 if (!CanGetRegistration(provider_host->document_url(), document_url)) {
480 bad_message::ReceivedBadMessage(this, 519 bad_message::ReceivedBadMessage(this,
481 bad_message::SWDH_GET_REGISTRATION_CANNOT); 520 bad_message::SWDH_GET_REGISTRATION_CANNOT);
482 return; 521 return;
483 } 522 }
484 523
485 if (!GetContentClient()->browser()->AllowServiceWorker( 524 if (!GetContentClient()->browser()->AllowServiceWorker(
486 provider_host->document_url(), provider_host->topmost_frame_url(), 525 provider_host->document_url(), provider_host->topmost_frame_url(),
nhiroki 2015/06/11 05:48:33 Question (maybe falken@ knows an answer?): Accordi
falken 2015/06/11 06:26:55 Mmm... good question. In practice, in the Chrome b
nhiroki 2015/06/12 08:50:57 Thank you for your reply. Probably I got the point
487 resource_context_, render_process_id_, provider_host->frame_id())) { 526 resource_context_, render_process_id_, provider_host->frame_id())) {
488 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( 527 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError(
489 thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown, 528 thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown,
490 base::ASCIIToUTF16(kServiceWorkerGetRegistrationErrorPrefix) + 529 base::ASCIIToUTF16(kServiceWorkerGetRegistrationErrorPrefix) +
491 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); 530 base::ASCIIToUTF16(kUserDeniedPermissionMessage)));
492 return; 531 return;
493 } 532 }
494 533
495 DCHECK_CURRENTLY_ON(BrowserThread::IO); 534 DCHECK_CURRENTLY_ON(BrowserThread::IO);
496 if (GetContext()->storage()->IsDisabled()) { 535 if (GetContext()->storage()->IsDisabled()) {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 680
642 ServiceWorkerRegistrationObjectInfo info; 681 ServiceWorkerRegistrationObjectInfo info;
643 ServiceWorkerVersionAttributes attrs; 682 ServiceWorkerVersionAttributes attrs;
644 GetRegistrationObjectInfoAndVersionAttributes( 683 GetRegistrationObjectInfoAndVersionAttributes(
645 provider_host->AsWeakPtr(), registration, &info, &attrs); 684 provider_host->AsWeakPtr(), registration, &info, &attrs);
646 685
647 Send(new ServiceWorkerMsg_AssociateRegistrationWithServiceWorker( 686 Send(new ServiceWorkerMsg_AssociateRegistrationWithServiceWorker(
648 kDocumentMainThreadId, provider_id, info, attrs)); 687 kDocumentMainThreadId, provider_id, info, attrs));
649 } 688 }
650 689
690 void ServiceWorkerDispatcherHost::DidFindRegistrationForUpdate(
691 ServiceWorkerStatusCode status,
692 const scoped_refptr<ServiceWorkerRegistration>& registration) {
693 if (status != SERVICE_WORKER_OK)
694 return;
695 if (!GetContext())
696 return;
697 if (!registration->GetNewestVersion()) {
698 // This can happen if update() is called during initial script evaluation.
699 // Abort the following steps according to the spec.
700 return;
701 }
kinuko 2015/06/11 03:50:36 It looks we don't check if the registration's for
nhiroki 2015/06/11 05:48:33 Good point. Added an origin check here.
702 // The spec says, "update() pings the server for an updated version of this
703 // script without consulting caches", so set |force_bypass_cache| to true.
704 GetContext()->UpdateServiceWorker(registration.get(),
705 true /* force_bypass_cache */);
706 }
707
651 ServiceWorkerRegistrationHandle* 708 ServiceWorkerRegistrationHandle*
652 ServiceWorkerDispatcherHost::FindRegistrationHandle(int provider_id, 709 ServiceWorkerDispatcherHost::FindRegistrationHandle(int provider_id,
653 int64 registration_id) { 710 int64 registration_id) {
654 for (IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer>::iterator 711 for (IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer>::iterator
655 iter(&registration_handles_); 712 iter(&registration_handles_);
656 !iter.IsAtEnd(); 713 !iter.IsAtEnd();
657 iter.Advance()) { 714 iter.Advance()) {
658 ServiceWorkerRegistrationHandle* handle = iter.GetCurrentValue(); 715 ServiceWorkerRegistrationHandle* handle = iter.GetCurrentValue();
659 DCHECK(handle); 716 DCHECK(handle);
660 DCHECK(handle->registration()); 717 DCHECK(handle->registration());
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 if (!handle) { 1105 if (!handle) {
1049 bad_message::ReceivedBadMessage(this, 1106 bad_message::ReceivedBadMessage(this,
1050 bad_message::SWDH_TERMINATE_BAD_HANDLE); 1107 bad_message::SWDH_TERMINATE_BAD_HANDLE);
1051 return; 1108 return;
1052 } 1109 }
1053 handle->version()->StopWorker( 1110 handle->version()->StopWorker(
1054 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 1111 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
1055 } 1112 }
1056 1113
1057 } // namespace content 1114 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698