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

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

Issue 2357053002: Always use arc::InstanceHolder<T>::GetInstanceForMethod (Closed)
Patch Set: review Created 4 years, 3 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 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"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 43
44 ArcNotificationManager::~ArcNotificationManager() { 44 ArcNotificationManager::~ArcNotificationManager() {
45 arc_bridge_service()->notifications()->RemoveObserver(this); 45 arc_bridge_service()->notifications()->RemoveObserver(this);
46 } 46 }
47 47
48 void ArcNotificationManager::OnInstanceReady() { 48 void ArcNotificationManager::OnInstanceReady() {
49 DCHECK(!ready_); 49 DCHECK(!ready_);
50 50
51 auto* notifications_instance = 51 auto* notifications_instance =
52 arc_bridge_service()->notifications()->instance(); 52 arc_bridge_service()->notifications()->GetInstanceForMethod("Init");
53 if (!notifications_instance) { 53 if (!notifications_instance)
54 VLOG(2) << "Request to refresh app list when bridge service is not ready.";
55 return; 54 return;
56 }
57 55
58 notifications_instance->Init(binding_.CreateInterfacePtrAndBind()); 56 notifications_instance->Init(binding_.CreateInterfacePtrAndBind());
59 ready_ = true; 57 ready_ = true;
60 } 58 }
61 59
62 void ArcNotificationManager::OnInstanceClosed() { 60 void ArcNotificationManager::OnInstanceClosed() {
63 DCHECK(ready_); 61 DCHECK(ready_);
64 while (!items_.empty()) { 62 while (!items_.empty()) {
65 auto it = items_.begin(); 63 auto it = items_.begin();
66 std::unique_ptr<ArcNotificationItem> item = std::move(it->second); 64 std::unique_ptr<ArcNotificationItem> item = std::move(it->second);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 << "), but it is already gone."; 113 << "), but it is already gone.";
116 return; 114 return;
117 } 115 }
118 116
119 // The removed ArcNotificationItem needs to live in this scope, since the 117 // The removed ArcNotificationItem needs to live in this scope, since the
120 // given argument |key| may be a part of the removed item. 118 // given argument |key| may be a part of the removed item.
121 std::unique_ptr<ArcNotificationItem> item = std::move(it->second); 119 std::unique_ptr<ArcNotificationItem> item = std::move(it->second);
122 items_.erase(it); 120 items_.erase(it);
123 121
124 auto* notifications_instance = 122 auto* notifications_instance =
125 arc_bridge_service()->notifications()->instance(); 123 arc_bridge_service()->notifications()->GetInstanceForMethod(
124 "SendNotificationEventToAndroid");
126 125
127 // On shutdown, the ARC channel may quit earlier then notifications. 126 // On shutdown, the ARC channel may quit earlier then notifications.
128 if (!notifications_instance) { 127 if (!notifications_instance) {
129 VLOG(2) << "ARC Notification (key: " << key 128 VLOG(2) << "ARC Notification (key: " << key
130 << ") is closed, but the ARC channel has already gone."; 129 << ") is closed, but the ARC channel has already gone.";
131 return; 130 return;
132 } 131 }
133 132
134 notifications_instance->SendNotificationEventToAndroid( 133 notifications_instance->SendNotificationEventToAndroid(
135 key, mojom::ArcNotificationEvent::CLOSED); 134 key, mojom::ArcNotificationEvent::CLOSED);
136 } 135 }
137 136
138 void ArcNotificationManager::SendNotificationClickedOnChrome( 137 void ArcNotificationManager::SendNotificationClickedOnChrome(
139 const std::string& key) { 138 const std::string& key) {
140 if (items_.find(key) == items_.end()) { 139 if (items_.find(key) == items_.end()) {
141 VLOG(3) << "Chrome requests to fire a click event on notification (key: " 140 VLOG(3) << "Chrome requests to fire a click event on notification (key: "
142 << key << "), but it is gone."; 141 << key << "), but it is gone.";
143 return; 142 return;
144 } 143 }
145 144
146 auto* notifications_instance = 145 auto* notifications_instance =
147 arc_bridge_service()->notifications()->instance(); 146 arc_bridge_service()->notifications()->GetInstanceForMethod(
147 "SendNotificationEventToAndroid");
148 148
149 // On shutdown, the ARC channel may quit earlier then notifications. 149 // On shutdown, the ARC channel may quit earlier then notifications.
150 if (!notifications_instance) { 150 if (!notifications_instance) {
151 VLOG(2) << "ARC Notification (key: " << key 151 VLOG(2) << "ARC Notification (key: " << key
152 << ") is clicked, but the ARC channel has already gone."; 152 << ") is clicked, but the ARC channel has already gone.";
153 return; 153 return;
154 } 154 }
155 155
156 notifications_instance->SendNotificationEventToAndroid( 156 notifications_instance->SendNotificationEventToAndroid(
157 key, mojom::ArcNotificationEvent::BODY_CLICKED); 157 key, mojom::ArcNotificationEvent::BODY_CLICKED);
158 } 158 }
159 159
160 void ArcNotificationManager::SendNotificationButtonClickedOnChrome( 160 void ArcNotificationManager::SendNotificationButtonClickedOnChrome(
161 const std::string& key, 161 const std::string& key,
162 int button_index) { 162 int button_index) {
163 if (items_.find(key) == items_.end()) { 163 if (items_.find(key) == items_.end()) {
164 VLOG(3) << "Chrome requests to fire a click event on notification (key: " 164 VLOG(3) << "Chrome requests to fire a click event on notification (key: "
165 << key << "), but it is gone."; 165 << key << "), but it is gone.";
166 return; 166 return;
167 } 167 }
168 168
169 auto* notifications_instance = 169 auto* notifications_instance =
170 arc_bridge_service()->notifications()->instance(); 170 arc_bridge_service()->notifications()->GetInstanceForMethod(
171 "SendNotificationEventToAndroid");
171 172
172 // On shutdown, the ARC channel may quit earlier then notifications. 173 // On shutdown, the ARC channel may quit earlier then notifications.
173 if (!notifications_instance) { 174 if (!notifications_instance) {
174 VLOG(2) << "ARC Notification (key: " << key 175 VLOG(2) << "ARC Notification (key: " << key
175 << ")'s button is clicked, but the ARC channel has already gone."; 176 << ")'s button is clicked, but the ARC channel has already gone.";
176 return; 177 return;
177 } 178 }
178 179
179 arc::mojom::ArcNotificationEvent command; 180 arc::mojom::ArcNotificationEvent command;
180 switch (button_index) { 181 switch (button_index) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 ash::WmShell::Get()->toast_manager()->Show( 239 ash::WmShell::Get()->toast_manager()->Show(
239 ash::ToastData(data->id, data->text.To<base::string16>(), data->duration, 240 ash::ToastData(data->id, data->text.To<base::string16>(), data->duration,
240 data->dismiss_text.To<base::string16>())); 241 data->dismiss_text.To<base::string16>()));
241 } 242 }
242 243
243 void ArcNotificationManager::OnToastCancelled(mojom::ArcToastDataPtr data) { 244 void ArcNotificationManager::OnToastCancelled(mojom::ArcToastDataPtr data) {
244 ash::WmShell::Get()->toast_manager()->Cancel(data->id); 245 ash::WmShell::Get()->toast_manager()->Cancel(data->id);
245 } 246 }
246 247
247 } // namespace arc 248 } // namespace arc
OLDNEW
« components/arc/instance_holder.h ('K') | « components/arc/power/arc_power_bridge.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698