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

Side by Side Diff: ui/arc/notification/arc_notification_manager.cc

Issue 2599673005: arc: Use GET_INTERFACE_FOR_METHOD macro (Closed)
Patch Set: Addressed feedback Created 3 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 unified diff | Download patch
« no previous file with comments | « components/arc/storage_manager/arc_storage_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ui/arc/notification/arc_notification_manager.h" 5 #include "ui/arc/notification/arc_notification_manager.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/common/system/toast/toast_manager.h" 10 #include "ash/common/system/toast/toast_manager.h"
11 #include "ash/common/wm_shell.h" 11 #include "ash/common/wm_shell.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "components/arc/arc_bridge_service.h" 15 #include "components/arc/arc_bridge_service.h"
16 #include "mojo/common/common_type_converters.h" 16 #include "mojo/common/common_type_converters.h"
17 #include "ui/arc/notification/arc_custom_notification_item.h" 17 #include "ui/arc/notification/arc_custom_notification_item.h"
18 #include "ui/arc/notification/arc_notification_item.h" 18 #include "ui/arc/notification/arc_notification_item.h"
19 19
20 namespace arc { 20 namespace arc {
21 21
22 namespace {
23
24 // Min version to support Create/CloseNotificationWindow.
25 constexpr int kMinVersionNotificationWindow = 7;
26
27 } // namespace
28
29 ArcNotificationManager::ArcNotificationManager(ArcBridgeService* bridge_service, 22 ArcNotificationManager::ArcNotificationManager(ArcBridgeService* bridge_service,
30 const AccountId& main_profile_id) 23 const AccountId& main_profile_id)
31 : ArcNotificationManager(bridge_service, 24 : ArcNotificationManager(bridge_service,
32 main_profile_id, 25 main_profile_id,
33 message_center::MessageCenter::Get()) {} 26 message_center::MessageCenter::Get()) {}
34 27
35 ArcNotificationManager::ArcNotificationManager( 28 ArcNotificationManager::ArcNotificationManager(
36 ArcBridgeService* bridge_service, 29 ArcBridgeService* bridge_service,
37 const AccountId& main_profile_id, 30 const AccountId& main_profile_id,
38 message_center::MessageCenter* message_center) 31 message_center::MessageCenter* message_center)
39 : ArcService(bridge_service), 32 : ArcService(bridge_service),
40 main_profile_id_(main_profile_id), 33 main_profile_id_(main_profile_id),
41 message_center_(message_center), 34 message_center_(message_center),
42 binding_(this) { 35 binding_(this) {
43 arc_bridge_service()->notifications()->AddObserver(this); 36 arc_bridge_service()->notifications()->AddObserver(this);
44 } 37 }
45 38
46 ArcNotificationManager::~ArcNotificationManager() { 39 ArcNotificationManager::~ArcNotificationManager() {
47 arc_bridge_service()->notifications()->RemoveObserver(this); 40 arc_bridge_service()->notifications()->RemoveObserver(this);
48 } 41 }
49 42
50 void ArcNotificationManager::OnInstanceReady() { 43 void ArcNotificationManager::OnInstanceReady() {
51 DCHECK(!ready_); 44 DCHECK(!ready_);
52 45
53 auto* notifications_instance = 46 auto* notifications_instance =
54 arc_bridge_service()->notifications()->GetInstanceForMethod("Init"); 47 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->notifications(), Init);
55 DCHECK(notifications_instance); 48 DCHECK(notifications_instance);
56 49
57 notifications_instance->Init(binding_.CreateInterfacePtrAndBind()); 50 notifications_instance->Init(binding_.CreateInterfacePtrAndBind());
58 ready_ = true; 51 ready_ = true;
59 } 52 }
60 53
61 void ArcNotificationManager::OnInstanceClosed() { 54 void ArcNotificationManager::OnInstanceClosed() {
62 DCHECK(ready_); 55 DCHECK(ready_);
63 while (!items_.empty()) { 56 while (!items_.empty()) {
64 auto it = items_.begin(); 57 auto it = items_.begin();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 VLOG(3) << "Chrome requests to remove a notification (key: " << key 106 VLOG(3) << "Chrome requests to remove a notification (key: " << key
114 << "), but it is already gone."; 107 << "), but it is already gone.";
115 return; 108 return;
116 } 109 }
117 110
118 // The removed ArcNotificationItem needs to live in this scope, since the 111 // The removed ArcNotificationItem needs to live in this scope, since the
119 // given argument |key| may be a part of the removed item. 112 // given argument |key| may be a part of the removed item.
120 std::unique_ptr<ArcNotificationItem> item = std::move(it->second); 113 std::unique_ptr<ArcNotificationItem> item = std::move(it->second);
121 items_.erase(it); 114 items_.erase(it);
122 115
123 auto* notifications_instance = 116 auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD(
124 arc_bridge_service()->notifications()->GetInstanceForMethod( 117 arc_bridge_service()->notifications(), SendNotificationEventToAndroid);
125 "SendNotificationEventToAndroid");
126 118
127 // On shutdown, the ARC channel may quit earlier then notifications. 119 // On shutdown, the ARC channel may quit earlier then notifications.
128 if (!notifications_instance) { 120 if (!notifications_instance) {
129 VLOG(2) << "ARC Notification (key: " << key 121 VLOG(2) << "ARC Notification (key: " << key
130 << ") is closed, but the ARC channel has already gone."; 122 << ") is closed, but the ARC channel has already gone.";
131 return; 123 return;
132 } 124 }
133 125
134 notifications_instance->SendNotificationEventToAndroid( 126 notifications_instance->SendNotificationEventToAndroid(
135 key, mojom::ArcNotificationEvent::CLOSED); 127 key, mojom::ArcNotificationEvent::CLOSED);
136 } 128 }
137 129
138 void ArcNotificationManager::SendNotificationClickedOnChrome( 130 void ArcNotificationManager::SendNotificationClickedOnChrome(
139 const std::string& key) { 131 const std::string& key) {
140 if (items_.find(key) == items_.end()) { 132 if (items_.find(key) == items_.end()) {
141 VLOG(3) << "Chrome requests to fire a click event on notification (key: " 133 VLOG(3) << "Chrome requests to fire a click event on notification (key: "
142 << key << "), but it is gone."; 134 << key << "), but it is gone.";
143 return; 135 return;
144 } 136 }
145 137
146 auto* notifications_instance = 138 auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD(
147 arc_bridge_service()->notifications()->GetInstanceForMethod( 139 arc_bridge_service()->notifications(), SendNotificationEventToAndroid);
148 "SendNotificationEventToAndroid");
149 140
150 // On shutdown, the ARC channel may quit earlier then notifications. 141 // On shutdown, the ARC channel may quit earlier then notifications.
151 if (!notifications_instance) { 142 if (!notifications_instance) {
152 VLOG(2) << "ARC Notification (key: " << key 143 VLOG(2) << "ARC Notification (key: " << key
153 << ") is clicked, but the ARC channel has already gone."; 144 << ") is clicked, but the ARC channel has already gone.";
154 return; 145 return;
155 } 146 }
156 147
157 notifications_instance->SendNotificationEventToAndroid( 148 notifications_instance->SendNotificationEventToAndroid(
158 key, mojom::ArcNotificationEvent::BODY_CLICKED); 149 key, mojom::ArcNotificationEvent::BODY_CLICKED);
159 } 150 }
160 151
161 void ArcNotificationManager::SendNotificationButtonClickedOnChrome( 152 void ArcNotificationManager::SendNotificationButtonClickedOnChrome(
162 const std::string& key, 153 const std::string& key,
163 int button_index) { 154 int button_index) {
164 if (items_.find(key) == items_.end()) { 155 if (items_.find(key) == items_.end()) {
165 VLOG(3) << "Chrome requests to fire a click event on notification (key: " 156 VLOG(3) << "Chrome requests to fire a click event on notification (key: "
166 << key << "), but it is gone."; 157 << key << "), but it is gone.";
167 return; 158 return;
168 } 159 }
169 160
170 auto* notifications_instance = 161 auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD(
171 arc_bridge_service()->notifications()->GetInstanceForMethod( 162 arc_bridge_service()->notifications(), SendNotificationEventToAndroid);
172 "SendNotificationEventToAndroid");
173 163
174 // On shutdown, the ARC channel may quit earlier then notifications. 164 // On shutdown, the ARC channel may quit earlier then notifications.
175 if (!notifications_instance) { 165 if (!notifications_instance) {
176 VLOG(2) << "ARC Notification (key: " << key 166 VLOG(2) << "ARC Notification (key: " << key
177 << ")'s button is clicked, but the ARC channel has already gone."; 167 << ")'s button is clicked, but the ARC channel has already gone.";
178 return; 168 return;
179 } 169 }
180 170
181 mojom::ArcNotificationEvent command; 171 mojom::ArcNotificationEvent command;
182 switch (button_index) { 172 switch (button_index) {
(...skipping 21 matching lines...) Expand all
204 notifications_instance->SendNotificationEventToAndroid(key, command); 194 notifications_instance->SendNotificationEventToAndroid(key, command);
205 } 195 }
206 196
207 void ArcNotificationManager::CreateNotificationWindow(const std::string& key) { 197 void ArcNotificationManager::CreateNotificationWindow(const std::string& key) {
208 if (items_.find(key) == items_.end()) { 198 if (items_.find(key) == items_.end()) {
209 VLOG(3) << "Chrome requests to create window on notification (key: " << key 199 VLOG(3) << "Chrome requests to create window on notification (key: " << key
210 << "), but it is gone."; 200 << "), but it is gone.";
211 return; 201 return;
212 } 202 }
213 203
214 auto* notifications_instance = 204 auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD(
215 arc_bridge_service()->notifications()->GetInstanceForMethod( 205 arc_bridge_service()->notifications(), CreateNotificationWindow);
216 "CreateNotificationWindow", kMinVersionNotificationWindow);
217 if (!notifications_instance) 206 if (!notifications_instance)
218 return; 207 return;
219 208
220 notifications_instance->CreateNotificationWindow(key); 209 notifications_instance->CreateNotificationWindow(key);
221 } 210 }
222 211
223 void ArcNotificationManager::CloseNotificationWindow(const std::string& key) { 212 void ArcNotificationManager::CloseNotificationWindow(const std::string& key) {
224 if (items_.find(key) == items_.end()) { 213 if (items_.find(key) == items_.end()) {
225 VLOG(3) << "Chrome requests to close window on notification (key: " << key 214 VLOG(3) << "Chrome requests to close window on notification (key: " << key
226 << "), but it is gone."; 215 << "), but it is gone.";
227 return; 216 return;
228 } 217 }
229 218
230 auto* notifications_instance = 219 auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD(
231 arc_bridge_service()->notifications()->GetInstanceForMethod( 220 arc_bridge_service()->notifications(), CloseNotificationWindow);
232 "CloseNotificationWindow", kMinVersionNotificationWindow);
233 if (!notifications_instance) 221 if (!notifications_instance)
234 return; 222 return;
235 223
236 notifications_instance->CloseNotificationWindow(key); 224 notifications_instance->CloseNotificationWindow(key);
237 } 225 }
238 226
239 void ArcNotificationManager::OnToastPosted(mojom::ArcToastDataPtr data) { 227 void ArcNotificationManager::OnToastPosted(mojom::ArcToastDataPtr data) {
240 const base::string16 text16( 228 const base::string16 text16(
241 base::UTF8ToUTF16(data->text.has_value() ? *data->text : std::string())); 229 base::UTF8ToUTF16(data->text.has_value() ? *data->text : std::string()));
242 const base::string16 dismiss_text16(base::UTF8ToUTF16( 230 const base::string16 dismiss_text16(base::UTF8ToUTF16(
243 data->dismiss_text.has_value() ? *data->dismiss_text : std::string())); 231 data->dismiss_text.has_value() ? *data->dismiss_text : std::string()));
244 ash::WmShell::Get()->toast_manager()->Show( 232 ash::WmShell::Get()->toast_manager()->Show(
245 ash::ToastData(data->id, text16, data->duration, dismiss_text16)); 233 ash::ToastData(data->id, text16, data->duration, dismiss_text16));
246 } 234 }
247 235
248 void ArcNotificationManager::OnToastCancelled(mojom::ArcToastDataPtr data) { 236 void ArcNotificationManager::OnToastCancelled(mojom::ArcToastDataPtr data) {
249 ash::WmShell::Get()->toast_manager()->Cancel(data->id); 237 ash::WmShell::Get()->toast_manager()->Cancel(data->id);
250 } 238 }
251 239
252 } // namespace arc 240 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/storage_manager/arc_storage_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698