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

Unified Diff: content/child/service_worker/web_service_worker_provider_impl.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/web_service_worker_provider_impl.cc
diff --git a/content/child/service_worker/web_service_worker_provider_impl.cc b/content/child/service_worker/web_service_worker_provider_impl.cc
index 99f9738be7af2197237ce89ca02e28f4f594e220..b76ca5b99d239979a58fa1e04ef038793b6169cf 100644
--- a/content/child/service_worker/web_service_worker_provider_impl.cc
+++ b/content/child/service_worker/web_service_worker_provider_impl.cc
@@ -7,19 +7,34 @@
#include "base/atomic_sequence_num.h"
#include "base/logging.h"
#include "content/child/child_thread.h"
+#include "content/child/service_worker/scoped_service_worker_reference.h"
#include "content/child/service_worker/service_worker_dispatcher.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/child/worker_task_runner.h"
+#include "content/common/service_worker/service_worker_messages.h"
+#include "third_party/WebKit/public/platform/WebServiceWorkerProviderClient.h"
#include "third_party/WebKit/public/platform/WebURL.h"
using blink::WebURL;
namespace content {
+namespace {
+
+int CurrentWorkerId() {
+ return WorkerTaskRunner::Instance()->CurrentWorkerId();
+}
+
+} // namespace
+
WebServiceWorkerProviderImpl::WebServiceWorkerProviderImpl(
ThreadSafeSender* thread_safe_sender,
- int provider_id)
+ ServiceWorkerProviderContext* context)
: thread_safe_sender_(thread_safe_sender),
- provider_id_(provider_id) {
+ context_(context),
+ provider_id_(context->provider_id()) {
}
WebServiceWorkerProviderImpl::~WebServiceWorkerProviderImpl() {
@@ -29,10 +44,24 @@ WebServiceWorkerProviderImpl::~WebServiceWorkerProviderImpl() {
void WebServiceWorkerProviderImpl::setClient(
blink::WebServiceWorkerProviderClient* client) {
- if (client)
- GetDispatcher()->AddScriptClient(provider_id_, client);
- else
+ if (!client) {
RemoveScriptClient();
+ return;
+ }
+
+ scoped_ptr<ScopedServiceWorkerReference> current;
+ context_->AddProviderThreadAndGetInitializationInfo(
+ CurrentWorkerId(), &current);
+ GetDispatcher()->AddScriptClient(provider_id_, client);
+ if (!current)
+ return;
+
+ int handle_id = current->info().handle_id;
+ if (handle_id != kInvalidServiceWorkerHandleId) {
+ scoped_ptr<WebServiceWorkerImpl> worker(
+ new WebServiceWorkerImpl(current.Pass(), thread_safe_sender_));
+ client->setCurrentServiceWorker(worker.release());
+ }
}
void WebServiceWorkerProviderImpl::registerServiceWorker(
@@ -57,6 +86,7 @@ void WebServiceWorkerProviderImpl::RemoveScriptClient() {
ServiceWorkerDispatcher::GetThreadSpecificInstance();
if (dispatcher)
dispatcher->RemoveScriptClient(provider_id_);
+ context_->RemoveProviderThread(CurrentWorkerId());
}
ServiceWorkerDispatcher* WebServiceWorkerProviderImpl::GetDispatcher() {

Powered by Google App Engine
This is Rietveld 408576698