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 #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" |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 if (!provider_host) { | 320 if (!provider_host) { |
321 BadMessageReceived(); | 321 BadMessageReceived(); |
322 return; | 322 return; |
323 } | 323 } |
324 if (!provider_host->IsContextAlive()) | 324 if (!provider_host->IsContextAlive()) |
325 return; | 325 return; |
326 if (!provider_host->SetHostedVersionId(version_id)) | 326 if (!provider_host->SetHostedVersionId(version_id)) |
327 BadMessageReceived(); | 327 BadMessageReceived(); |
328 } | 328 } |
329 | 329 |
330 ServiceWorkerHandle* ServiceWorkerDispatcherHost::FindHandle(int provider_id, | |
331 int64 version_id) { | |
332 for (IDMap<ServiceWorkerHandle, IDMapOwnPointer>::iterator iter(&handles_); | |
333 !iter.IsAtEnd(); | |
334 iter.Advance()) { | |
335 ServiceWorkerHandle* handle = iter.GetCurrentValue(); | |
336 DCHECK(handle); | |
337 if (handle->provider_id() == provider_id && handle->version() && | |
338 handle->version()->version_id() == version_id) { | |
339 return handle; | |
340 } | |
341 } | |
342 return NULL; | |
343 } | |
344 | |
345 ServiceWorkerRegistrationHandle* | 330 ServiceWorkerRegistrationHandle* |
346 ServiceWorkerDispatcherHost::FindRegistrationHandle(int provider_id, | 331 ServiceWorkerDispatcherHost::FindRegistrationHandle(int provider_id, |
347 int64 registration_id) { | 332 int64 registration_id) { |
348 for (IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer>::iterator | 333 for (IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer>::iterator |
349 iter(®istration_handles_); | 334 iter(®istration_handles_); |
350 !iter.IsAtEnd(); | 335 !iter.IsAtEnd(); |
351 iter.Advance()) { | 336 iter.Advance()) { |
352 ServiceWorkerRegistrationHandle* handle = iter.GetCurrentValue(); | 337 ServiceWorkerRegistrationHandle* handle = iter.GetCurrentValue(); |
353 DCHECK(handle); | 338 DCHECK(handle); |
354 if (handle->provider_id() == provider_id && handle->registration() && | 339 if (handle->provider_id() == provider_id && handle->registration() && |
(...skipping 12 matching lines...) Expand all Loading... |
367 int64 registration_id, | 352 int64 registration_id, |
368 int64 version_id) { | 353 int64 version_id) { |
369 if (!GetContext()) | 354 if (!GetContext()) |
370 return; | 355 return; |
371 | 356 |
372 if (status != SERVICE_WORKER_OK) { | 357 if (status != SERVICE_WORKER_OK) { |
373 SendRegistrationError(thread_id, request_id, status); | 358 SendRegistrationError(thread_id, request_id, status); |
374 return; | 359 return; |
375 } | 360 } |
376 | 361 |
377 ServiceWorkerVersion* version = GetContext()->GetLiveVersion(version_id); | |
378 DCHECK(version); | |
379 DCHECK_EQ(registration_id, version->registration_id()); | |
380 ServiceWorkerObjectInfo info; | |
381 | |
382 ServiceWorkerHandle* handle = FindHandle(provider_id, version_id); | |
383 if (handle) { | |
384 DCHECK_EQ(thread_id, handle->thread_id()); | |
385 info = handle->GetObjectInfo(); | |
386 handle->IncrementRefCount(); | |
387 } else { | |
388 scoped_ptr<ServiceWorkerHandle> new_handle = ServiceWorkerHandle::Create( | |
389 GetContext()->AsWeakPtr(), this, thread_id, provider_id, version); | |
390 info = new_handle->GetObjectInfo(); | |
391 RegisterServiceWorkerHandle(new_handle.Pass()); | |
392 } | |
393 | |
394 ServiceWorkerRegistration* registration = | 362 ServiceWorkerRegistration* registration = |
395 GetContext()->GetLiveRegistration(registration_id); | 363 GetContext()->GetLiveRegistration(registration_id); |
396 DCHECK(registration); | 364 DCHECK(registration); |
397 | 365 |
398 ServiceWorkerRegistrationHandle* registration_handle = | 366 ServiceWorkerRegistrationHandle* handle = |
399 FindRegistrationHandle(provider_id, registration_id); | 367 FindRegistrationHandle(provider_id, registration_id); |
400 int registration_handle_id = kInvalidServiceWorkerRegistrationHandleId; | 368 ServiceWorkerRegistrationObjectInfo info; |
401 if (registration_handle) { | 369 if (handle) { |
402 registration_handle->IncrementRefCount(); | 370 handle->IncrementRefCount(); |
403 registration_handle_id = registration_handle->handle_id(); | 371 info = handle->GetObjectInfo(); |
404 } else { | 372 } else { |
405 scoped_ptr<ServiceWorkerRegistrationHandle> new_handle( | 373 scoped_ptr<ServiceWorkerRegistrationHandle> new_handle( |
406 new ServiceWorkerRegistrationHandle( | 374 new ServiceWorkerRegistrationHandle( |
407 GetContext()->AsWeakPtr(), this, provider_id, registration)); | 375 GetContext()->AsWeakPtr(), this, provider_id, registration)); |
408 registration_handle_id = new_handle->handle_id(); | 376 info = new_handle->GetObjectInfo(); |
409 RegisterServiceWorkerRegistrationHandle(new_handle.Pass()); | 377 RegisterServiceWorkerRegistrationHandle(new_handle.Pass()); |
410 } | 378 } |
411 | 379 |
412 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( | 380 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( |
413 thread_id, request_id, registration_handle_id, info)); | 381 thread_id, request_id, info)); |
414 } | 382 } |
415 | 383 |
416 void ServiceWorkerDispatcherHost::OnWorkerScriptLoaded(int embedded_worker_id) { | 384 void ServiceWorkerDispatcherHost::OnWorkerScriptLoaded(int embedded_worker_id) { |
417 if (!GetContext()) | 385 if (!GetContext()) |
418 return; | 386 return; |
419 EmbeddedWorkerRegistry* registry = GetContext()->embedded_worker_registry(); | 387 EmbeddedWorkerRegistry* registry = GetContext()->embedded_worker_registry(); |
420 if (!registry->CanHandle(embedded_worker_id)) | 388 if (!registry->CanHandle(embedded_worker_id)) |
421 return; | 389 return; |
422 registry->OnWorkerScriptLoaded(render_process_id_, embedded_worker_id); | 390 registry->OnWorkerScriptLoaded(render_process_id_, embedded_worker_id); |
423 } | 391 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 status, &error_type, &error_message); | 529 status, &error_type, &error_message); |
562 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 530 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
563 thread_id, request_id, error_type, error_message)); | 531 thread_id, request_id, error_type, error_message)); |
564 } | 532 } |
565 | 533 |
566 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { | 534 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { |
567 return context_wrapper_->context(); | 535 return context_wrapper_->context(); |
568 } | 536 } |
569 | 537 |
570 } // namespace content | 538 } // namespace content |
OLD | NEW |