| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 return; | 201 return; |
| 202 } | 202 } |
| 203 GetContext()->RegisterServiceWorker( | 203 GetContext()->RegisterServiceWorker( |
| 204 pattern, | 204 pattern, |
| 205 script_url, | 205 script_url, |
| 206 render_process_id_, | 206 render_process_id_, |
| 207 provider_host, | 207 provider_host, |
| 208 base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete, | 208 base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete, |
| 209 this, | 209 this, |
| 210 thread_id, | 210 thread_id, |
| 211 provider_id, |
| 211 request_id)); | 212 request_id)); |
| 212 } | 213 } |
| 213 | 214 |
| 214 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( | 215 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( |
| 215 int thread_id, | 216 int thread_id, |
| 216 int request_id, | 217 int request_id, |
| 217 int provider_id, | 218 int provider_id, |
| 218 const GURL& pattern) { | 219 const GURL& pattern) { |
| 219 if (!GetContext()) { | 220 if (!GetContext()) { |
| 220 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 221 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 if (!provider_host) { | 309 if (!provider_host) { |
| 309 BadMessageReceived(); | 310 BadMessageReceived(); |
| 310 return; | 311 return; |
| 311 } | 312 } |
| 312 if (!provider_host->IsContextAlive()) | 313 if (!provider_host->IsContextAlive()) |
| 313 return; | 314 return; |
| 314 if (!provider_host->SetHostedVersionId(version_id)) | 315 if (!provider_host->SetHostedVersionId(version_id)) |
| 315 BadMessageReceived(); | 316 BadMessageReceived(); |
| 316 } | 317 } |
| 317 | 318 |
| 318 ServiceWorkerHandle* ServiceWorkerDispatcherHost::FindHandle(int thread_id, | 319 ServiceWorkerHandle* ServiceWorkerDispatcherHost::FindHandle(int provider_id, |
| 319 int64 version_id) { | 320 int64 version_id) { |
| 320 for (IDMap<ServiceWorkerHandle, IDMapOwnPointer>::iterator iter(&handles_); | 321 for (IDMap<ServiceWorkerHandle, IDMapOwnPointer>::iterator iter(&handles_); |
| 321 !iter.IsAtEnd(); | 322 !iter.IsAtEnd(); |
| 322 iter.Advance()) { | 323 iter.Advance()) { |
| 323 ServiceWorkerHandle* handle = iter.GetCurrentValue(); | 324 ServiceWorkerHandle* handle = iter.GetCurrentValue(); |
| 324 DCHECK(handle); | 325 DCHECK(handle); |
| 325 if (handle->thread_id() == thread_id && handle->version() && | 326 if (handle->provider_id() == provider_id && handle->version() && |
| 326 handle->version()->version_id() == version_id) | 327 handle->version()->version_id() == version_id) { |
| 327 return handle; | 328 return handle; |
| 329 } |
| 328 } | 330 } |
| 329 return NULL; | 331 return NULL; |
| 330 } | 332 } |
| 331 | 333 |
| 332 void ServiceWorkerDispatcherHost::RegistrationComplete( | 334 void ServiceWorkerDispatcherHost::RegistrationComplete( |
| 333 int thread_id, | 335 int thread_id, |
| 336 int provider_id, |
| 334 int request_id, | 337 int request_id, |
| 335 ServiceWorkerStatusCode status, | 338 ServiceWorkerStatusCode status, |
| 336 int64 registration_id, | 339 int64 registration_id, |
| 337 int64 version_id) { | 340 int64 version_id) { |
| 338 if (!GetContext()) | 341 if (!GetContext()) |
| 339 return; | 342 return; |
| 340 | 343 |
| 341 if (status != SERVICE_WORKER_OK) { | 344 if (status != SERVICE_WORKER_OK) { |
| 342 SendRegistrationError(thread_id, request_id, status); | 345 SendRegistrationError(thread_id, request_id, status); |
| 343 return; | 346 return; |
| 344 } | 347 } |
| 345 | 348 |
| 346 ServiceWorkerVersion* version = GetContext()->GetLiveVersion(version_id); | 349 ServiceWorkerVersion* version = GetContext()->GetLiveVersion(version_id); |
| 347 DCHECK(version); | 350 DCHECK(version); |
| 348 DCHECK_EQ(registration_id, version->registration_id()); | 351 DCHECK_EQ(registration_id, version->registration_id()); |
| 349 ServiceWorkerObjectInfo info; | 352 ServiceWorkerObjectInfo info; |
| 350 ServiceWorkerHandle* handle = FindHandle(thread_id, version_id); | 353 ServiceWorkerHandle* handle = FindHandle(provider_id, version_id); |
| 351 if (handle) { | 354 if (handle) { |
| 355 DCHECK_EQ(thread_id, handle->thread_id()); |
| 352 info = handle->GetObjectInfo(); | 356 info = handle->GetObjectInfo(); |
| 353 handle->IncrementRefCount(); | 357 handle->IncrementRefCount(); |
| 354 } else { | 358 } else { |
| 355 scoped_ptr<ServiceWorkerHandle> new_handle = ServiceWorkerHandle::Create( | 359 scoped_ptr<ServiceWorkerHandle> new_handle = ServiceWorkerHandle::Create( |
| 356 GetContext()->AsWeakPtr(), this, thread_id, version); | 360 GetContext()->AsWeakPtr(), this, thread_id, provider_id, version); |
| 357 info = new_handle->GetObjectInfo(); | 361 info = new_handle->GetObjectInfo(); |
| 358 RegisterServiceWorkerHandle(new_handle.Pass()); | 362 RegisterServiceWorkerHandle(new_handle.Pass()); |
| 359 } | 363 } |
| 360 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( | 364 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( |
| 361 thread_id, request_id, info)); | 365 thread_id, request_id, info)); |
| 362 } | 366 } |
| 363 | 367 |
| 364 void ServiceWorkerDispatcherHost::OnWorkerScriptLoaded(int embedded_worker_id) { | 368 void ServiceWorkerDispatcherHost::OnWorkerScriptLoaded(int embedded_worker_id) { |
| 365 if (!GetContext()) | 369 if (!GetContext()) |
| 366 return; | 370 return; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 status, &error_type, &error_message); | 489 status, &error_type, &error_message); |
| 486 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 490 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
| 487 thread_id, request_id, error_type, error_message)); | 491 thread_id, request_id, error_type, error_message)); |
| 488 } | 492 } |
| 489 | 493 |
| 490 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { | 494 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { |
| 491 return context_wrapper_->context(); | 495 return context_wrapper_->context(); |
| 492 } | 496 } |
| 493 | 497 |
| 494 } // namespace content | 498 } // namespace content |
| OLD | NEW |