Commit 260f1af2 authored by Han Leon's avatar Han Leon Committed by Commit Bot

[ServiceWorker] SWDispatcher does not need main thread task runner

BUG=

Change-Id: I6f579ee57233224dac0b11bff3b3b3d76b1f52f4
Reviewed-on: https://chromium-review.googlesource.com/897402Reviewed-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@{#533622}
parent d3451304
......@@ -902,8 +902,7 @@ void ServiceWorkerContextClient::WorkerContextStarted(
// Set ServiceWorkerGlobalScope#registration.
// TakeRegistrationForServiceWorkerGlobalScope() expects the dispatcher to be
// already created, so create it first.
ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(
sender_.get(), main_thread_task_runner_.get());
ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(sender_.get());
proxy_->SetRegistration(WebServiceWorkerRegistrationImpl::CreateHandle(
provider_context_->TakeRegistrationForServiceWorkerGlobalScope(
io_thread_task_runner_)));
......@@ -1580,8 +1579,7 @@ void ServiceWorkerContextClient::DispatchExtendableMessageEvent(
event->source_info_for_service_worker->version_id !=
blink::mojom::kInvalidServiceWorkerVersionId);
ServiceWorkerDispatcher* dispatcher =
ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(
sender_.get(), main_thread_task_runner_.get());
ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(sender_.get());
scoped_refptr<WebServiceWorkerImpl> worker =
dispatcher->GetOrCreateServiceWorker(
std::move(event->source_info_for_service_worker));
......
......@@ -218,8 +218,7 @@ class ServiceWorkerContextClientTest : public testing::Test {
void TearDown() override {
ServiceWorkerContextClient::ResetThreadSpecificInstanceForTesting();
ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(
sender_, main_task_runner())
ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(sender_)
->AllowReinstantiationForTesting();
// Unregister this thread from worker threads.
WorkerThreadRegistry::Instance()->WillStopCurrentWorkerThread();
......@@ -277,11 +276,6 @@ class ServiceWorkerContextClientTest : public testing::Test {
}
private:
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner() {
// Use this thread as the main thread.
return task_runner_;
}
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner() {
// Use this thread as the IO thread.
return task_runner_;
......
......@@ -10,7 +10,6 @@
#include "base/lazy_instance.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/threading/thread_local.h"
#include "base/threading/thread_task_runner_handle.h"
......@@ -43,10 +42,8 @@ void* const kDeletedServiceWorkerDispatcherMarker =
} // namespace
ServiceWorkerDispatcher::ServiceWorkerDispatcher(
scoped_refptr<ThreadSafeSender> thread_safe_sender,
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner)
: thread_safe_sender_(std::move(thread_safe_sender)),
main_thread_task_runner_(std::move(main_thread_task_runner)) {
scoped_refptr<ThreadSafeSender> thread_safe_sender)
: thread_safe_sender_(std::move(thread_safe_sender)) {
g_dispatcher_tls.Pointer()->Set(static_cast<void*>(this));
}
......@@ -74,8 +71,7 @@ void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) {
ServiceWorkerDispatcher*
ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(
scoped_refptr<ThreadSafeSender> thread_safe_sender,
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) {
scoped_refptr<ThreadSafeSender> thread_safe_sender) {
if (g_dispatcher_tls.Pointer()->Get() ==
kDeletedServiceWorkerDispatcherMarker) {
NOTREACHED() << "Re-instantiating TLS ServiceWorkerDispatcher.";
......@@ -85,8 +81,8 @@ ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(
return static_cast<ServiceWorkerDispatcher*>(
g_dispatcher_tls.Pointer()->Get());
ServiceWorkerDispatcher* dispatcher = new ServiceWorkerDispatcher(
std::move(thread_safe_sender), std::move(main_thread_task_runner));
ServiceWorkerDispatcher* dispatcher =
new ServiceWorkerDispatcher(std::move(thread_safe_sender));
if (WorkerThread::GetCurrentId())
WorkerThread::AddObserver(dispatcher);
return dispatcher;
......
......@@ -27,10 +27,6 @@
#include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWorkerProvider.h"
#include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWorkerRegistration.h"
namespace base {
class SingleThreadTaskRunner;
}
namespace IPC {
class Message;
}
......@@ -45,9 +41,8 @@ class WebServiceWorkerImpl;
// scripts through methods like navigator.registerServiceWorker().
class CONTENT_EXPORT ServiceWorkerDispatcher : public WorkerThread::Observer {
public:
ServiceWorkerDispatcher(
scoped_refptr<ThreadSafeSender> thread_safe_sender,
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner);
explicit ServiceWorkerDispatcher(
scoped_refptr<ThreadSafeSender> thread_safe_sender);
~ServiceWorkerDispatcher() override;
void OnMessageReceived(const IPC::Message& msg);
......@@ -58,17 +53,12 @@ class CONTENT_EXPORT ServiceWorkerDispatcher : public WorkerThread::Observer {
blink::mojom::ServiceWorkerObjectInfoPtr info);
static ServiceWorkerDispatcher* GetOrCreateThreadSpecificInstance(
scoped_refptr<ThreadSafeSender> thread_safe_sender,
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner);
scoped_refptr<ThreadSafeSender> thread_safe_sender);
// Unlike GetOrCreateThreadSpecificInstance() this doesn't create a new
// instance if thread-local instance doesn't exist.
static ServiceWorkerDispatcher* GetThreadSpecificInstance();
base::SingleThreadTaskRunner* main_thread_task_runner() {
return main_thread_task_runner_.get();
}
private:
using WorkerObjectMap = std::map<int, WebServiceWorkerImpl*>;
......@@ -96,7 +86,6 @@ class CONTENT_EXPORT ServiceWorkerDispatcher : public WorkerThread::Observer {
WorkerObjectMap service_workers_;
scoped_refptr<ThreadSafeSender> thread_safe_sender_;
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher);
};
......
......@@ -49,9 +49,8 @@ class ServiceWorkerDispatcherTest : public testing::Test {
ServiceWorkerDispatcherTest() {}
void SetUp() override {
dispatcher_.reset(
new ServiceWorkerDispatcher(nullptr /* thread_safe_sender */,
nullptr /* main_thread_task_runner */));
dispatcher_ = std::make_unique<ServiceWorkerDispatcher>(
nullptr /* thread_safe_sender */);
}
bool ContainsServiceWorker(int handle_id) {
......
......@@ -26,7 +26,7 @@ bool ServiceWorkerMessageFilter::ShouldHandleMessage(
void ServiceWorkerMessageFilter::OnFilteredMessageReceived(
const IPC::Message& msg) {
ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(
thread_safe_sender(), main_thread_task_runner())
thread_safe_sender())
->OnMessageReceived(msg);
}
......
......@@ -295,8 +295,7 @@ ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider(
// current() may be null in tests.
if (ChildThreadImpl::current()) {
ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(
ChildThreadImpl::current()->thread_safe_sender(),
base::ThreadTaskRunnerHandle::Get().get());
ChildThreadImpl::current()->thread_safe_sender());
context_ = base::MakeRefCounted<ServiceWorkerProviderContext>(
browser_provider_id, provider_type, std::move(client_request),
std::move(host_ptr_info), std::move(controller_info),
......@@ -318,8 +317,7 @@ ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider(
scoped_refptr<ThreadSafeSender> sender) {
// Initialize the provider context with info for
// ServiceWorkerGlobalScope#registration.
ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(
sender, base::ThreadTaskRunnerHandle::Get());
ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(sender);
context_ = base::MakeRefCounted<ServiceWorkerProviderContext>(
info->provider_id, std::move(info->client_request),
std::move(info->host_ptr_info));
......
......@@ -274,7 +274,7 @@ class ServiceWorkerProviderContextTest : public testing::Test {
void SetUp() override {
sender_ = new ServiceWorkerTestSender(&ipc_sink_);
dispatcher_.reset(new ServiceWorkerDispatcher(sender_.get(), nullptr));
dispatcher_ = std::make_unique<ServiceWorkerDispatcher>(sender_.get());
}
void EnableS13nServiceWorker() {
......
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