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

Side by Side Diff: components/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: Addressed comments Created 5 years 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 2015 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 "components/arc/notification/arc_notification_manager.h"
6
7 #include "base/stl_util.h"
8 #include "components/arc/notification/arc_notification_item.h"
9
10 namespace arc {
11
12 ArcNotificationManager::ArcNotificationManager(
13 ArcBridgeService* arc_bridge,
14 const AccountId& main_profile_id)
15 : arc_bridge_(arc_bridge), main_profile_id_(main_profile_id) {
16 // This must be initialized after ArcBridgeService.
17 DCHECK(arc_bridge_);
18 DCHECK_EQ(arc_bridge_, ArcBridgeService::Get());
19 arc_bridge_->AddNotificationObserver(this);
20 }
21
22 ArcNotificationManager::~ArcNotificationManager() {
23 // This should be free'd before ArcBridgeService.
24 DCHECK(ArcBridgeService::Get());
25 DCHECK_EQ(arc_bridge_, ArcBridgeService::Get());
26 arc_bridge_->RemoveNotificationObserver(this);
27 }
28
29 void ArcNotificationManager::OnNotificationPostedFromAndroid(
30 const ArcNotificationData& data) {
31 ArcNotificationItem* item = items_.get(data.key);
32 if (!item) {
33 // Show a notification on the primary loged-in user's desktop.
34 // TODO(yoshiki): Reconsider when ARC supports multi-user.
35 scoped_ptr<ArcNotificationItem> item(new ArcNotificationItem(
36 this, message_center::MessageCenter::Get(), data, main_profile_id_));
37 items_.set(data.key, item.Pass());
38 }
39 item->UpdateWithArcNotificationData(data);
40 }
41
42 void ArcNotificationManager::OnNotificationRemovedFromAndroid(
43 const std::string& key) {
44 Items::iterator it = items_.find(key);
45 if (it != items_.end()) {
46 scoped_ptr<ArcNotificationItem> item(items_.take_and_erase(it));
47
48 item->OnClosedFromAndroid();
49 } else {
50 VLOG(3) << "Android requests to remove a notification (key: " << key
51 << "), but it is already gone.";
52 }
53 }
54
55 void ArcNotificationManager::SendNotificationRemovedFromChrome(
56 const std::string& key) {
57 Items::iterator it = items_.find(key);
58 if (it != items_.end()) {
59 scoped_ptr<ArcNotificationItem> item(items_.take_and_erase(it));
60
61 ArcBridgeService::Get()->SendNotificationEventToAndroid(
Luis Héctor Chávez 2015/12/17 22:49:50 You already have |arc_bridge_|, any reason why you
yoshiki 2015/12/21 19:23:00 Done.
62 key, ARC_NOTIFICATION_EVENT_CLOSED);
63 } else {
64 VLOG(3) << "Chrome requests to remove a notification (key: " << key
65 << "), but it is already gone.";
66 }
67 }
68
69 void ArcNotificationManager::SendNotificationClickedOnChrome(
70 const std::string& key) {
71 if (items_.contains(key)) {
72 ArcBridgeService::Get()->SendNotificationEventToAndroid(
73 key, ARC_NOTIFICATION_EVENT_BODY_CLICKED);
74 } else {
75 VLOG(3) << "Chrome requests to fire a click event on notification (key: "
76 << key << "), but it is gone.";
77 }
78 }
79
80 } // namespace components
Luis Héctor Chávez 2015/12/17 23:11:42 nit: namespace arc.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698