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

Side by Side Diff: content/child/notifications/notification_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, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/notifications/notification_dispatcher.h" 5 #include "content/child/notifications/notification_dispatcher.h"
6 6
7 #include "base/message_loop/message_loop_proxy.h"
8 #include "content/child/notifications/notification_manager.h" 7 #include "content/child/notifications/notification_manager.h"
9 #include "content/child/thread_safe_sender.h"
10 #include "content/child/worker_thread_task_runner.h"
11 #include "content/common/platform_notification_messages.h" 8 #include "content/common/platform_notification_messages.h"
12 9
13 namespace content { 10 namespace content {
14 11
15 NotificationDispatcher::NotificationDispatcher( 12 NotificationDispatcher::NotificationDispatcher(
16 ThreadSafeSender* thread_safe_sender) 13 ThreadSafeSender* thread_safe_sender)
17 : main_thread_loop_proxy_(base::MessageLoopProxy::current()), 14 : WorkerThreadMessageFilter(thread_safe_sender), next_notification_id_(0) {
18 thread_safe_sender_(thread_safe_sender),
19 next_notification_id_(0) {
20 } 15 }
21 16
22 NotificationDispatcher::~NotificationDispatcher() {} 17 NotificationDispatcher::~NotificationDispatcher() {}
23 18
24 int NotificationDispatcher::GenerateNotificationId(int thread_id) { 19 int NotificationDispatcher::GenerateNotificationId(int thread_id) {
25 base::AutoLock lock(notification_id_map_lock_); 20 base::AutoLock lock(notification_id_map_lock_);
26 notification_id_map_[next_notification_id_] = thread_id; 21 notification_id_map_[next_notification_id_] = thread_id;
27 return next_notification_id_++; 22 return next_notification_id_++;
28 } 23 }
29 24
30 base::TaskRunner* NotificationDispatcher::OverrideTaskRunnerForMessage( 25 bool NotificationDispatcher::ShouldHandleMessage(
26 const IPC::Message& msg) const {
27 return IPC_MESSAGE_CLASS(msg) == PlatformNotificationMsgStart;
28 }
29
30 void NotificationDispatcher::OnFilteredMessageReceived(
31 const IPC::Message& msg) { 31 const IPC::Message& msg) {
32 if (!ShouldHandleMessage(msg)) 32 NotificationManager::ThreadSpecificInstance(thread_safe_sender(),
33 return NULL; 33 main_thread_task_runner(),
34 this)->OnMessageReceived(msg);
35 }
34 36
35 int notification_id = -1, 37 bool NotificationDispatcher::GetWorkerThreadIdForMessage(
36 thread_id = 0; 38 const IPC::Message& msg,
37 39 int* ipc_thread_id) {
40 int notification_id = -1;
38 const bool success = PickleIterator(msg).ReadInt(&notification_id); 41 const bool success = PickleIterator(msg).ReadInt(&notification_id);
39 DCHECK(success); 42 DCHECK(success);
40 43
41 { 44 base::AutoLock lock(notification_id_map_lock_);
42 base::AutoLock lock(notification_id_map_lock_); 45 auto iterator = notification_id_map_.find(notification_id);
43 auto iterator = notification_id_map_.find(notification_id); 46 if (iterator != notification_id_map_.end()) {
44 if (iterator != notification_id_map_.end()) 47 *ipc_thread_id = iterator->second;
45 thread_id = iterator->second; 48 return true;
46 } 49 }
47 50 return false;
48 if (!thread_id)
49 return main_thread_loop_proxy_.get();
50
51 return new WorkerThreadTaskRunner(thread_id);
52 }
53
54 bool NotificationDispatcher::OnMessageReceived(const IPC::Message& msg) {
55 if (!ShouldHandleMessage(msg))
56 return false;
57
58 NotificationManager::ThreadSpecificInstance(
59 thread_safe_sender_.get(),
60 main_thread_loop_proxy_.get(),
61 this)->OnMessageReceived(msg);
62 return true;
63 }
64
65 bool NotificationDispatcher::ShouldHandleMessage(const IPC::Message& msg) {
66 return IPC_MESSAGE_CLASS(msg) == PlatformNotificationMsgStart;
67 } 51 }
68 52
69 } // namespace content 53 } // namespace content
OLDNEW
« no previous file with comments | « content/child/notifications/notification_dispatcher.h ('k') | content/child/push_messaging/push_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698