| 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/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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 } | 242 } |
| 243 | 243 |
| 244 void ServiceWorkerDispatcherHost::RegisterServiceWorkerRegistrationHandle( | 244 void ServiceWorkerDispatcherHost::RegisterServiceWorkerRegistrationHandle( |
| 245 scoped_ptr<ServiceWorkerRegistrationHandle> handle) { | 245 scoped_ptr<ServiceWorkerRegistrationHandle> handle) { |
| 246 int handle_id = handle->handle_id(); | 246 int handle_id = handle->handle_id(); |
| 247 registration_handles_.AddWithID(handle.release(), handle_id); | 247 registration_handles_.AddWithID(handle.release(), handle_id); |
| 248 } | 248 } |
| 249 | 249 |
| 250 ServiceWorkerHandle* ServiceWorkerDispatcherHost::FindServiceWorkerHandle( | 250 ServiceWorkerHandle* ServiceWorkerDispatcherHost::FindServiceWorkerHandle( |
| 251 int provider_id, | 251 int provider_id, |
| 252 int64 version_id) { | 252 std::string version_uuid) { |
| 253 for (IDMap<ServiceWorkerHandle, IDMapOwnPointer>::iterator iter(&handles_); | 253 for (IDMap<ServiceWorkerHandle, IDMapOwnPointer>::iterator iter(&handles_); |
| 254 !iter.IsAtEnd(); iter.Advance()) { | 254 !iter.IsAtEnd(); iter.Advance()) { |
| 255 ServiceWorkerHandle* handle = iter.GetCurrentValue(); | 255 ServiceWorkerHandle* handle = iter.GetCurrentValue(); |
| 256 DCHECK(handle); | 256 DCHECK(handle); |
| 257 DCHECK(handle->version()); | 257 DCHECK(handle->version()); |
| 258 if (handle->provider_id() == provider_id && | 258 if (handle->provider_id() == provider_id && |
| 259 handle->version()->version_id() == version_id) { | 259 handle->version()->version_uuid().compare(version_uuid) == 0) { |
| 260 return handle; | 260 return handle; |
| 261 } | 261 } |
| 262 } | 262 } |
| 263 return NULL; | 263 return NULL; |
| 264 } | 264 } |
| 265 | 265 |
| 266 ServiceWorkerRegistrationHandle* | 266 ServiceWorkerRegistrationHandle* |
| 267 ServiceWorkerDispatcherHost::GetOrCreateRegistrationHandle( | 267 ServiceWorkerDispatcherHost::GetOrCreateRegistrationHandle( |
| 268 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 268 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 269 ServiceWorkerRegistration* registration) { | 269 ServiceWorkerRegistration* registration) { |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 return; | 727 return; |
| 728 if (!GetContext()->GetProviderHost(render_process_id_, provider_id)) { | 728 if (!GetContext()->GetProviderHost(render_process_id_, provider_id)) { |
| 729 bad_message::ReceivedBadMessage( | 729 bad_message::ReceivedBadMessage( |
| 730 this, bad_message::SWDH_PROVIDER_DESTROYED_NO_HOST); | 730 this, bad_message::SWDH_PROVIDER_DESTROYED_NO_HOST); |
| 731 return; | 731 return; |
| 732 } | 732 } |
| 733 GetContext()->RemoveProviderHost(render_process_id_, provider_id); | 733 GetContext()->RemoveProviderHost(render_process_id_, provider_id); |
| 734 } | 734 } |
| 735 | 735 |
| 736 void ServiceWorkerDispatcherHost::OnSetHostedVersionId( | 736 void ServiceWorkerDispatcherHost::OnSetHostedVersionId( |
| 737 int provider_id, int64 version_id) { | 737 int provider_id, |
| 738 std::string version_uuid) { |
| 738 TRACE_EVENT0("ServiceWorker", | 739 TRACE_EVENT0("ServiceWorker", |
| 739 "ServiceWorkerDispatcherHost::OnSetHostedVersionId"); | 740 "ServiceWorkerDispatcherHost::OnSetHostedVersionId"); |
| 740 if (!GetContext()) | 741 if (!GetContext()) |
| 741 return; | 742 return; |
| 742 ServiceWorkerProviderHost* provider_host = | 743 ServiceWorkerProviderHost* provider_host = |
| 743 GetContext()->GetProviderHost(render_process_id_, provider_id); | 744 GetContext()->GetProviderHost(render_process_id_, provider_id); |
| 744 if (!provider_host) { | 745 if (!provider_host) { |
| 745 bad_message::ReceivedBadMessage( | 746 bad_message::ReceivedBadMessage( |
| 746 this, bad_message::SWDH_SET_HOSTED_VERSION_NO_HOST); | 747 this, bad_message::SWDH_SET_HOSTED_VERSION_NO_HOST); |
| 747 return; | 748 return; |
| 748 } | 749 } |
| 749 if (!provider_host->IsContextAlive()) | 750 if (!provider_host->IsContextAlive()) |
| 750 return; | 751 return; |
| 751 if (!provider_host->SetHostedVersionId(version_id)) | 752 if (!provider_host->SetHostedVersionId(version_uuid)) |
| 752 bad_message::ReceivedBadMessage(this, bad_message::SWDH_SET_HOSTED_VERSION); | 753 bad_message::ReceivedBadMessage(this, bad_message::SWDH_SET_HOSTED_VERSION); |
| 753 | 754 |
| 754 ServiceWorkerVersion* version = GetContext()->GetLiveVersion(version_id); | 755 ServiceWorkerVersion* version = GetContext()->GetLiveVersion(version_uuid); |
| 755 if (!version) | 756 if (!version) |
| 756 return; | 757 return; |
| 757 | 758 |
| 758 // Retrieve the registration associated with |version|. The registration | 759 // Retrieve the registration associated with |version|. The registration |
| 759 // must be alive because the version keeps it during starting worker. | 760 // must be alive because the version keeps it during starting worker. |
| 760 ServiceWorkerRegistration* registration = | 761 ServiceWorkerRegistration* registration = |
| 761 GetContext()->GetLiveRegistration(version->registration_id()); | 762 GetContext()->GetLiveRegistration(version->registration_id()); |
| 762 DCHECK(registration); | 763 DCHECK(registration); |
| 763 // TODO(ksakamoto): This is a quick fix for crbug.com/459916. | 764 // TODO(ksakamoto): This is a quick fix for crbug.com/459916. |
| 764 if (!registration) | 765 if (!registration) |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1228 if (!handle) { | 1229 if (!handle) { |
| 1229 bad_message::ReceivedBadMessage(this, | 1230 bad_message::ReceivedBadMessage(this, |
| 1230 bad_message::SWDH_TERMINATE_BAD_HANDLE); | 1231 bad_message::SWDH_TERMINATE_BAD_HANDLE); |
| 1231 return; | 1232 return; |
| 1232 } | 1233 } |
| 1233 handle->version()->StopWorker( | 1234 handle->version()->StopWorker( |
| 1234 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 1235 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 1235 } | 1236 } |
| 1236 | 1237 |
| 1237 } // namespace content | 1238 } // namespace content |
| OLD | NEW |