Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1415)

Unified Diff: content/child/service_worker/service_worker_dispatcher.cc

Issue 261533003: Populate .current when navigator.serviceWorker is accessed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/child/service_worker/service_worker_dispatcher.cc
diff --git a/content/child/service_worker/service_worker_dispatcher.cc b/content/child/service_worker/service_worker_dispatcher.cc
index d8ac46e89ebbaa8cbbbcbb1f53b10fea2e09062d..9e6d7d9a82d7d8dbb1ddf2f3a570377fd6f265c7 100644
--- a/content/child/service_worker/service_worker_dispatcher.cc
+++ b/content/child/service_worker/service_worker_dispatcher.cc
@@ -7,9 +7,11 @@
#include "base/lazy_instance.h"
#include "base/stl_util.h"
#include "base/threading/thread_local.h"
+#include "content/child/service_worker/service_worker_provider_context.h"
#include "content/child/service_worker/web_service_worker_impl.h"
#include "content/child/thread_safe_sender.h"
#include "content/common/service_worker/service_worker_messages.h"
+#include "third_party/WebKit/public/platform/WebServiceWorkerProviderClient.h"
#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
using blink::WebServiceWorkerError;
@@ -39,13 +41,6 @@ ServiceWorkerDispatcher::ServiceWorkerDispatcher(
}
ServiceWorkerDispatcher::~ServiceWorkerDispatcher() {
- for (ScriptClientMap::iterator it = script_clients_.begin();
- it != script_clients_.end();
- ++it) {
- Send(new ServiceWorkerHostMsg_RemoveScriptClient(
- CurrentWorkerId(), it->first));
- }
-
g_dispatcher_tls.Pointer()->Set(kHasBeenDeleted);
}
@@ -91,23 +86,33 @@ void ServiceWorkerDispatcher::UnregisterServiceWorker(
CurrentWorkerId(), request_id, provider_id, pattern));
}
+void ServiceWorkerDispatcher::AddProviderContext(
+ ServiceWorkerProviderContext* provider_context) {
+ DCHECK(provider_context);
+ int provider_id = provider_context->provider_id();
+ DCHECK(!ContainsKey(provider_contexts_, provider_id));
+ provider_contexts_[provider_id] = provider_context;
+}
+
+void ServiceWorkerDispatcher::RemoveProviderContext(
+ ServiceWorkerProviderContext* provider_context) {
+ DCHECK(provider_context);
+ DCHECK(ContainsKey(provider_contexts_, provider_context->provider_id()));
+ provider_contexts_.erase(provider_context->provider_id());
+}
+
void ServiceWorkerDispatcher::AddScriptClient(
int provider_id,
blink::WebServiceWorkerProviderClient* client) {
DCHECK(client);
DCHECK(!ContainsKey(script_clients_, provider_id));
script_clients_[provider_id] = client;
- thread_safe_sender_->Send(new ServiceWorkerHostMsg_AddScriptClient(
- CurrentWorkerId(), provider_id));
}
void ServiceWorkerDispatcher::RemoveScriptClient(int provider_id) {
// This could be possibly called multiple times to ensure termination.
- if (ContainsKey(script_clients_, provider_id)) {
+ if (ContainsKey(script_clients_, provider_id))
script_clients_.erase(provider_id);
- thread_safe_sender_->Send(new ServiceWorkerHostMsg_RemoveScriptClient(
- CurrentWorkerId(), provider_id));
- }
}
ServiceWorkerDispatcher*
@@ -195,16 +200,25 @@ void ServiceWorkerDispatcher::OnServiceWorkerStateChanged(
int thread_id,
int handle_id,
blink::WebServiceWorkerState state) {
- ServiceWorkerMap::iterator found = service_workers_.find(handle_id);
- if (found == service_workers_.end())
- return;
- found->second->OnStateChanged(state);
+ WorkerObjectMap::iterator worker = service_workers_.find(handle_id);
+ if (worker != service_workers_.end())
+ worker->second->OnStateChanged(state);
+
+ WorkerToProviderMap::iterator provider = worker_to_provider_.find(handle_id);
+ if (provider != worker_to_provider_.end())
+ provider->second->OnServiceWorkerStateChanged(thread_id, handle_id, state);
}
void ServiceWorkerDispatcher::OnSetCurrentServiceWorker(
int thread_id,
int provider_id,
const ServiceWorkerObjectInfo& info) {
+ ProviderContextMap::iterator provider = provider_contexts_.find(provider_id);
+ if (provider != provider_contexts_.end()) {
+ provider->second->OnSetCurrentServiceWorker(thread_id, provider_id, info);
+ worker_to_provider_[info.handle_id] = provider->second;
+ }
+
scoped_ptr<WebServiceWorkerImpl> worker(
new WebServiceWorkerImpl(info, thread_safe_sender_));
ScriptClientMap::iterator found = script_clients_.find(provider_id);
@@ -214,8 +228,7 @@ void ServiceWorkerDispatcher::OnSetCurrentServiceWorker(
// created when sending us this message.
return;
}
- // TODO(falken): Call client->setCurrentServiceWorker(worker) when the Blink
- // change to add that function rolls in.
+ found->second->setCurrentServiceWorker(worker.release());
}
void ServiceWorkerDispatcher::AddServiceWorker(

Powered by Google App Engine
This is Rietveld 408576698