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

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

Issue 1181973004: ServiceWorker: Route unregister() through WebServiceWorkerRegistration for refactoring (2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove ifdef 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 161 }
162 162
163 bool ServiceWorkerDispatcherHost::OnMessageReceived( 163 bool ServiceWorkerDispatcherHost::OnMessageReceived(
164 const IPC::Message& message) { 164 const IPC::Message& message) {
165 bool handled = true; 165 bool handled = true;
166 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message) 166 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message)
167 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, 167 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker,
168 OnRegisterServiceWorker) 168 OnRegisterServiceWorker)
169 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UpdateServiceWorker, 169 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UpdateServiceWorker,
170 OnUpdateServiceWorker) 170 OnUpdateServiceWorker)
171 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_DeprecatedUnregisterServiceWorker,
172 OnDeprecatedUnregisterServiceWorker)
171 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, 173 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker,
172 OnUnregisterServiceWorker) 174 OnUnregisterServiceWorker)
173 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration, 175 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration,
174 OnGetRegistration) 176 OnGetRegistration)
175 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrations, 177 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrations,
176 OnGetRegistrations) 178 OnGetRegistrations)
177 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrationForReady, 179 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrationForReady,
178 OnGetRegistrationForReady) 180 OnGetRegistrationForReady)
179 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated, 181 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated,
180 OnProviderCreated) 182 OnProviderCreated)
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 // Abort the following steps according to the spec. 419 // Abort the following steps according to the spec.
418 return; 420 return;
419 } 421 }
420 422
421 // The spec says, "update() pings the server for an updated version of this 423 // The spec says, "update() pings the server for an updated version of this
422 // script without consulting caches", so set |force_bypass_cache| to true. 424 // script without consulting caches", so set |force_bypass_cache| to true.
423 GetContext()->UpdateServiceWorker(registration, 425 GetContext()->UpdateServiceWorker(registration,
424 true /* force_bypass_cache */); 426 true /* force_bypass_cache */);
425 } 427 }
426 428
427 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( 429 void ServiceWorkerDispatcherHost::OnDeprecatedUnregisterServiceWorker(
428 int thread_id, 430 int thread_id,
429 int request_id, 431 int request_id,
430 int provider_id, 432 int provider_id,
431 const GURL& pattern) { 433 const GURL& pattern) {
432 TRACE_EVENT0("ServiceWorker", 434 TRACE_EVENT0("ServiceWorker",
433 "ServiceWorkerDispatcherHost::OnUnregisterServiceWorker"); 435 "ServiceWorkerDispatcherHost::OnUnregisterServiceWorker");
434 if (!GetContext()) { 436 if (!GetContext()) {
435 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( 437 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
436 thread_id, 438 thread_id,
437 request_id, 439 request_id,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 request_id, 493 request_id,
492 "Pattern", pattern.spec()); 494 "Pattern", pattern.spec());
493 GetContext()->UnregisterServiceWorker( 495 GetContext()->UnregisterServiceWorker(
494 pattern, 496 pattern,
495 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete, 497 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete,
496 this, 498 this,
497 thread_id, 499 thread_id,
498 request_id)); 500 request_id));
499 } 501 }
500 502
503 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(
504 int thread_id,
505 int request_id,
506 int provider_id,
507 int64 registration_id) {
508 TRACE_EVENT0("ServiceWorker",
509 "ServiceWorkerDispatcherHost::OnUnregisterServiceWorker");
510 if (!GetContext()) {
511 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
512 thread_id, request_id, blink::WebServiceWorkerError::ErrorTypeAbort,
513 base::ASCIIToUTF16(kShutdownErrorMessage)));
514 return;
515 }
516
517 ServiceWorkerProviderHost* provider_host =
518 GetContext()->GetProviderHost(render_process_id_, provider_id);
519 if (!provider_host) {
520 bad_message::ReceivedBadMessage(this, bad_message::SWDH_UNREGISTER_NO_HOST);
521 return;
522 }
523 if (!provider_host->IsContextAlive()) {
524 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
525 thread_id, request_id, blink::WebServiceWorkerError::ErrorTypeAbort,
526 base::ASCIIToUTF16(kShutdownErrorMessage)));
527 return;
528 }
529
530 // TODO(ksakamoto): This check can be removed once crbug.com/439697 is fixed.
531 if (provider_host->document_url().is_empty()) {
532 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
533 thread_id, request_id, WebServiceWorkerError::ErrorTypeSecurity,
534 base::ASCIIToUTF16(kNoDocumentURLErrorMessage)));
535 return;
536 }
537
538 ServiceWorkerRegistration* registration =
539 GetContext()->GetLiveRegistration(registration_id);
540 if (!registration) {
541 // |registration| must be alive because a renderer retains a registration
542 // reference at this point.
543 bad_message::ReceivedBadMessage(
544 this, bad_message::SWDH_UNREGISTER_BAD_REGISTRATION_ID);
545 return;
546 }
547
548 if (!CanUnregisterServiceWorker(provider_host->document_url(),
549 registration->pattern())) {
550 bad_message::ReceivedBadMessage(this, bad_message::SWDH_UNREGISTER_CANNOT);
551 return;
552 }
553
554 if (!GetContentClient()->browser()->AllowServiceWorker(
555 registration->pattern(), provider_host->topmost_frame_url(),
556 resource_context_, render_process_id_, provider_host->frame_id())) {
557 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
558 thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown,
559 base::ASCIIToUTF16(kUserDeniedPermissionMessage)));
560 return;
561 }
562
563 TRACE_EVENT_ASYNC_BEGIN1(
564 "ServiceWorker", "ServiceWorkerDispatcherHost::UnregisterServiceWorker",
565 request_id, "Pattern", registration->pattern().spec());
566 GetContext()->UnregisterServiceWorker(
567 registration->pattern(),
568 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete, this,
569 thread_id, request_id));
570 }
571
501 void ServiceWorkerDispatcherHost::OnGetRegistration( 572 void ServiceWorkerDispatcherHost::OnGetRegistration(
502 int thread_id, 573 int thread_id,
503 int request_id, 574 int request_id,
504 int provider_id, 575 int provider_id,
505 const GURL& document_url) { 576 const GURL& document_url) {
506 TRACE_EVENT0("ServiceWorker", 577 TRACE_EVENT0("ServiceWorker",
507 "ServiceWorkerDispatcherHost::OnGetRegistration"); 578 "ServiceWorkerDispatcherHost::OnGetRegistration");
508 579
509 DCHECK_CURRENTLY_ON(BrowserThread::IO); 580 DCHECK_CURRENTLY_ON(BrowserThread::IO);
510 581
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 if (!handle) { 1307 if (!handle) {
1237 bad_message::ReceivedBadMessage(this, 1308 bad_message::ReceivedBadMessage(this,
1238 bad_message::SWDH_TERMINATE_BAD_HANDLE); 1309 bad_message::SWDH_TERMINATE_BAD_HANDLE);
1239 return; 1310 return;
1240 } 1311 }
1241 handle->version()->StopWorker( 1312 handle->version()->StopWorker(
1242 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 1313 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
1243 } 1314 }
1244 1315
1245 } // namespace content 1316 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698