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

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

Issue 1477733002: Add ArcNotificationManager for new ARC notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/arc/notification/arc_notification_manager.h"
6
7 #include "base/stl_util.h"
8 #include "ui/arc/notification/arc_notification_item.h"
9
10 namespace arc {
11
12 ArcNotificationManager::ArcNotificationManager(ArcBridgeService* arc_bridge,
13 const AccountId& main_profile_id)
14 : arc_bridge_(arc_bridge),
15 main_profile_id_(main_profile_id),
16 binding_(this) {
17 // This must be initialized after ArcBridgeService.
18 DCHECK(arc_bridge_);
19 DCHECK_EQ(arc_bridge_, ArcBridgeService::Get());
20 arc_bridge_->AddObserver(this);
21 }
22
23 ArcNotificationManager::~ArcNotificationManager() {
24 // This should be free'd before ArcBridgeService.
25 DCHECK(ArcBridgeService::Get());
26 DCHECK_EQ(arc_bridge_, ArcBridgeService::Get());
27 arc_bridge_->RemoveObserver(this);
28 }
29
30 void ArcNotificationManager::OnNotificationsInstanceReady() {
31 NotificationsInstance* notifications_instance =
32 arc_bridge_->notifications_instance();
33 if (!notifications_instance) {
34 VLOG(2) << "Request to refresh app list when bridge service is not ready.";
35 return;
36 }
37
38 NotificationsHostPtr host;
39 binding_.Bind(mojo::GetProxy(&host));
40 notifications_instance->Init(std::move(host));
41 }
42
43 void ArcNotificationManager::OnNotificationPosted(ArcNotificationDataPtr data) {
44 ArcNotificationItem* item = items_.get(data->key);
45 if (!item) {
46 // Show a notification on the primary loged-in user's desktop.
47 // TODO(yoshiki): Reconsider when ARC supports multi-user.
48 item = new ArcNotificationItem(this, message_center::MessageCenter::Get(),
49 *data, main_profile_id_);
dcheng 2016/01/12 01:25:48 Nit: I think it would be slightly clearer to only
yoshiki 2016/01/12 04:50:25 Done.
50 items_.set(data->key, make_scoped_ptr(item));
51 }
52 item->UpdateWithArcNotificationData(*data);
53 }
54
55 void ArcNotificationManager::OnNotificationRemoved(const mojo::String& key) {
56 ItemMap::iterator it = items_.find(key.get());
57 if (it == items_.end()) {
58 VLOG(3) << "Android requests to remove a notification (key: " << key
59 << "), but it is already gone.";
60 return;
61 }
62
63 scoped_ptr<ArcNotificationItem> item(items_.take_and_erase(it));
64 item->OnClosedFromAndroid();
65 }
66
67 void ArcNotificationManager::SendNotificationRemovedFromChrome(
68 const std::string& key) {
69 ItemMap::iterator it = items_.find(key);
70 if (it == items_.end()) {
71 VLOG(3) << "Chrome requests to remove a notification (key: " << key
72 << "), but it is already gone.";
73 return;
74 }
75
76 scoped_ptr<ArcNotificationItem> item(items_.take_and_erase(it));
77
78 arc_bridge_->notifications_instance()->SendNotificationEventToAndroid(
79 key, ARC_NOTIFICATION_EVENT_CLOSED);
80 }
81
82 void ArcNotificationManager::SendNotificationClickedOnChrome(
83 const std::string& key) {
84 if (!items_.contains(key)) {
85 VLOG(3) << "Chrome requests to fire a click event on notification (key: "
86 << key << "), but it is gone.";
87 return;
88 }
89
90 arc_bridge_->notifications_instance()->SendNotificationEventToAndroid(
91 key, ARC_NOTIFICATION_EVENT_BODY_CLICKED);
92 }
93
94 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698