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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 if (!provider_host) { | 308 if (!provider_host) { |
309 BadMessageReceived(); | 309 BadMessageReceived(); |
310 return; | 310 return; |
311 } | 311 } |
312 if (!provider_host->IsContextAlive()) | 312 if (!provider_host->IsContextAlive()) |
313 return; | 313 return; |
314 if (!provider_host->SetHostedVersionId(version_id)) | 314 if (!provider_host->SetHostedVersionId(version_id)) |
315 BadMessageReceived(); | 315 BadMessageReceived(); |
316 } | 316 } |
317 | 317 |
| 318 ServiceWorkerHandle* ServiceWorkerDispatcherHost::FindHandle(int thread_id, |
| 319 int64 version_id) { |
| 320 for (IDMap<ServiceWorkerHandle, IDMapOwnPointer>::iterator iter(&handles_); |
| 321 !iter.IsAtEnd(); |
| 322 iter.Advance()) { |
| 323 ServiceWorkerHandle* handle = iter.GetCurrentValue(); |
| 324 DCHECK(handle); |
| 325 if (handle->thread_id() == thread_id && handle->version() && |
| 326 handle->version()->version_id() == version_id) |
| 327 return handle; |
| 328 } |
| 329 return NULL; |
| 330 } |
| 331 |
318 void ServiceWorkerDispatcherHost::RegistrationComplete( | 332 void ServiceWorkerDispatcherHost::RegistrationComplete( |
319 int thread_id, | 333 int thread_id, |
320 int request_id, | 334 int request_id, |
321 ServiceWorkerStatusCode status, | 335 ServiceWorkerStatusCode status, |
322 int64 registration_id, | 336 int64 registration_id, |
323 int64 version_id) { | 337 int64 version_id) { |
324 if (!GetContext()) | 338 if (!GetContext()) |
325 return; | 339 return; |
326 | 340 |
327 if (status != SERVICE_WORKER_OK) { | 341 if (status != SERVICE_WORKER_OK) { |
328 SendRegistrationError(thread_id, request_id, status); | 342 SendRegistrationError(thread_id, request_id, status); |
329 return; | 343 return; |
330 } | 344 } |
331 | 345 |
332 ServiceWorkerVersion* version = GetContext()->GetLiveVersion(version_id); | 346 ServiceWorkerVersion* version = GetContext()->GetLiveVersion(version_id); |
333 DCHECK(version); | 347 DCHECK(version); |
334 DCHECK_EQ(registration_id, version->registration_id()); | 348 DCHECK_EQ(registration_id, version->registration_id()); |
335 scoped_ptr<ServiceWorkerHandle> handle = | 349 ServiceWorkerObjectInfo info; |
336 ServiceWorkerHandle::Create(GetContext()->AsWeakPtr(), | 350 ServiceWorkerHandle* handle = FindHandle(thread_id, version_id); |
337 this, thread_id, version); | 351 if (handle) { |
| 352 info = handle->GetObjectInfo(); |
| 353 handle->IncrementRefCount(); |
| 354 } else { |
| 355 scoped_ptr<ServiceWorkerHandle> new_handle = ServiceWorkerHandle::Create( |
| 356 GetContext()->AsWeakPtr(), this, thread_id, version); |
| 357 info = new_handle->GetObjectInfo(); |
| 358 RegisterServiceWorkerHandle(new_handle.Pass()); |
| 359 } |
338 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( | 360 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( |
339 thread_id, request_id, handle->GetObjectInfo())); | 361 thread_id, request_id, info)); |
340 RegisterServiceWorkerHandle(handle.Pass()); | |
341 } | 362 } |
342 | 363 |
343 void ServiceWorkerDispatcherHost::OnWorkerScriptLoaded(int embedded_worker_id) { | 364 void ServiceWorkerDispatcherHost::OnWorkerScriptLoaded(int embedded_worker_id) { |
344 if (!GetContext()) | 365 if (!GetContext()) |
345 return; | 366 return; |
346 EmbeddedWorkerRegistry* registry = GetContext()->embedded_worker_registry(); | 367 EmbeddedWorkerRegistry* registry = GetContext()->embedded_worker_registry(); |
347 if (!registry->CanHandle(embedded_worker_id)) | 368 if (!registry->CanHandle(embedded_worker_id)) |
348 return; | 369 return; |
349 registry->OnWorkerScriptLoaded(render_process_id_, embedded_worker_id); | 370 registry->OnWorkerScriptLoaded(render_process_id_, embedded_worker_id); |
350 } | 371 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 status, &error_type, &error_message); | 485 status, &error_type, &error_message); |
465 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 486 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
466 thread_id, request_id, error_type, error_message)); | 487 thread_id, request_id, error_type, error_message)); |
467 } | 488 } |
468 | 489 |
469 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { | 490 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { |
470 return context_wrapper_->context(); | 491 return context_wrapper_->context(); |
471 } | 492 } |
472 | 493 |
473 } // namespace content | 494 } // namespace content |
OLD | NEW |