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

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

Issue 463013002: ServiceWorker: Implement updatefound event and version attributes (Chromium) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address for comments Created 6 years, 4 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 | Annotate | Revision Log
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/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "content/browser/message_port_message_filter.h" 9 #include "content/browser/message_port_message_filter.h"
10 #include "content/browser/message_port_service.h" 10 #include "content/browser/message_port_service.h"
11 #include "content/browser/service_worker/embedded_worker_registry.h" 11 #include "content/browser/service_worker/embedded_worker_registry.h"
12 #include "content/browser/service_worker/service_worker_context_core.h" 12 #include "content/browser/service_worker/service_worker_context_core.h"
13 #include "content/browser/service_worker/service_worker_context_wrapper.h" 13 #include "content/browser/service_worker/service_worker_context_wrapper.h"
14 #include "content/browser/service_worker/service_worker_handle.h" 14 #include "content/browser/service_worker/service_worker_handle.h"
15 #include "content/browser/service_worker/service_worker_registration.h" 15 #include "content/browser/service_worker/service_worker_registration.h"
16 #include "content/browser/service_worker/service_worker_registration_handle.h"
16 #include "content/browser/service_worker/service_worker_utils.h" 17 #include "content/browser/service_worker/service_worker_utils.h"
17 #include "content/common/service_worker/embedded_worker_messages.h" 18 #include "content/common/service_worker/embedded_worker_messages.h"
18 #include "content/common/service_worker/service_worker_messages.h" 19 #include "content/common/service_worker/service_worker_messages.h"
19 #include "ipc/ipc_message_macros.h" 20 #include "ipc/ipc_message_macros.h"
20 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" 21 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h"
21 #include "url/gurl.h" 22 #include "url/gurl.h"
22 23
23 using blink::WebServiceWorkerError; 24 using blink::WebServiceWorkerError;
24 25
25 namespace content { 26 namespace content {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_DidPauseAfterDownload, 129 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_DidPauseAfterDownload,
129 OnPausedAfterDownload) 130 OnPausedAfterDownload)
130 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_ReportException, 131 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_ReportException,
131 OnReportException) 132 OnReportException)
132 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_ReportConsoleMessage, 133 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_ReportConsoleMessage,
133 OnReportConsoleMessage) 134 OnReportConsoleMessage)
134 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_IncrementServiceWorkerRefCount, 135 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_IncrementServiceWorkerRefCount,
135 OnIncrementServiceWorkerRefCount) 136 OnIncrementServiceWorkerRefCount)
136 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount, 137 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount,
137 OnDecrementServiceWorkerRefCount) 138 OnDecrementServiceWorkerRefCount)
139 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_IncrementRegistrationRefCount,
140 OnIncrementRegistrationRefCount)
141 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_DecrementRegistrationRefCount,
142 OnDecrementRegistrationRefCount)
138 IPC_MESSAGE_UNHANDLED(handled = false) 143 IPC_MESSAGE_UNHANDLED(handled = false)
139 IPC_END_MESSAGE_MAP() 144 IPC_END_MESSAGE_MAP()
140 145
141 if (!handled && GetContext()) { 146 if (!handled && GetContext()) {
142 handled = 147 handled =
143 GetContext()->embedded_worker_registry()->OnMessageReceived(message); 148 GetContext()->embedded_worker_registry()->OnMessageReceived(message);
144 if (!handled) 149 if (!handled)
145 BadMessageReceived(); 150 BadMessageReceived();
146 } 151 }
147 152
(...skipping 10 matching lines...) Expand all
158 pending_messages_.push_back(message); 163 pending_messages_.push_back(message);
159 return true; 164 return true;
160 } 165 }
161 166
162 void ServiceWorkerDispatcherHost::RegisterServiceWorkerHandle( 167 void ServiceWorkerDispatcherHost::RegisterServiceWorkerHandle(
163 scoped_ptr<ServiceWorkerHandle> handle) { 168 scoped_ptr<ServiceWorkerHandle> handle) {
164 int handle_id = handle->handle_id(); 169 int handle_id = handle->handle_id();
165 handles_.AddWithID(handle.release(), handle_id); 170 handles_.AddWithID(handle.release(), handle_id);
166 } 171 }
167 172
173 void ServiceWorkerDispatcherHost::RegisterServiceWorkerRegistrationHandle(
174 scoped_ptr<ServiceWorkerRegistrationHandle> handle) {
175 int handle_id = handle->handle_id();
176 registration_handles_.AddWithID(handle.release(), handle_id);
177 }
178
168 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( 179 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker(
169 int thread_id, 180 int thread_id,
170 int request_id, 181 int request_id,
171 int provider_id, 182 int provider_id,
172 const GURL& pattern, 183 const GURL& pattern,
173 const GURL& script_url) { 184 const GURL& script_url) {
174 if (!GetContext()) { 185 if (!GetContext()) {
175 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( 186 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
176 thread_id, 187 thread_id,
177 request_id, 188 request_id,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 ServiceWorkerHandle* handle = iter.GetCurrentValue(); 335 ServiceWorkerHandle* handle = iter.GetCurrentValue();
325 DCHECK(handle); 336 DCHECK(handle);
326 if (handle->provider_id() == provider_id && handle->version() && 337 if (handle->provider_id() == provider_id && handle->version() &&
327 handle->version()->version_id() == version_id) { 338 handle->version()->version_id() == version_id) {
328 return handle; 339 return handle;
329 } 340 }
330 } 341 }
331 return NULL; 342 return NULL;
332 } 343 }
333 344
345 ServiceWorkerRegistrationHandle*
346 ServiceWorkerDispatcherHost::FindRegistrationHandle(int provider_id,
347 int64 registration_id) {
348 for (IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer>::iterator
349 iter(&registration_handles_);
350 !iter.IsAtEnd();
351 iter.Advance()) {
352 ServiceWorkerRegistrationHandle* handle = iter.GetCurrentValue();
353 DCHECK(handle);
354 if (handle->provider_id() == provider_id && handle->registration() &&
355 handle->registration()->id() == registration_id) {
356 return handle;
357 }
358 }
359 return NULL;
360 }
361
334 void ServiceWorkerDispatcherHost::RegistrationComplete( 362 void ServiceWorkerDispatcherHost::RegistrationComplete(
335 int thread_id, 363 int thread_id,
336 int provider_id, 364 int provider_id,
337 int request_id, 365 int request_id,
338 ServiceWorkerStatusCode status, 366 ServiceWorkerStatusCode status,
339 int64 registration_id, 367 int64 registration_id,
340 int64 version_id) { 368 int64 version_id) {
341 if (!GetContext()) 369 if (!GetContext())
342 return; 370 return;
343 371
344 if (status != SERVICE_WORKER_OK) { 372 if (status != SERVICE_WORKER_OK) {
345 SendRegistrationError(thread_id, request_id, status); 373 SendRegistrationError(thread_id, request_id, status);
346 return; 374 return;
347 } 375 }
348 376
349 ServiceWorkerVersion* version = GetContext()->GetLiveVersion(version_id); 377 ServiceWorkerVersion* version = GetContext()->GetLiveVersion(version_id);
350 DCHECK(version); 378 DCHECK(version);
351 DCHECK_EQ(registration_id, version->registration_id()); 379 DCHECK_EQ(registration_id, version->registration_id());
352 ServiceWorkerObjectInfo info; 380 ServiceWorkerObjectInfo info;
381
353 ServiceWorkerHandle* handle = FindHandle(provider_id, version_id); 382 ServiceWorkerHandle* handle = FindHandle(provider_id, version_id);
354 if (handle) { 383 if (handle) {
355 DCHECK_EQ(thread_id, handle->thread_id()); 384 DCHECK_EQ(thread_id, handle->thread_id());
356 info = handle->GetObjectInfo(); 385 info = handle->GetObjectInfo();
357 handle->IncrementRefCount(); 386 handle->IncrementRefCount();
358 } else { 387 } else {
359 scoped_ptr<ServiceWorkerHandle> new_handle = ServiceWorkerHandle::Create( 388 scoped_ptr<ServiceWorkerHandle> new_handle = ServiceWorkerHandle::Create(
360 GetContext()->AsWeakPtr(), this, thread_id, provider_id, version); 389 GetContext()->AsWeakPtr(), this, thread_id, provider_id, version);
361 info = new_handle->GetObjectInfo(); 390 info = new_handle->GetObjectInfo();
362 RegisterServiceWorkerHandle(new_handle.Pass()); 391 RegisterServiceWorkerHandle(new_handle.Pass());
363 } 392 }
393
394 ServiceWorkerRegistration* registration =
395 GetContext()->GetLiveRegistration(registration_id);
396 DCHECK(registration);
397
398 ServiceWorkerRegistrationHandle* registration_handle =
399 FindRegistrationHandle(provider_id, registration_id);
400 int registration_handle_id = kInvalidServiceWorkerRegistrationHandleId;
401 if (registration_handle) {
402 registration_handle->IncrementRefCount();
403 registration_handle_id = registration_handle->handle_id();
404 } else {
405 scoped_ptr<ServiceWorkerRegistrationHandle> new_handle(
406 new ServiceWorkerRegistrationHandle(
407 GetContext()->AsWeakPtr(), this, provider_id, registration));
408 registration_handle_id = new_handle->handle_id();
409 RegisterServiceWorkerRegistrationHandle(new_handle.Pass());
410 }
411
364 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( 412 Send(new ServiceWorkerMsg_ServiceWorkerRegistered(
365 thread_id, request_id, info)); 413 thread_id, request_id, registration_handle_id, info));
366 } 414 }
367 415
368 void ServiceWorkerDispatcherHost::OnWorkerScriptLoaded(int embedded_worker_id) { 416 void ServiceWorkerDispatcherHost::OnWorkerScriptLoaded(int embedded_worker_id) {
369 if (!GetContext()) 417 if (!GetContext())
370 return; 418 return;
371 EmbeddedWorkerRegistry* registry = GetContext()->embedded_worker_registry(); 419 EmbeddedWorkerRegistry* registry = GetContext()->embedded_worker_registry();
372 if (!registry->CanHandle(embedded_worker_id)) 420 if (!registry->CanHandle(embedded_worker_id))
373 return; 421 return;
374 registry->OnWorkerScriptLoaded(render_process_id_, embedded_worker_id); 422 registry->OnWorkerScriptLoaded(render_process_id_, embedded_worker_id);
375 } 423 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); 508 ServiceWorkerHandle* handle = handles_.Lookup(handle_id);
461 if (!handle) { 509 if (!handle) {
462 BadMessageReceived(); 510 BadMessageReceived();
463 return; 511 return;
464 } 512 }
465 handle->DecrementRefCount(); 513 handle->DecrementRefCount();
466 if (handle->HasNoRefCount()) 514 if (handle->HasNoRefCount())
467 handles_.Remove(handle_id); 515 handles_.Remove(handle_id);
468 } 516 }
469 517
518 void ServiceWorkerDispatcherHost::OnIncrementRegistrationRefCount(
519 int registration_handle_id) {
520 ServiceWorkerRegistrationHandle* handle =
521 registration_handles_.Lookup(registration_handle_id);
522 if (!handle) {
523 BadMessageReceived();
524 return;
525 }
526 handle->IncrementRefCount();
527 }
528
529 void ServiceWorkerDispatcherHost::OnDecrementRegistrationRefCount(
530 int registration_handle_id) {
531 ServiceWorkerRegistrationHandle* handle =
532 registration_handles_.Lookup(registration_handle_id);
533 if (!handle) {
534 BadMessageReceived();
535 return;
536 }
537 handle->DecrementRefCount();
538 if (handle->HasNoRefCount())
539 registration_handles_.Remove(registration_handle_id);
540 }
541
470 void ServiceWorkerDispatcherHost::UnregistrationComplete( 542 void ServiceWorkerDispatcherHost::UnregistrationComplete(
471 int thread_id, 543 int thread_id,
472 int request_id, 544 int request_id,
473 ServiceWorkerStatusCode status) { 545 ServiceWorkerStatusCode status) {
474 if (status != SERVICE_WORKER_OK) { 546 if (status != SERVICE_WORKER_OK) {
475 SendRegistrationError(thread_id, request_id, status); 547 SendRegistrationError(thread_id, request_id, status);
476 return; 548 return;
477 } 549 }
478 550
479 Send(new ServiceWorkerMsg_ServiceWorkerUnregistered(thread_id, request_id)); 551 Send(new ServiceWorkerMsg_ServiceWorkerUnregistered(thread_id, request_id));
480 } 552 }
481 553
482 void ServiceWorkerDispatcherHost::SendRegistrationError( 554 void ServiceWorkerDispatcherHost::SendRegistrationError(
483 int thread_id, 555 int thread_id,
484 int request_id, 556 int request_id,
485 ServiceWorkerStatusCode status) { 557 ServiceWorkerStatusCode status) {
486 base::string16 error_message; 558 base::string16 error_message;
487 blink::WebServiceWorkerError::ErrorType error_type; 559 blink::WebServiceWorkerError::ErrorType error_type;
488 GetServiceWorkerRegistrationStatusResponse( 560 GetServiceWorkerRegistrationStatusResponse(
489 status, &error_type, &error_message); 561 status, &error_type, &error_message);
490 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( 562 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
491 thread_id, request_id, error_type, error_message)); 563 thread_id, request_id, error_type, error_message));
492 } 564 }
493 565
494 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { 566 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() {
495 return context_wrapper_->context(); 567 return context_wrapper_->context();
496 } 568 }
497 569
498 } // namespace content 570 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698