Commit fac8e63e authored by Han Leon's avatar Han Leon Committed by Commit Bot

[ServiceWorker] Eliminate ServiceWorkerDispatcherHost::resource_context_

This CL lets ServiceWorkerProviderHost get the resource context from
ServiceWorkerContextWrapper directly, rather than getting from
ServiceWorkerDispatcherHost, then we no longer need to keep a resource
context in each ServiceWorkerDispatcherHost.

BUG=845341

Change-Id: Ia6dd603055607b3e2d53f5bbc7d5095c9514f954
Reviewed-on: https://chromium-review.googlesource.com/1068268Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Commit-Queue: Han Leon <leon.han@intel.com>
Cr-Commit-Position: refs/heads/master@{#561401}
parent 044d3d63
...@@ -1838,8 +1838,8 @@ void RenderProcessHostImpl::CreateMessageFilters() { ...@@ -1838,8 +1838,8 @@ void RenderProcessHostImpl::CreateMessageFilters() {
AddFilter(new TextInputClientMessageFilter()); AddFilter(new TextInputClientMessageFilter());
#endif #endif
scoped_refptr<ServiceWorkerDispatcherHost> service_worker_filter = auto service_worker_filter =
new ServiceWorkerDispatcherHost(GetID(), resource_context); base::MakeRefCounted<ServiceWorkerDispatcherHost>(GetID());
service_worker_filter->Init( service_worker_filter->Init(
storage_partition_impl_->GetServiceWorkerContext()); storage_partition_impl_->GetServiceWorkerContext());
AddFilter(service_worker_filter.get()); AddFilter(service_worker_filter.get());
......
...@@ -44,11 +44,8 @@ namespace { ...@@ -44,11 +44,8 @@ namespace {
class MockServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost { class MockServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost {
public: public:
MockServiceWorkerDispatcherHost(int process_id, MockServiceWorkerDispatcherHost(int process_id, IPC::Sender* sender)
ResourceContext* resource_context, : ServiceWorkerDispatcherHost(process_id), sender_(sender) {}
IPC::Sender* sender)
: ServiceWorkerDispatcherHost(process_id, resource_context),
sender_(sender) {}
bool Send(IPC::Message* message) override { return sender_->Send(message); } bool Send(IPC::Message* message) override { return sender_->Send(message); }
...@@ -491,8 +488,8 @@ void EmbeddedWorkerTestHelper::RegisterDispatcherHost( ...@@ -491,8 +488,8 @@ void EmbeddedWorkerTestHelper::RegisterDispatcherHost(
void EmbeddedWorkerTestHelper::EnsureDispatcherHostForProcess(int process_id) { void EmbeddedWorkerTestHelper::EnsureDispatcherHostForProcess(int process_id) {
if (context()->GetDispatcherHost(process_id)) if (context()->GetDispatcherHost(process_id))
return; return;
auto dispatcher_host = base::MakeRefCounted<MockServiceWorkerDispatcherHost>( auto dispatcher_host =
process_id, browser_context_->GetResourceContext(), this); base::MakeRefCounted<MockServiceWorkerDispatcherHost>(process_id, this);
dispatcher_host->Init(wrapper_.get()); dispatcher_host->Init(wrapper_.get());
RegisterDispatcherHost(process_id, std::move(dispatcher_host)); RegisterDispatcherHost(process_id, std::move(dispatcher_host));
} }
......
...@@ -50,15 +50,12 @@ const uint32_t kServiceWorkerFilteredMessageClasses[] = { ...@@ -50,15 +50,12 @@ const uint32_t kServiceWorkerFilteredMessageClasses[] = {
} // namespace } // namespace
ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost(int render_process_id)
int render_process_id,
ResourceContext* resource_context)
: BrowserMessageFilter(kServiceWorkerFilteredMessageClasses, : BrowserMessageFilter(kServiceWorkerFilteredMessageClasses,
arraysize(kServiceWorkerFilteredMessageClasses)), arraysize(kServiceWorkerFilteredMessageClasses)),
BrowserAssociatedInterface<mojom::ServiceWorkerDispatcherHost>(this, BrowserAssociatedInterface<mojom::ServiceWorkerDispatcherHost>(this,
this), this),
render_process_id_(render_process_id), render_process_id_(render_process_id),
resource_context_(resource_context),
weak_ptr_factory_(this) {} weak_ptr_factory_(this) {}
ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() { ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() {
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
namespace content { namespace content {
class ResourceContext;
class ServiceWorkerContextCore; class ServiceWorkerContextCore;
class ServiceWorkerContextWrapper; class ServiceWorkerContextWrapper;
...@@ -66,9 +65,7 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost ...@@ -66,9 +65,7 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost
public BrowserAssociatedInterface<mojom::ServiceWorkerDispatcherHost>, public BrowserAssociatedInterface<mojom::ServiceWorkerDispatcherHost>,
public mojom::ServiceWorkerDispatcherHost { public mojom::ServiceWorkerDispatcherHost {
public: public:
ServiceWorkerDispatcherHost( explicit ServiceWorkerDispatcherHost(int render_process_id);
int render_process_id,
ResourceContext* resource_context);
void Init(ServiceWorkerContextWrapper* context_wrapper); void Init(ServiceWorkerContextWrapper* context_wrapper);
...@@ -77,8 +74,6 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost ...@@ -77,8 +74,6 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost
void OnDestruct() const override; void OnDestruct() const override;
bool OnMessageReceived(const IPC::Message& message) override; bool OnMessageReceived(const IPC::Message& message) override;
ResourceContext* resource_context() { return resource_context_; }
base::WeakPtr<ServiceWorkerDispatcherHost> AsWeakPtr(); base::WeakPtr<ServiceWorkerDispatcherHost> AsWeakPtr();
protected: protected:
...@@ -111,7 +106,6 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost ...@@ -111,7 +106,6 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost
ServiceWorkerContextCore* GetContext(); ServiceWorkerContextCore* GetContext();
const int render_process_id_; const int render_process_id_;
ResourceContext* resource_context_;
// Only accessed on the IO thread. // Only accessed on the IO thread.
Phase phase_ = Phase::kInitial; Phase phase_ = Phase::kInitial;
// Only accessed on the IO thread. // Only accessed on the IO thread.
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "content/common/service_worker/service_worker_utils.h" #include "content/common/service_worker/service_worker_utils.h"
#include "content/public/common/browser_side_navigation_policy.h" #include "content/public/common/browser_side_navigation_policy.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/test/mock_resource_context.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/service_worker/service_worker.mojom.h" #include "third_party/blink/public/mojom/service_worker/service_worker.mojom.h"
...@@ -87,9 +86,8 @@ std::unique_ptr<ServiceWorkerNavigationHandleCore> CreateNavigationHandleCore( ...@@ -87,9 +86,8 @@ std::unique_ptr<ServiceWorkerNavigationHandleCore> CreateNavigationHandleCore(
class TestingServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost { class TestingServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost {
public: public:
TestingServiceWorkerDispatcherHost(int process_id, TestingServiceWorkerDispatcherHost(int process_id,
ResourceContext* resource_context,
EmbeddedWorkerTestHelper* helper) EmbeddedWorkerTestHelper* helper)
: ServiceWorkerDispatcherHost(process_id, resource_context), : ServiceWorkerDispatcherHost(process_id),
bad_messages_received_count_(0), bad_messages_received_count_(0),
helper_(helper) {} helper_(helper) {}
...@@ -130,8 +128,8 @@ class ServiceWorkerDispatcherHostTest : public testing::Test { ...@@ -130,8 +128,8 @@ class ServiceWorkerDispatcherHostTest : public testing::Test {
helper_.reset(helper.release()); helper_.reset(helper.release());
// Replace the default dispatcher host. // Replace the default dispatcher host.
int process_id = helper_->mock_render_process_id(); int process_id = helper_->mock_render_process_id();
dispatcher_host_ = new TestingServiceWorkerDispatcherHost( dispatcher_host_ =
process_id, &resource_context_, helper_.get()); new TestingServiceWorkerDispatcherHost(process_id, helper_.get());
helper_->RegisterDispatcherHost(process_id, nullptr); helper_->RegisterDispatcherHost(process_id, nullptr);
dispatcher_host_->Init(context_wrapper()); dispatcher_host_->Init(context_wrapper());
} }
...@@ -179,7 +177,6 @@ class ServiceWorkerDispatcherHostTest : public testing::Test { ...@@ -179,7 +177,6 @@ class ServiceWorkerDispatcherHostTest : public testing::Test {
} }
TestBrowserThreadBundle browser_thread_bundle_; TestBrowserThreadBundle browser_thread_bundle_;
content::MockResourceContext resource_context_;
std::unique_ptr<EmbeddedWorkerTestHelper> helper_; std::unique_ptr<EmbeddedWorkerTestHelper> helper_;
scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_; scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_;
scoped_refptr<ServiceWorkerRegistration> registration_; scoped_refptr<ServiceWorkerRegistration> registration_;
...@@ -285,9 +282,9 @@ TEST_F(ServiceWorkerDispatcherHostTest, CleanupOnRendererCrash) { ...@@ -285,9 +282,9 @@ TEST_F(ServiceWorkerDispatcherHostTest, CleanupOnRendererCrash) {
// We should be able to hook up a new dispatcher host although the old object // We should be able to hook up a new dispatcher host although the old object
// is not yet destroyed. This is what the browser does when reusing a crashed // is not yet destroyed. This is what the browser does when reusing a crashed
// render process. // render process.
scoped_refptr<TestingServiceWorkerDispatcherHost> new_dispatcher_host( auto new_dispatcher_host =
new TestingServiceWorkerDispatcherHost(process_id, &resource_context_, base::MakeRefCounted<TestingServiceWorkerDispatcherHost>(process_id,
helper_.get())); helper_.get());
new_dispatcher_host->Init(context_wrapper()); new_dispatcher_host->Init(context_wrapper());
// To show the new dispatcher can operate, simulate provider creation. Since // To show the new dispatcher can operate, simulate provider creation. Since
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "content/common/service_worker/service_worker_types.h" #include "content/common/service_worker/service_worker_types.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/test/mock_resource_context.h"
#include "content/public/test/test_browser_context.h" #include "content/public/test/test_browser_context.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_renderer_host.h" #include "content/public/test/test_renderer_host.h"
...@@ -121,8 +120,8 @@ class ServiceWorkerHandleTest : public testing::Test { ...@@ -121,8 +120,8 @@ class ServiceWorkerHandleTest : public testing::Test {
void Initialize(std::unique_ptr<EmbeddedWorkerTestHelper> helper) { void Initialize(std::unique_ptr<EmbeddedWorkerTestHelper> helper) {
helper_ = std::move(helper); helper_ = std::move(helper);
dispatcher_host_ = new ServiceWorkerDispatcherHost( dispatcher_host_ = base::MakeRefCounted<ServiceWorkerDispatcherHost>(
helper_->mock_render_process_id(), &resource_context_); helper_->mock_render_process_id());
helper_->RegisterDispatcherHost(helper_->mock_render_process_id(), helper_->RegisterDispatcherHost(helper_->mock_render_process_id(),
dispatcher_host_); dispatcher_host_);
dispatcher_host_->Init(helper_->context_wrapper()); dispatcher_host_->Init(helper_->context_wrapper());
...@@ -214,7 +213,6 @@ class ServiceWorkerHandleTest : public testing::Test { ...@@ -214,7 +213,6 @@ class ServiceWorkerHandleTest : public testing::Test {
} }
TestBrowserThreadBundle browser_thread_bundle_; TestBrowserThreadBundle browser_thread_bundle_;
MockResourceContext resource_context_;
base::SimpleTestTickClock tick_clock_; base::SimpleTestTickClock tick_clock_;
std::unique_ptr<EmbeddedWorkerTestHelper> helper_; std::unique_ptr<EmbeddedWorkerTestHelper> helper_;
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "content/browser/service_worker/service_worker_consts.h" #include "content/browser/service_worker/service_worker_consts.h"
#include "content/browser/service_worker/service_worker_context_core.h" #include "content/browser/service_worker/service_worker_context_core.h"
#include "content/browser/service_worker/service_worker_context_request_handler.h" #include "content/browser/service_worker/service_worker_context_request_handler.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_controllee_request_handler.h" #include "content/browser/service_worker/service_worker_controllee_request_handler.h"
#include "content/browser/service_worker/service_worker_dispatcher_host.h" #include "content/browser/service_worker/service_worker_dispatcher_host.h"
#include "content/browser/service_worker/service_worker_registration_object_host.h" #include "content/browser/service_worker/service_worker_registration_object_host.h"
...@@ -501,9 +502,10 @@ void ServiceWorkerProviderHost::RemoveServiceWorkerHandle(int64_t version_id) { ...@@ -501,9 +502,10 @@ void ServiceWorkerProviderHost::RemoveServiceWorkerHandle(int64_t version_id) {
} }
bool ServiceWorkerProviderHost::AllowServiceWorker(const GURL& scope) { bool ServiceWorkerProviderHost::AllowServiceWorker(const GURL& scope) {
DCHECK(IsContextAlive());
return GetContentClient()->browser()->AllowServiceWorker( return GetContentClient()->browser()->AllowServiceWorker(
scope, IsProviderForClient() ? topmost_frame_url() : document_url(), scope, IsProviderForClient() ? topmost_frame_url() : document_url(),
dispatcher_host_->resource_context(), context_->wrapper()->resource_context(),
base::Bind(&WebContentsImpl::FromRenderFrameHostID, render_process_id_, base::Bind(&WebContentsImpl::FromRenderFrameHostID, render_process_id_,
frame_id())); frame_id()));
} }
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include "content/browser/service_worker/service_worker_registration_object_host.h" #include "content/browser/service_worker/service_worker_registration_object_host.h"
#include "content/browser/service_worker/service_worker_test_utils.h" #include "content/browser/service_worker/service_worker_test_utils.h"
#include "content/common/service_worker/service_worker_utils.h" #include "content/common/service_worker/service_worker_utils.h"
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "content/test/test_content_browser_client.h" #include "content/test/test_content_browser_client.h"
#include "mojo/edk/embedder/embedder.h" #include "mojo/edk/embedder/embedder.h"
...@@ -272,8 +271,7 @@ TEST_F(ServiceWorkerRegistrationTest, FailedRegistrationNoCrash) { ...@@ -272,8 +271,7 @@ TEST_F(ServiceWorkerRegistrationTest, FailedRegistrationNoCrash) {
auto registration = base::MakeRefCounted<ServiceWorkerRegistration>( auto registration = base::MakeRefCounted<ServiceWorkerRegistration>(
options, kRegistrationId, context()->AsWeakPtr()); options, kRegistrationId, context()->AsWeakPtr());
auto dispatcher_host = base::MakeRefCounted<ServiceWorkerDispatcherHost>( auto dispatcher_host = base::MakeRefCounted<ServiceWorkerDispatcherHost>(
helper_->mock_render_process_id(), helper_->mock_render_process_id());
helper_->browser_context()->GetResourceContext());
// Prepare a ServiceWorkerProviderHost. // Prepare a ServiceWorkerProviderHost.
ServiceWorkerRemoteProviderEndpoint remote_endpoint; ServiceWorkerRemoteProviderEndpoint remote_endpoint;
std::unique_ptr<ServiceWorkerProviderHost> provider_host = std::unique_ptr<ServiceWorkerProviderHost> provider_host =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment