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

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

Issue 1596663002: arc-bridge: Introduce the ArcService class (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: Addressed feedback Created 4 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
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 "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "ui/arc/notification/arc_notification_item.h" 8 #include "ui/arc/notification/arc_notification_item.h"
9 9
10 namespace arc { 10 namespace arc {
11 11
12 ArcNotificationManager::ArcNotificationManager(ArcBridgeService* arc_bridge, 12 ArcNotificationManager::ArcNotificationManager(
13 const AccountId& main_profile_id) 13 ArcBridgeService* arc_bridge_service,
14 : arc_bridge_(arc_bridge), 14 const AccountId& main_profile_id)
15 : arc_bridge_service_(arc_bridge_service),
15 main_profile_id_(main_profile_id), 16 main_profile_id_(main_profile_id),
16 binding_(this) { 17 binding_(this) {
17 // This must be initialized after ArcBridgeService. 18 DCHECK(arc_bridge_service_);
18 DCHECK(arc_bridge_); 19 arc_bridge_service_->AddObserver(this);
19 DCHECK_EQ(arc_bridge_, ArcBridgeService::Get()); 20
20 arc_bridge_->AddObserver(this); 21 // If NotificationsInstance was ready before we AddObserver(), we won't get
22 // OnNotificationsInstanceReady events. For such case, we have to call it
23 // explicitly.
24 if (arc_bridge_service_->notifications_instance())
25 OnNotificationsInstanceReady();
21 } 26 }
22 27
23 ArcNotificationManager::~ArcNotificationManager() { 28 ArcNotificationManager::~ArcNotificationManager() {
24 // This should be free'd before ArcBridgeService. 29 arc_bridge_service_->RemoveObserver(this);
25 DCHECK(ArcBridgeService::Get());
26 DCHECK_EQ(arc_bridge_, ArcBridgeService::Get());
27 arc_bridge_->RemoveObserver(this);
28 } 30 }
29 31
30 void ArcNotificationManager::OnNotificationsInstanceReady() { 32 void ArcNotificationManager::OnNotificationsInstanceReady() {
31 NotificationsInstance* notifications_instance = 33 NotificationsInstance* notifications_instance =
32 arc_bridge_->notifications_instance(); 34 arc_bridge_service_->notifications_instance();
33 if (!notifications_instance) { 35 if (!notifications_instance) {
34 VLOG(2) << "Request to refresh app list when bridge service is not ready."; 36 VLOG(2) << "Request to refresh app list when bridge service is not ready.";
35 return; 37 return;
36 } 38 }
37 39
38 NotificationsHostPtr host; 40 NotificationsHostPtr host;
39 binding_.Bind(mojo::GetProxy(&host)); 41 binding_.Bind(mojo::GetProxy(&host));
40 notifications_instance->Init(std::move(host)); 42 notifications_instance->Init(std::move(host));
41 } 43 }
42 44
(...skipping 25 matching lines...) Expand all
68 const std::string& key) { 70 const std::string& key) {
69 ItemMap::iterator it = items_.find(key); 71 ItemMap::iterator it = items_.find(key);
70 if (it == items_.end()) { 72 if (it == items_.end()) {
71 VLOG(3) << "Chrome requests to remove a notification (key: " << key 73 VLOG(3) << "Chrome requests to remove a notification (key: " << key
72 << "), but it is already gone."; 74 << "), but it is already gone.";
73 return; 75 return;
74 } 76 }
75 77
76 scoped_ptr<ArcNotificationItem> item(items_.take_and_erase(it)); 78 scoped_ptr<ArcNotificationItem> item(items_.take_and_erase(it));
77 79
78 arc_bridge_->notifications_instance()->SendNotificationEventToAndroid( 80 arc_bridge_service_->notifications_instance()->SendNotificationEventToAndroid(
79 key, ARC_NOTIFICATION_EVENT_CLOSED); 81 key, ARC_NOTIFICATION_EVENT_CLOSED);
80 } 82 }
81 83
82 void ArcNotificationManager::SendNotificationClickedOnChrome( 84 void ArcNotificationManager::SendNotificationClickedOnChrome(
83 const std::string& key) { 85 const std::string& key) {
84 if (!items_.contains(key)) { 86 if (!items_.contains(key)) {
85 VLOG(3) << "Chrome requests to fire a click event on notification (key: " 87 VLOG(3) << "Chrome requests to fire a click event on notification (key: "
86 << key << "), but it is gone."; 88 << key << "), but it is gone.";
87 return; 89 return;
88 } 90 }
89 91
90 arc_bridge_->notifications_instance()->SendNotificationEventToAndroid( 92 arc_bridge_service_->notifications_instance()->SendNotificationEventToAndroid(
91 key, ARC_NOTIFICATION_EVENT_BODY_CLICKED); 93 key, ARC_NOTIFICATION_EVENT_BODY_CLICKED);
92 } 94 }
93 95
94 } // namespace arc 96 } // namespace arc
OLDNEW
« components/arc/arc_service.h ('K') | « ui/arc/notification/arc_notification_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698