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

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

Issue 1011643002: ServiceWorker: Introduce SWMessageSender in order to mock IPC messaging (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add header comment Created 5 years, 9 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 da1f5c456472a0b76004d3a2273b906749557ab7..ff0c79d72d34f97ab929d5c00dcfebb4a4a04d6d 100644
--- a/content/child/service_worker/service_worker_dispatcher.cc
+++ b/content/child/service_worker/service_worker_dispatcher.cc
@@ -10,6 +10,7 @@
#include "base/trace_event/trace_event.h"
#include "content/child/child_thread_impl.h"
#include "content/child/service_worker/service_worker_handle_reference.h"
+#include "content/child/service_worker/service_worker_message_sender.h"
#include "content/child/service_worker/service_worker_provider_context.h"
#include "content/child/service_worker/service_worker_registration_handle_reference.h"
#include "content/child/service_worker/web_service_worker_impl.h"
@@ -45,8 +46,8 @@ int CurrentWorkerId() {
} // namespace
ServiceWorkerDispatcher::ServiceWorkerDispatcher(
- ThreadSafeSender* thread_safe_sender)
- : thread_safe_sender_(thread_safe_sender) {
+ ServiceWorkerMessageSender* sender)
+ : sender_(sender) {
g_dispatcher_tls.Pointer()->Set(this);
}
@@ -91,10 +92,6 @@ void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) {
DCHECK(handled) << "Unhandled message:" << msg.type();
}
-bool ServiceWorkerDispatcher::Send(IPC::Message* msg) {
- return thread_safe_sender_->Send(msg);
-}
-
void ServiceWorkerDispatcher::RegisterServiceWorker(
int provider_id,
const GURL& pattern,
@@ -121,7 +118,7 @@ void ServiceWorkerDispatcher::RegisterServiceWorker(
request_id,
"Scope", pattern.spec(),
"Script URL", script_url.spec());
- thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker(
+ sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker(
CurrentWorkerId(), request_id, provider_id, pattern, script_url));
}
@@ -148,7 +145,7 @@ void ServiceWorkerDispatcher::UnregisterServiceWorker(
"ServiceWorkerDispatcher::UnregisterServiceWorker",
request_id,
"Scope", pattern.spec());
- thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker(
+ sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker(
CurrentWorkerId(), request_id, provider_id, pattern));
}
@@ -175,7 +172,7 @@ void ServiceWorkerDispatcher::GetRegistration(
"ServiceWorkerDispatcher::GetRegistration",
request_id,
"Document URL", document_url.spec());
- thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration(
+ sender_->Send(new ServiceWorkerHostMsg_GetRegistration(
CurrentWorkerId(), request_id, provider_id, document_url));
}
@@ -186,7 +183,7 @@ void ServiceWorkerDispatcher::GetRegistrationForReady(
TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker",
"ServiceWorkerDispatcher::GetRegistrationForReady",
request_id);
- thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistrationForReady(
+ sender_->Send(new ServiceWorkerHostMsg_GetRegistrationForReady(
CurrentWorkerId(), request_id, provider_id));
}
@@ -225,7 +222,7 @@ void ServiceWorkerDispatcher::RemoveProviderClient(int provider_id) {
ServiceWorkerDispatcher*
ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(
- ThreadSafeSender* thread_safe_sender) {
+ ServiceWorkerMessageSender* sender) {
if (g_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) {
NOTREACHED() << "Re-instantiating TLS ServiceWorkerDispatcher.";
g_dispatcher_tls.Pointer()->Set(NULL);
@@ -234,7 +231,7 @@ ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(
return g_dispatcher_tls.Pointer()->Get();
ServiceWorkerDispatcher* dispatcher =
- new ServiceWorkerDispatcher(thread_safe_sender);
+ new ServiceWorkerDispatcher(sender);
if (WorkerTaskRunner::Instance()->CurrentWorkerId())
WorkerTaskRunner::Instance()->AddStopObserver(dispatcher);
return dispatcher;
@@ -263,18 +260,17 @@ WebServiceWorkerImpl* ServiceWorkerDispatcher::GetServiceWorker(
if (adopt_handle) {
// We are instructed to adopt a handle but we already have one, so
// adopt and destroy a handle ref.
- ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get());
+ ServiceWorkerHandleReference::Adopt(info, sender_.get());
}
return existing_worker->second;
}
scoped_ptr<ServiceWorkerHandleReference> handle_ref =
adopt_handle
- ? ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get())
- : ServiceWorkerHandleReference::Create(info,
- thread_safe_sender_.get());
+ ? ServiceWorkerHandleReference::Adopt(info, sender_.get())
+ : ServiceWorkerHandleReference::Create(info, sender_.get());
// WebServiceWorkerImpl constructor calls AddServiceWorker.
- return new WebServiceWorkerImpl(handle_ref.Pass(), thread_safe_sender_.get());
+ return new WebServiceWorkerImpl(handle_ref.Pass(), sender_.get());
}
WebServiceWorkerRegistrationImpl*
@@ -288,8 +284,7 @@ ServiceWorkerDispatcher::FindServiceWorkerRegistration(
if (adopt_handle) {
// We are instructed to adopt a handle but we already have one, so
// adopt and destroy a handle ref.
- ServiceWorkerRegistrationHandleReference::Adopt(
- info, thread_safe_sender_.get());
+ ServiceWorkerRegistrationHandleReference::Adopt(info, sender_.get());
}
return registration->second;
}
@@ -304,9 +299,9 @@ ServiceWorkerDispatcher::CreateServiceWorkerRegistration(
scoped_ptr<ServiceWorkerRegistrationHandleReference> handle_ref =
adopt_handle ? ServiceWorkerRegistrationHandleReference::Adopt(
- info, thread_safe_sender_.get())
+ info, sender_.get())
: ServiceWorkerRegistrationHandleReference::Create(
- info, thread_safe_sender_.get());
+ info, sender_.get());
// WebServiceWorkerRegistrationImpl constructor calls
// AddServiceWorkerRegistration.
@@ -698,12 +693,9 @@ ServiceWorkerDispatcher::FindOrCreateRegistration(
} else {
// |registration| must already have version attributes, so adopt and destroy
// handle refs for them.
- ServiceWorkerHandleReference::Adopt(
- attrs.installing, thread_safe_sender_.get());
- ServiceWorkerHandleReference::Adopt(
- attrs.waiting, thread_safe_sender_.get());
- ServiceWorkerHandleReference::Adopt(
- attrs.active, thread_safe_sender_.get());
+ ServiceWorkerHandleReference::Adopt(attrs.installing, sender_.get());
+ ServiceWorkerHandleReference::Adopt(attrs.waiting, sender_.get());
+ ServiceWorkerHandleReference::Adopt(attrs.active, sender_.get());
}
return registration;
}

Powered by Google App Engine
This is Rietveld 408576698