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

Side by Side Diff: content/child/notifications/notification_dispatcher.h

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 #ifndef CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_DISPATCHER_H_ 5 #ifndef CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_DISPATCHER_H_
6 #define CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_DISPATCHER_H_ 6 #define CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_DISPATCHER_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/memory/ref_counted.h"
11 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
12 #include "content/child/child_message_filter.h" 11 #include "content/child/worker_thread_message_filter.h"
13
14 namespace base {
15 class MessageLoopProxy;
16 }
17 12
18 namespace content { 13 namespace content {
19 14
20 class ThreadSafeSender; 15 class NotificationDispatcher : public WorkerThreadMessageFilter {
21
22 class NotificationDispatcher : public ChildMessageFilter {
23 public: 16 public:
24 explicit NotificationDispatcher(ThreadSafeSender* thread_safe_sender); 17 explicit NotificationDispatcher(ThreadSafeSender* thread_safe_sender);
25 18
26 // Generates a, process-unique new notification Id mapped to |thread_id|, and 19 // Generates a, process-unique new notification Id mapped to |thread_id|, and
27 // return the notification Id. This method can be called on any thread. 20 // return the notification Id. This method can be called on any thread.
28 int GenerateNotificationId(int thread_id); 21 int GenerateNotificationId(int thread_id);
29 22
30 protected: 23 protected:
31 ~NotificationDispatcher() override; 24 ~NotificationDispatcher() override;
32 25
33 private: 26 private:
34 bool ShouldHandleMessage(const IPC::Message& msg); 27 // WorkerThreadMessageFilter:
35 28 bool ShouldHandleMessage(const IPC::Message& msg) const override;
36 // ChildMessageFilter implementation. 29 void OnFilteredMessageReceived(const IPC::Message& msg) override;
37 base::TaskRunner* OverrideTaskRunnerForMessage(const IPC::Message& msg) 30 bool GetWorkerThreadIdForMessage(const IPC::Message& msg,
38 override; 31 int* ipc_thread_id) override;
39 bool OnMessageReceived(const IPC::Message& msg) override;
40
41 scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_;
42 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
43 32
44 using NotificationIdToThreadId = std::map<int, int>; 33 using NotificationIdToThreadId = std::map<int, int>;
45 34
46 base::Lock notification_id_map_lock_; 35 base::Lock notification_id_map_lock_;
47 NotificationIdToThreadId notification_id_map_; 36 NotificationIdToThreadId notification_id_map_;
48 int next_notification_id_; 37 int next_notification_id_;
49 38
50 DISALLOW_COPY_AND_ASSIGN(NotificationDispatcher); 39 DISALLOW_COPY_AND_ASSIGN(NotificationDispatcher);
51 }; 40 };
52 41
53 } // namespace content 42 } // namespace content
54 43
55 #endif // CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_DISPATCHER_H_ 44 #endif // CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698