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

Unified Diff: content/child/push_messaging/push_dispatcher.cc

Issue 892543002: workers: Introduce a WorkerMessageFilter to ease routing/processing worker messages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 11 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
« no previous file with comments | « content/child/push_messaging/push_dispatcher.h ('k') | content/child/push_messaging/push_provider.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/push_messaging/push_dispatcher.cc
diff --git a/content/child/push_messaging/push_dispatcher.cc b/content/child/push_messaging/push_dispatcher.cc
index 4bd1705adbe1fe7104e0bc8dc9cc94b0aadd5e1d..8cc33fc0dd20e53164d0fa60fbb94cd763af0b36 100644
--- a/content/child/push_messaging/push_dispatcher.cc
+++ b/content/child/push_messaging/push_dispatcher.cc
@@ -4,19 +4,13 @@
#include "content/child/push_messaging/push_dispatcher.h"
-#include "base/message_loop/message_loop_proxy.h"
-#include "base/pickle.h"
#include "content/child/push_messaging/push_provider.h"
-#include "content/child/thread_safe_sender.h"
-#include "content/child/worker_thread_task_runner.h"
#include "content/common/push_messaging_messages.h"
namespace content {
PushDispatcher::PushDispatcher(ThreadSafeSender* thread_safe_sender)
- : main_thread_loop_proxy_(base::MessageLoopProxy::current()),
- thread_safe_sender_(thread_safe_sender),
- next_request_id_(0) {
+ : WorkerThreadMessageFilter(thread_safe_sender), next_request_id_(0) {
}
PushDispatcher::~PushDispatcher() {
@@ -28,43 +22,7 @@ int PushDispatcher::GenerateRequestId(int thread_id) {
return next_request_id_++;
}
-base::TaskRunner* PushDispatcher::OverrideTaskRunnerForMessage(
- const IPC::Message& msg) {
- if (!ShouldHandleMessage(msg))
- return nullptr;
-
- int request_id = -1;
- int thread_id = 0;
-
- const bool success = PickleIterator(msg).ReadInt(&request_id);
- DCHECK(success);
-
- {
- base::AutoLock lock(request_id_map_lock_);
- auto it = request_id_map_.find(request_id);
- if (it != request_id_map_.end()) {
- thread_id = it->second;
- request_id_map_.erase(it);
- }
- }
-
- if (!thread_id)
- return main_thread_loop_proxy_.get();
-
- return new WorkerThreadTaskRunner(thread_id);
-}
-
-bool PushDispatcher::OnMessageReceived(const IPC::Message& msg) {
- if (!ShouldHandleMessage(msg))
- return false;
-
- bool handled = PushProvider::ThreadSpecificInstance(
- thread_safe_sender_.get(), this)->OnMessageReceived(msg);
- DCHECK(handled);
- return handled;
-}
-
-bool PushDispatcher::ShouldHandleMessage(const IPC::Message& msg) {
+bool PushDispatcher::ShouldHandleMessage(const IPC::Message& msg) const {
// Note that not all Push API IPC messages flow through this class. A subset
// of the API functionality requires a direct association with a document and
// a frame, and for those cases the IPC messages are handled by a
@@ -79,4 +37,27 @@ bool PushDispatcher::ShouldHandleMessage(const IPC::Message& msg) {
msg.type() == PushMessagingMsg_UnregisterError::ID;
}
+void PushDispatcher::OnFilteredMessageReceived(const IPC::Message& msg) {
+ bool handled = PushProvider::ThreadSpecificInstance(
+ thread_safe_sender(), this)->OnMessageReceived(msg);
+ DCHECK(handled);
+}
+
+bool PushDispatcher::GetWorkerThreadIdForMessage(const IPC::Message& msg,
+ int* ipc_thread_id) {
+ int request_id = -1;
+
+ const bool success = PickleIterator(msg).ReadInt(&request_id);
+ DCHECK(success);
+
+ base::AutoLock lock(request_id_map_lock_);
+ auto it = request_id_map_.find(request_id);
+ if (it != request_id_map_.end()) {
+ *ipc_thread_id = it->second;
+ request_id_map_.erase(it);
+ return true;
+ }
+ return false;
+}
+
} // namespace content
« no previous file with comments | « content/child/push_messaging/push_dispatcher.h ('k') | content/child/push_messaging/push_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698