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

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

Issue 644643005: Implement a RenderFrame-less path for Web Notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add OWNERS file Created 6 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/child/notifications/notification_dispatcher.h"
6
7 #include "base/message_loop/message_loop_proxy.h"
8 #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"
12
13 namespace content {
14
15 NotificationDispatcher::NotificationDispatcher(
16 ThreadSafeSender* thread_safe_sender)
17 : main_thread_loop_proxy_(base::MessageLoopProxy::current()),
18 thread_safe_sender_(thread_safe_sender) {
19 }
20
21 NotificationDispatcher::~NotificationDispatcher() {}
22
23 int NotificationDispatcher::GenerateNotificationId(int thread_id) {
24 base::AutoLock lock(notification_id_map_lock_);
25 notification_id_map_[next_notification_id_] = thread_id;
26 return next_notification_id_++;
27 }
28
29 base::TaskRunner* NotificationDispatcher::OverrideTaskRunnerForMessage(
30 const IPC::Message& msg) {
31 if (!ShouldHandleMessage(msg))
32 return NULL;
33
34 int notification_id = -1,
35 thread_id = 0;
36
37 const bool success = PickleIterator(msg).ReadInt(&notification_id);
38 DCHECK(success);
39
40 {
41 base::AutoLock lock(notification_id_map_lock_);
42 auto iterator = notification_id_map_.find(notification_id);
43 if (iterator != notification_id_map_.end())
44 thread_id = iterator->second;
45 }
46
47 if (!thread_id)
48 return main_thread_loop_proxy_.get();
49
50 return new WorkerThreadTaskRunner(thread_id);
51 }
52
53 bool NotificationDispatcher::OnMessageReceived(const IPC::Message& msg) {
54 if (!ShouldHandleMessage(msg))
55 return false;
56
57 NotificationManager::ThreadSpecificInstance(thread_safe_sender_.get(), this)
58 ->OnMessageReceived(msg);
59 return true;
60 }
61
62 bool NotificationDispatcher::ShouldHandleMessage(const IPC::Message& msg) {
63 // The thread-safe message filter is responsible for handling all the messages
64 // except for the routed permission-request-completed message, which will be
65 // picked up by the RenderFrameImpl instead.
66 return IPC_MESSAGE_CLASS(msg) == PlatformNotificationMsgStart &&
67 msg.type() != PlatformNotificationMsg_PermissionRequestComplete::ID;
68 }
69
70 } // namespace content
OLDNEW
« no previous file with comments | « content/child/notifications/notification_dispatcher.h ('k') | content/child/notifications/notification_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698