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

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

Issue 644643005: Implement a RenderFrame-less path for Web Notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove now unused ipc messages Created 6 years, 2 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
(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_manager.h"
6
7 #include "base/lazy_instance.h"
8 #include "base/threading/thread_local.h"
9 #include "content/child/notifications/notification_dispatcher.h"
10 #include "content/child/thread_safe_sender.h"
11 #include "content/child/worker_task_runner.h"
12 #include "content/common/platform_notification_messages.h"
13 #include "content/public/common/show_desktop_notification_params.h"
14 #include "third_party/WebKit/public/platform/WebNotificationData.h"
15 #include "third_party/WebKit/public/platform/WebNotificationDelegate.h"
16 #include "third_party/WebKit/public/platform/WebSerializedOrigin.h"
17 #include "third_party/skia/include/core/SkBitmap.h"
18
19 using blink::WebNotificationPermission;
20
21 namespace content {
22 namespace {
Mike West 2014/10/24 13:20:18 Nit: Blank line.
Peter Beverloo 2014/10/24 13:57:35 Done.
23 int CurrentWorkerId() {
24 return WorkerTaskRunner::Instance()->CurrentWorkerId();
25 }
26 } // namespace
27
28 static base::LazyInstance<base::ThreadLocalPointer<NotificationManager> >::Leaky
Mike West 2014/10/24 13:20:18 Nit: >>
Peter Beverloo 2014/10/24 13:57:35 Done.
29 g_notification_manager_tls = LAZY_INSTANCE_INITIALIZER;
30
31 NotificationManager::NotificationManager(
32 ThreadSafeSender* thread_safe_sender,
33 NotificationDispatcher* notification_dispatcher)
34 : thread_safe_sender_(thread_safe_sender),
35 notification_dispatcher_(notification_dispatcher) {
36 g_notification_manager_tls.Pointer()->Set(this);
37 }
38
39 NotificationManager::~NotificationManager() {
40 g_notification_manager_tls.Pointer()->Set(NULL);
Mike West 2014/10/24 13:20:18 Nit: nullptr
Peter Beverloo 2014/10/24 13:57:35 Done.
41 }
42
43 NotificationManager* NotificationManager::ThreadSpecificInstance(
44 ThreadSafeSender* thread_safe_sender,
45 NotificationDispatcher* notification_dispatcher) {
46 if (g_notification_manager_tls.Pointer()->Get())
47 return g_notification_manager_tls.Pointer()->Get();
48
49 NotificationManager* manager = new NotificationManager(
50 thread_safe_sender, notification_dispatcher);
51 if (WorkerTaskRunner::Instance()->CurrentWorkerId())
52 WorkerTaskRunner::Instance()->AddStopObserver(manager);
53 return manager;
54 }
55
56 void NotificationManager::OnWorkerRunLoopStopped() {
57 delete this;
58 }
59
60 void NotificationManager::show(
61 const blink::WebSerializedOrigin& origin,
62 const blink::WebNotificationData& notification_data,
63 blink::WebNotificationDelegate* delegate) {
64 int notification_id =
65 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId());
66
67 active_notifications_[notification_id] = delegate;
68
69 ShowDesktopNotificationHostMsgParams params;
70 params.origin = GURL(origin.string());
71
72 // TODO(peter): Move the notification_icon_loader to //content/child/ and use
73 // it to download Notification icons here.
74 params.icon = SkBitmap();
75 params.title = notification_data.title;
76 params.body = notification_data.body;
77
78 // TODO(peter): Remove the usage of the Blink WebTextDirection enumeration for
79 // the text direction of notifications throughout Chrome.
80 params.direction = blink::WebTextDirectionLeftToRight;
81 params.replace_id = notification_data.tag;
82
83 thread_safe_sender_->Send(new PlatformNotificationHostMsg_Show(
84 notification_id, params));
85 }
86
87 void NotificationManager::close(blink::WebNotificationDelegate* delegate) {
88 auto iter = active_notifications_.cbegin();
89 for (; iter != active_notifications_.cend(); ++iter) {
90 if (iter->second != delegate)
91 continue;
92
93 thread_safe_sender_->Send(
94 new PlatformNotificationHostMsg_Close(iter->first));
95 active_notifications_.erase(iter);
96
97 delegate->dispatchCloseEvent();
98 return;
99 }
100
101 // It should not be possible for Blink to call close() on a Notification which
102 // does not exist anymore in the manager.
103 NOTREACHED();
104 }
105
106 void NotificationManager::notifyDelegateDestroyed(
107 blink::WebNotificationDelegate* delegate) {
108 auto iter = active_notifications_.cbegin();
109 for (; iter != active_notifications_.cend(); ++iter) {
110 if (iter->second != delegate)
111 continue;
112
113 active_notifications_.erase(iter);
114 return;
115 }
116 }
117
118 WebNotificationPermission NotificationManager::checkPermission(
119 const blink::WebSerializedOrigin& origin) {
120 WebNotificationPermission permission =
121 blink::WebNotificationPermissionAllowed;
122 thread_safe_sender_->Send(new PlatformNotificationHostMsg_CheckPermission(
123 GURL(origin.string()), &permission));
124
125 return permission;
126 }
127
128 bool NotificationManager::OnMessageReceived(const IPC::Message& message) {
129 // TODO(peter): Implement the message handlers for browser -> renderer events.
130 return false;
131 }
132
133 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698