summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormichaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-22 23:37:08 +0000
committermichaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-22 23:37:08 +0000
commitbc5fd24c67f9d1a590541ce59c9593eacefa0af0 (patch)
treec9cc0fb4652b4fee2c5f001c21e09224ff7be68b
parent429d1d87560b14d603f287a1e4006536f82ed59e (diff)
downloadchromium_src-bc5fd24c67f9d1a590541ce59c9593eacefa0af0.zip
chromium_src-bc5fd24c67f9d1a590541ce59c9593eacefa0af0.tar.gz
chromium_src-bc5fd24c67f9d1a590541ce59c9593eacefa0af0.tar.bz2
More scaffolding, add class ServiceWorkerProviderHost.
BUG=285976 Review URL: https://codereview.chromium.org/70533005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236872 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/service_worker/service_worker_context_core.cc39
-rw-r--r--content/browser/service_worker/service_worker_context_core.h20
-rw-r--r--content/browser/service_worker/service_worker_context_wrapper.h3
-rw-r--r--content/browser/service_worker/service_worker_dispatcher_host.cc36
-rw-r--r--content/browser/service_worker/service_worker_dispatcher_host.h7
-rw-r--r--content/browser/service_worker/service_worker_dispatcher_host_unittest.cc114
-rw-r--r--content/browser/service_worker/service_worker_provider_host.cc19
-rw-r--r--content/browser/service_worker/service_worker_provider_host.h42
-rw-r--r--content/child/service_worker/web_service_worker_provider_impl.cc29
-rw-r--r--content/child/service_worker/web_service_worker_provider_impl.h14
-rw-r--r--content/common/service_worker_messages.h9
-rw-r--r--content/content_browser.gypi2
-rw-r--r--content/renderer/render_frame_impl.cc2
13 files changed, 291 insertions, 45 deletions
diff --git a/content/browser/service_worker/service_worker_context_core.cc b/content/browser/service_worker/service_worker_context_core.cc
index 9cb2cbe..22ae500 100644
--- a/content/browser/service_worker/service_worker_context_core.cc
+++ b/content/browser/service_worker/service_worker_context_core.cc
@@ -6,6 +6,7 @@
#include "base/command_line.h"
#include "base/files/file_path.h"
+#include "content/browser/service_worker/service_worker_provider_host.h"
#include "content/public/common/content_switches.h"
#include "webkit/browser/quota/quota_manager.h"
@@ -26,12 +27,44 @@ ServiceWorkerContextCore::ServiceWorkerContextCore(
path_ = user_data_directory.Append(kServiceWorkerDirectory);
}
+ServiceWorkerContextCore::~ServiceWorkerContextCore() {
+}
+
+ServiceWorkerProviderHost* ServiceWorkerContextCore::GetProviderHost(
+ int process_id, int provider_id) {
+ ProviderMap* map = GetProviderMapForProcess(process_id);
+ if (!map)
+ return NULL;
+ return map->Lookup(provider_id);
+}
+
+void ServiceWorkerContextCore::AddProviderHost(
+ scoped_ptr<ServiceWorkerProviderHost> host) {
+ ServiceWorkerProviderHost* host_ptr = host.release(); // we take ownership
+ ProviderMap* map = GetProviderMapForProcess(host_ptr->process_id());
+ if (!map) {
+ map = new ProviderMap;
+ providers_.AddWithID(map, host_ptr->process_id());
+ }
+ map->AddWithID(host_ptr, host_ptr->provider_id());
+}
+
+void ServiceWorkerContextCore::RemoveProviderHost(
+ int process_id, int provider_id) {
+ ProviderMap* map = GetProviderMapForProcess(process_id);
+ DCHECK(map);
+ map->Remove(provider_id);
+}
+
+void ServiceWorkerContextCore::RemoveAllProviderHostsForProcess(
+ int process_id) {
+ if (providers_.Lookup(process_id))
+ providers_.Remove(process_id);
+}
+
bool ServiceWorkerContextCore::IsEnabled() {
return CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableServiceWorker);
}
-ServiceWorkerContextCore::~ServiceWorkerContextCore() {
-}
-
} // namespace content
diff --git a/content/browser/service_worker/service_worker_context_core.h b/content/browser/service_worker/service_worker_context_core.h
index 3a62977..8d6f442 100644
--- a/content/browser/service_worker/service_worker_context_core.h
+++ b/content/browser/service_worker/service_worker_context_core.h
@@ -6,7 +6,10 @@
#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CORE_H_
#include "base/files/file_path.h"
+#include "base/id_map.h"
+#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
+#include "content/browser/service_worker/service_worker_provider_host.h"
#include "content/common/content_export.h"
namespace base {
@@ -19,6 +22,8 @@ class QuotaManagerProxy;
namespace content {
+class ServiceWorkerProviderHost;
+
// This class manages data associated with service workers.
// The class is single threaded and should only be used on the IO thread.
// In chromium, there is one instance per storagepartition. This class
@@ -33,9 +38,24 @@ class CONTENT_EXPORT ServiceWorkerContextCore
quota::QuotaManagerProxy* quota_manager_proxy);
~ServiceWorkerContextCore();
+ // The context class owns the set of ProviderHosts.
+ ServiceWorkerProviderHost* GetProviderHost(int process_id, int provider_id);
+ void AddProviderHost(scoped_ptr<ServiceWorkerProviderHost> provider_host);
+ void RemoveProviderHost(int process_id, int provider_id);
+ void RemoveAllProviderHostsForProcess(int process_id);
+
+ // Checks the cmdline flag.
bool IsEnabled();
private:
+ typedef IDMap<ServiceWorkerProviderHost, IDMapOwnPointer> ProviderMap;
+ typedef IDMap<ProviderMap, IDMapOwnPointer> ProcessToProviderMap;
+
+ ProviderMap* GetProviderMapForProcess(int process_id) {
+ return providers_.Lookup(process_id);
+ }
+
+ ProcessToProviderMap providers_;
scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_;
base::FilePath path_;
};
diff --git a/content/browser/service_worker/service_worker_context_wrapper.h b/content/browser/service_worker/service_worker_context_wrapper.h
index b48c32d..1b9b652 100644
--- a/content/browser/service_worker/service_worker_context_wrapper.h
+++ b/content/browser/service_worker/service_worker_context_wrapper.h
@@ -9,6 +9,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "content/browser/service_worker/service_worker_context.h"
+#include "content/common/content_export.h"
namespace base {
class FilePath;
@@ -26,7 +27,7 @@ class ServiceWorkerContextCore;
// classes keep references to this class on mutliple threads. The inner core
// instance is strictly single threaded and is not refcounted, the core object
// is what is used internally in the service worker lib.
-class ServiceWorkerContextWrapper
+class CONTENT_EXPORT ServiceWorkerContextWrapper
: NON_EXPORTED_BASE(public ServiceWorkerContext),
public base::RefCountedThreadSafe<ServiceWorkerContextWrapper> {
public:
diff --git a/content/browser/service_worker/service_worker_dispatcher_host.cc b/content/browser/service_worker/service_worker_dispatcher_host.cc
index 4cee0e1..696c5c1 100644
--- a/content/browser/service_worker/service_worker_dispatcher_host.cc
+++ b/content/browser/service_worker/service_worker_dispatcher_host.cc
@@ -7,6 +7,7 @@
#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"
+#include "content/browser/service_worker/service_worker_provider_host.h"
#include "content/common/service_worker_messages.h"
#include "ipc/ipc_message_macros.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerError.h"
@@ -31,10 +32,13 @@ int64 NextWorkerId() {
} // namespace
ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost(
- int render_process_id) {
+ int render_process_id)
+ : render_process_id_(render_process_id) {
}
ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() {
+ if (context_)
+ context_->RemoveAllProviderHostsForProcess(render_process_id_);
}
void ServiceWorkerDispatcherHost::Init(
@@ -49,6 +53,10 @@ void ServiceWorkerDispatcherHost::Init(
context_ = context_wrapper->context()->AsWeakPtr();
}
+void ServiceWorkerDispatcherHost::OnDestruct() const {
+ BrowserThread::DeleteOnIOThread::Destruct(this);
+}
+
bool ServiceWorkerDispatcherHost::OnMessageReceived(
const IPC::Message& message,
bool* message_was_ok) {
@@ -62,6 +70,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 +128,26 @@ void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(int32 thread_id,
Send(new ServiceWorkerMsg_ServiceWorkerUnregistered(thread_id, request_id));
}
+void ServiceWorkerDispatcherHost::OnProviderCreated(int provider_id) {
+ if (!context_)
+ return;
+ if (context_->GetProviderHost(render_process_id_, provider_id)) {
+ BadMessageReceived();
+ return;
+ }
+ scoped_ptr<ServiceWorkerProviderHost> provider_host(
+ new ServiceWorkerProviderHost(render_process_id_, provider_id));
+ context_->AddProviderHost(provider_host.Pass());
+}
+
+void ServiceWorkerDispatcherHost::OnProviderDestroyed(int provider_id) {
+ if (!context_)
+ return;
+ if (!context_->GetProviderHost(render_process_id_, provider_id)) {
+ BadMessageReceived();
+ return;
+ }
+ context_->RemoveProviderHost(render_process_id_, provider_id);
+}
+
} // namespace content
diff --git a/content/browser/service_worker/service_worker_dispatcher_host.h b/content/browser/service_worker/service_worker_dispatcher_host.h
index 48a0a58..bb0abf8 100644
--- a/content/browser/service_worker/service_worker_dispatcher_host.h
+++ b/content/browser/service_worker/service_worker_dispatcher_host.h
@@ -14,6 +14,7 @@ namespace content {
class ServiceWorkerContextCore;
class ServiceWorkerContextWrapper;
+class ServiceWorkerProviderHost;
class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter {
public:
@@ -22,6 +23,7 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter {
void Init(ServiceWorkerContextWrapper* context_wrapper);
// BrowserIOMessageFilter implementation
+ virtual void OnDestruct() const OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& message,
bool* message_was_ok) OVERRIDE;
@@ -29,6 +31,8 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter {
virtual ~ServiceWorkerDispatcherHost();
private:
+ friend class BrowserThread;
+ friend class base::DeleteHelper<ServiceWorkerDispatcherHost>;
friend class TestingServiceWorkerDispatcherHost;
// IPC Message handlers
@@ -39,7 +43,10 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter {
void OnUnregisterServiceWorker(int32 thread_id,
int32 request_id,
const GURL& scope);
+ void OnProviderCreated(int provider_id);
+ void OnProviderDestroyed(int provider_id);
+ int render_process_id_;
base::WeakPtr<ServiceWorkerContextCore> context_;
};
diff --git a/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc b/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc
index ad62568..2276a5a 100644
--- a/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc
+++ b/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc
@@ -6,7 +6,10 @@
#include "base/command_line.h"
#include "base/files/file_path.h"
+#include "base/message_loop/message_loop.h"
+#include "content/browser/browser_thread_impl.h"
#include "content/browser/service_worker/service_worker_context_core.h"
+#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/common/service_worker_messages.h"
#include "content/public/common/content_switches.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -17,25 +20,38 @@ namespace content {
class ServiceWorkerDispatcherHostTest : public testing::Test {
protected:
+ ServiceWorkerDispatcherHostTest()
+ : io_thread_(BrowserThread::IO, &message_loop_) {}
+
virtual void SetUp() {
- context_.reset(new ServiceWorkerContextCore(base::FilePath(), NULL));
+ context_wrapper_ = new ServiceWorkerContextWrapper;
+ context_wrapper_->Init(base::FilePath(), NULL);
}
virtual void TearDown() {
- context_.reset();
+ if (context_wrapper_) {
+ context_wrapper_->Shutdown();
+ context_wrapper_ = NULL;
+ }
}
- scoped_ptr<ServiceWorkerContextCore> context_;
+ ServiceWorkerContextCore* context() { return context_wrapper_->context(); }
+
+ scoped_refptr<ServiceWorkerContextWrapper> context_wrapper_;
+ base::MessageLoopForIO message_loop_;
+ BrowserThreadImpl io_thread_;
};
static const int kRenderProcessId = 1;
class TestingServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost {
public:
- TestingServiceWorkerDispatcherHost(int process_id,
- ServiceWorkerContextCore* context)
- : ServiceWorkerDispatcherHost(process_id) {
- context_ = context->AsWeakPtr();
+ TestingServiceWorkerDispatcherHost(
+ int process_id,
+ ServiceWorkerContextWrapper* context_wrapper)
+ : ServiceWorkerDispatcherHost(process_id),
+ bad_messages_received_count_(0) {
+ Init(context_wrapper);
}
virtual bool Send(IPC::Message* message) OVERRIDE {
@@ -43,7 +59,12 @@ class TestingServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost {
return true;
}
+ virtual void BadMessageReceived() OVERRIDE {
+ ++bad_messages_received_count_;
+ }
+
ScopedVector<IPC::Message> sent_messages_;
+ int bad_messages_received_count_;
protected:
virtual ~TestingServiceWorkerDispatcherHost() {}
@@ -54,17 +75,18 @@ TEST_F(ServiceWorkerDispatcherHostTest, DisabledCausesError) {
switches::kEnableServiceWorker));
scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host =
- new TestingServiceWorkerDispatcherHost(kRenderProcessId, context_.get());
+ new TestingServiceWorkerDispatcherHost(kRenderProcessId,
+ context_wrapper_.get());
bool handled;
dispatcher_host->OnMessageReceived(
ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, GURL(), GURL()),
&handled);
- DCHECK(handled);
+ EXPECT_TRUE(handled);
// TODO(alecflett): Pump the message loop when this becomes async.
- DCHECK_EQ(1UL, dispatcher_host->sent_messages_.size());
- DCHECK_EQ(
+ ASSERT_EQ(1UL, dispatcher_host->sent_messages_.size());
+ EXPECT_EQ(
static_cast<uint32>(ServiceWorkerMsg_ServiceWorkerRegistrationError::ID),
dispatcher_host->sent_messages_[0]->type());
}
@@ -76,17 +98,18 @@ TEST_F(ServiceWorkerDispatcherHostTest, Enabled) {
switches::kEnableServiceWorker);
scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host =
- new TestingServiceWorkerDispatcherHost(kRenderProcessId, context_.get());
+ new TestingServiceWorkerDispatcherHost(kRenderProcessId,
+ context_wrapper_.get());
bool handled;
dispatcher_host->OnMessageReceived(
ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, GURL(), GURL()),
&handled);
- DCHECK(handled);
+ EXPECT_TRUE(handled);
// TODO(alecflett): Pump the message loop when this becomes async.
- DCHECK_EQ(1UL, dispatcher_host->sent_messages_.size());
- DCHECK_EQ(static_cast<uint32>(ServiceWorkerMsg_ServiceWorkerRegistered::ID),
+ ASSERT_EQ(1UL, dispatcher_host->sent_messages_.size());
+ EXPECT_EQ(static_cast<uint32>(ServiceWorkerMsg_ServiceWorkerRegistered::ID),
dispatcher_host->sent_messages_[0]->type());
}
@@ -97,21 +120,72 @@ TEST_F(ServiceWorkerDispatcherHostTest, EarlyContextDeletion) {
switches::kEnableServiceWorker);
scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host =
- new TestingServiceWorkerDispatcherHost(kRenderProcessId, context_.get());
+ new TestingServiceWorkerDispatcherHost(kRenderProcessId,
+ context_wrapper_.get());
- context_.reset();
+ context_wrapper_->Shutdown();
+ context_wrapper_ = NULL;
bool handled;
dispatcher_host->OnMessageReceived(
ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, GURL(), GURL()),
&handled);
- DCHECK(handled);
+ EXPECT_TRUE(handled);
// TODO(alecflett): Pump the message loop when this becomes async.
- DCHECK_EQ(1UL, dispatcher_host->sent_messages_.size());
- DCHECK_EQ(
+ ASSERT_EQ(1UL, dispatcher_host->sent_messages_.size());
+ EXPECT_EQ(
static_cast<uint32>(ServiceWorkerMsg_ServiceWorkerRegistrationError::ID),
dispatcher_host->sent_messages_[0]->type());
}
+TEST_F(ServiceWorkerDispatcherHostTest, ProviderCreatedAndDestroyed) {
+ scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host =
+ new TestingServiceWorkerDispatcherHost(kRenderProcessId,
+ context_wrapper_.get());
+
+ const int kProviderId = 1001; // Test with a value != kRenderProcessId.
+
+ bool handled = false;
+ dispatcher_host->OnMessageReceived(
+ ServiceWorkerHostMsg_ProviderCreated(kProviderId),
+ &handled);
+ EXPECT_TRUE(handled);
+ EXPECT_TRUE(context()->GetProviderHost(kRenderProcessId, kProviderId));
+
+ // Two with the same ID should be seen as a bad message.
+ handled = false;
+ dispatcher_host->OnMessageReceived(
+ ServiceWorkerHostMsg_ProviderCreated(kProviderId),
+ &handled);
+ EXPECT_TRUE(handled);
+ EXPECT_EQ(1, dispatcher_host->bad_messages_received_count_);
+
+ handled = false;
+ dispatcher_host->OnMessageReceived(
+ ServiceWorkerHostMsg_ProviderDestroyed(kProviderId),
+ &handled);
+ EXPECT_TRUE(handled);
+ EXPECT_FALSE(context()->GetProviderHost(kRenderProcessId, kProviderId));
+
+ // Destroying an ID that does not exist warrants a bad message.
+ handled = false;
+ dispatcher_host->OnMessageReceived(
+ ServiceWorkerHostMsg_ProviderDestroyed(kProviderId),
+ &handled);
+ EXPECT_TRUE(handled);
+ EXPECT_EQ(2, dispatcher_host->bad_messages_received_count_);
+
+ // Deletion of the dispatcher_host should cause providers for that
+ // process to get deleted as well.
+ dispatcher_host->OnMessageReceived(
+ ServiceWorkerHostMsg_ProviderCreated(kProviderId),
+ &handled);
+ EXPECT_TRUE(handled);
+ EXPECT_TRUE(context()->GetProviderHost(kRenderProcessId, kProviderId));
+ EXPECT_TRUE(dispatcher_host->HasOneRef());
+ dispatcher_host = NULL;
+ EXPECT_FALSE(context()->GetProviderHost(kRenderProcessId, kProviderId));
+}
+
} // namespace content
diff --git a/content/browser/service_worker/service_worker_provider_host.cc b/content/browser/service_worker/service_worker_provider_host.cc
new file mode 100644
index 0000000..871343b
--- /dev/null
+++ b/content/browser/service_worker/service_worker_provider_host.cc
@@ -0,0 +1,19 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/service_worker/service_worker_provider_host.h"
+
+#include "content/browser/service_worker/service_worker_version.h"
+
+namespace content {
+
+ServiceWorkerProviderHost::ServiceWorkerProviderHost(
+ int process_id, int provider_id)
+ : process_id_(process_id), provider_id_(provider_id) {
+}
+
+ServiceWorkerProviderHost::~ServiceWorkerProviderHost() {
+}
+
+} // namespace content
diff --git a/content/browser/service_worker/service_worker_provider_host.h b/content/browser/service_worker/service_worker_provider_host.h
new file mode 100644
index 0000000..09990b6
--- /dev/null
+++ b/content/browser/service_worker/service_worker_provider_host.h
@@ -0,0 +1,42 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_
+#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_
+
+#include "base/memory/ref_counted.h"
+
+namespace content {
+
+class ServiceWorkerVersion;
+
+// This class is the browser-process representation of a serice worker
+// provider. There is a provider per document and the lifetime of this
+// object is tied to the lifetime of its document in the renderer process.
+// This class holds service worker state this is scoped to an individual
+// document.
+class ServiceWorkerProviderHost {
+ public:
+ ServiceWorkerProviderHost(int process_id,
+ int provider_id);
+ ~ServiceWorkerProviderHost();
+
+ int process_id() const { return process_id_; }
+ int provider_id() const { return provider_id_; }
+
+ // The service worker version that corresponds with navigator.serviceWorker
+ // for our document.
+ ServiceWorkerVersion* associated_version() const {
+ return associated_version_.get();
+ }
+
+ private:
+ const int process_id_;
+ const int provider_id_;
+ scoped_refptr<ServiceWorkerVersion> associated_version_;
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_
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 a951a5e..c259f18 100644
--- a/content/child/service_worker/web_service_worker_provider_impl.cc
+++ b/content/child/service_worker/web_service_worker_provider_impl.cc
@@ -4,29 +4,42 @@
#include "content/child/service_worker/web_service_worker_provider_impl.h"
+#include "base/atomic_sequence_num.h"
#include "base/logging.h"
#include "content/child/child_thread.h"
#include "content/child/service_worker/service_worker_dispatcher.h"
-#include "content/child/service_worker/service_worker_message_filter.h"
#include "content/child/thread_safe_sender.h"
#include "content/common/service_worker_messages.h"
-#include "ipc/ipc_sender.h"
-#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebURL.h"
-using blink::WebString;
using blink::WebURL;
namespace content {
+namespace {
+
+// Must be unique in the child process.
+int GetNextProviderId() {
+ static base::StaticAtomicSequenceNumber sequence;
+ return sequence.GetNext() + 1; // We want to start at 1.
+}
+
+} // namespace
+
WebServiceWorkerProviderImpl::WebServiceWorkerProviderImpl(
ThreadSafeSender* thread_safe_sender,
- ServiceWorkerMessageFilter* message_filter,
- const blink::WebURL& origin,
scoped_ptr<blink::WebServiceWorkerProviderClient> client)
- : thread_safe_sender_(thread_safe_sender), client_(client.Pass()) {}
+ : provider_id_(GetNextProviderId()),
+ thread_safe_sender_(thread_safe_sender),
+ client_(client.Pass()) {
+ thread_safe_sender_->Send(
+ new ServiceWorkerHostMsg_ProviderCreated(provider_id_));
+}
-WebServiceWorkerProviderImpl::~WebServiceWorkerProviderImpl() {}
+WebServiceWorkerProviderImpl::~WebServiceWorkerProviderImpl() {
+ thread_safe_sender_->Send(
+ new ServiceWorkerHostMsg_ProviderDestroyed(provider_id_));
+}
void WebServiceWorkerProviderImpl::registerServiceWorker(
const WebURL& pattern,
diff --git a/content/child/service_worker/web_service_worker_provider_impl.h b/content/child/service_worker/web_service_worker_provider_impl.h
index 29a379f..45fe4ac 100644
--- a/content/child/service_worker/web_service_worker_provider_impl.h
+++ b/content/child/service_worker/web_service_worker_provider_impl.h
@@ -7,35 +7,28 @@
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerProvider.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerProviderClient.h"
-#include "third_party/WebKit/public/web/WebFrame.h"
-#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
namespace blink {
-class WebString;
class WebURL;
}
-namespace IPC {
-class Sender;
-}
-
namespace content {
class ThreadSafeSender;
-class ServiceWorkerMessageFilter;
class WebServiceWorkerProviderImpl
: NON_EXPORTED_BASE(public blink::WebServiceWorkerProvider) {
public:
WebServiceWorkerProviderImpl(
ThreadSafeSender* thread_safe_sender,
- ServiceWorkerMessageFilter* message_filter,
- const blink::WebURL& origin,
scoped_ptr<blink::WebServiceWorkerProviderClient> client);
virtual ~WebServiceWorkerProviderImpl();
+ int provider_id() const { return provider_id_; }
+
virtual void registerServiceWorker(const blink::WebURL& pattern,
const blink::WebURL& script_url,
WebServiceWorkerCallbacks*);
@@ -44,6 +37,7 @@ class WebServiceWorkerProviderImpl
WebServiceWorkerCallbacks*);
private:
+ const int provider_id_;
scoped_refptr<ThreadSafeSender> thread_safe_sender_;
scoped_ptr<blink::WebServiceWorkerProviderClient> client_;
diff --git a/content/common/service_worker_messages.h b/content/common/service_worker_messages.h
index 92c6e90..0e706e9 100644
--- a/content/common/service_worker_messages.h
+++ b/content/common/service_worker_messages.h
@@ -50,3 +50,12 @@ IPC_MESSAGE_CONTROL4(ServiceWorkerMsg_ServiceWorkerRegistrationError,
int32 /* request_id */,
blink::WebServiceWorkerError::ErrorType /* code */,
string16 /* message */)
+
+// Informs the browser of a new ServiceWorkerProvider in the child process,
+// |provider_id| is unique within its child process.
+IPC_MESSAGE_CONTROL1(ServiceWorkerHostMsg_ProviderCreated,
+ int /* provider_id */)
+
+// Informs the browser of a ServiceWorkerProvider being destroyed.
+IPC_MESSAGE_CONTROL1(ServiceWorkerHostMsg_ProviderDestroyed,
+ int /* provider_id */)
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index ba3b63f..4319814 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -1080,6 +1080,8 @@
'browser/service_worker/service_worker_context_wrapper.h',
'browser/service_worker/service_worker_dispatcher_host.cc',
'browser/service_worker/service_worker_dispatcher_host.h',
+ 'browser/service_worker/service_worker_provider_host.cc',
+ 'browser/service_worker/service_worker_provider_host.h',
'browser/service_worker/service_worker_registration.cc',
'browser/service_worker/service_worker_registration.h',
'browser/service_worker/service_worker_version.cc',
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
index 3165905..b2b7373 100644
--- a/content/renderer/render_frame_impl.cc
+++ b/content/renderer/render_frame_impl.cc
@@ -210,8 +210,6 @@ blink::WebServiceWorkerProvider* RenderFrameImpl::createServiceWorkerProvider(
blink::WebServiceWorkerProviderClient* client) {
return new WebServiceWorkerProviderImpl(
ChildThread::current()->thread_safe_sender(),
- ChildThread::current()->service_worker_message_filter(),
- GURL(frame->document().securityOrigin().toString()),
make_scoped_ptr(client));
}