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

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: . 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 arc::ArcBridgeService* arc_bridge,
hidehiko 2015/12/17 07:47:51 Maybe, it's time to remove "arc::" from this CL :-
yoshiki 2015/12/17 19:15:14 Done.
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_, arc::ArcBridgeService::Get());
19 arc_bridge_->AddNotificationObserver(this);
20 }
21
22 ArcNotificationManager::~ArcNotificationManager() {
23 // This should be free'd before ArcBridgeService.
24 DCHECK(arc::ArcBridgeService::Get());
25 DCHECK_EQ(arc_bridge_, arc::ArcBridgeService::Get());
26 arc_bridge_->RemoveNotificationObserver(this);
27 }
28
29 void ArcNotificationManager::OnNotificationPostedFromAndroid(
30 const arc::ArcNotificationData& data) {
31 if (items_.get(data.key) == nullptr) {
hidehiko 2015/12/17 07:47:51 nit: contains()? Or, if you do not want to search
yoshiki 2015/12/17 19:15:14 Done.
32 // Show a notification on the primary loged-in user's desktop.
33 // TODO(yoshiki): Reconsider when ARC supports multi-user.
34 scoped_ptr<ArcNotificationItem> item(new ArcNotificationItem(
35 this, message_center::MessageCenter::Get(), data, main_profile_id_));
36 items_.set(data.key, item.Pass());
37 }
38 items_.get(data.key)->UpdateWithArcNotificationData(data);
39 }
40
41 void ArcNotificationManager::OnNotificationRemovedFromAndroid(
42 const std::string& key) {
43 Items::iterator it = items_.find(key);
44 if (it != items_.end()) {
45 scoped_ptr<ArcNotificationItem> item(items_.take_and_erase(it));
46
47 item->OnClosedFromAndroid();
48 } else {
49 VLOG(3) << "Android requested to remove a notification (key: " << key
50 << "), but it is already gone.";
51 }
52 }
53
54 void ArcNotificationManager::SendNotificationRemovedFromChrome(
55 const std::string& key) {
56 // Note: This method may be also called by ArcNotificationItem during
57 // OnNotificationRemovedFromAndroid(), since that method should removes
elijahtaylor1 2015/12/16 02:34:37 s/removes/remove
yoshiki 2015/12/17 19:15:14 Thanks, but I removed the comment.
58 // the notification on Chrome UI.
elijahtaylor1 2015/12/16 02:34:37 s/on/in
59
60 Items::iterator it = items_.find(key);
61 if (it != items_.end()) {
62 scoped_ptr<ArcNotificationItem> item(items_.take_and_erase(it));
63
64 arc::ArcBridgeService::Get()->SendNotificationEventToAndroid(
65 key, arc::ARC_NOTIFICATION_EVENT_CLOSED);
66 }
hidehiko 2015/12/17 07:47:51 nit: maybe logging on error?
yoshiki 2015/12/17 19:15:14 Done. And to make the logging code simpler, I adde
67 }
68
69 void ArcNotificationManager::SendNotificationClickedOnChrome(
70 const std::string& key) {
71 if (items_.contains(key)) {
72 arc::ArcBridgeService::Get()->SendNotificationEventToAndroid(
73 key, arc::ARC_NOTIFICATION_EVENT_BODY_CLICKED);
74 }
hidehiko 2015/12/17 07:47:51 Ditto.
yoshiki 2015/12/17 19:15:14 Done.
75 }
76
77 } // namespace components
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698