| Index: content/browser/service_worker/service_worker_dispatcher_host.cc
|
| diff --git a/content/browser/service_worker/service_worker_dispatcher_host.cc b/content/browser/service_worker/service_worker_dispatcher_host.cc
|
| index 4cee0e102e3fbde729fbce0b551fa85555ff1002..4d22d9050fbcca33ecb7bb9b2295065fc7cf0855 100644
|
| --- a/content/browser/service_worker/service_worker_dispatcher_host.cc
|
| +++ b/content/browser/service_worker/service_worker_dispatcher_host.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "content/browser/service_worker/service_worker_dispatcher_host.h"
|
|
|
| +#include "base/stl_util.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "content/browser/service_worker/service_worker_context_core.h"
|
| #include "content/browser/service_worker/service_worker_context_wrapper.h"
|
| @@ -31,10 +32,14 @@ int64 NextWorkerId() {
|
| } // namespace
|
|
|
| ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost(
|
| - int render_process_id) {
|
| + int render_process_id)
|
| + : render_process_id_(render_process_id) {
|
| }
|
|
|
| ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() {
|
| + STLDeleteValues(&providers_);
|
| + if (context_)
|
| + context_->DetachProviderHostMap(render_process_id_);
|
| }
|
|
|
| void ServiceWorkerDispatcherHost::Init(
|
| @@ -47,6 +52,12 @@ void ServiceWorkerDispatcherHost::Init(
|
| return;
|
| }
|
| context_ = context_wrapper->context()->AsWeakPtr();
|
| + if (context_)
|
| + context_->AttachProviderHostMap(render_process_id_, &providers_);
|
| +}
|
| +
|
| +void ServiceWorkerDispatcherHost::OnDestruct() const {
|
| + BrowserThread::DeleteOnIOThread::Destruct(this);
|
| }
|
|
|
| bool ServiceWorkerDispatcherHost::OnMessageReceived(
|
| @@ -62,6 +73,10 @@ bool ServiceWorkerDispatcherHost::OnMessageReceived(
|
| OnRegisterServiceWorker)
|
| IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker,
|
| OnUnregisterServiceWorker)
|
| + IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated,
|
| + OnProviderCreated)
|
| + IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed,
|
| + OnProviderDestroyed)
|
| IPC_MESSAGE_UNHANDLED(handled = false)
|
| IPC_END_MESSAGE_MAP()
|
|
|
| @@ -116,4 +131,27 @@ void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(int32 thread_id,
|
| Send(new ServiceWorkerMsg_ServiceWorkerUnregistered(thread_id, request_id));
|
| }
|
|
|
| +void ServiceWorkerDispatcherHost::OnProviderCreated(int provider_id) {
|
| + DCHECK(!GetProviderHost(provider_id));
|
| + providers_[provider_id] = new ServiceWorkerProviderHost(provider_id);
|
| +}
|
| +
|
| +void ServiceWorkerDispatcherHost::OnProviderDestroyed(int provider_id) {
|
| + ServiceWorkerProviderHostMap::iterator found = providers_.find(provider_id);
|
| + if (found == providers_.end()) {
|
| + BadMessageReceived();
|
| + return;
|
| + }
|
| + delete found->second;
|
| + providers_.erase(found);
|
| +}
|
| +
|
| +ServiceWorkerProviderHost* ServiceWorkerDispatcherHost::GetProviderHost(
|
| + int provider_id) {
|
| + ServiceWorkerProviderHostMap::iterator found = providers_.find(provider_id);
|
| + if (found == providers_.end())
|
| + return NULL;
|
| + return found->second;
|
| +}
|
| +
|
| } // namespace content
|
|
|