OLD | NEW |
---|---|
(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 "chrome/browser/chromeos/arc/notification/arc_notification_manager.h" | |
6 | |
7 #include "base/stl_util.h" | |
8 #include "chrome/browser/browser_process.h" | |
9 #include "chrome/browser/chromeos/arc/notification/arc_notification_item.h" | |
10 | |
11 namespace chromeos { | |
12 | |
13 ArcNotificationManager::ArcNotificationManager( | |
14 arc::ArcBridgeService* arc_bridge, | |
15 Profile* main_profile) | |
16 : arc_bridge_(arc_bridge), main_profile_(main_profile) { | |
17 // This must be initialized after ArcBridgeService. | |
18 DCHECK(arc_bridge_); | |
19 DCHECK_EQ(arc_bridge_, arc::ArcBridgeService::Get()); | |
20 arc_bridge_->AddNotificationObserver(this); | |
21 } | |
22 | |
23 ArcNotificationManager::~ArcNotificationManager() { | |
24 STLDeleteValues(&items_); | |
25 // This should be free'd before ArcBridgeService. | |
26 DCHECK(arc::ArcBridgeService::Get()); | |
27 DCHECK_EQ(arc_bridge_, arc::ArcBridgeService::Get()); | |
28 arc_bridge_->RemoveNotificationObserver(this); | |
29 } | |
30 | |
31 void ArcNotificationManager::OnNotificationPostedFromAndroid( | |
32 const arc::ArcNotificationData& data) { | |
33 if (items_.find(data.key) == items_.end()) { | |
34 // Show a notification on the primary loged-in user's desktop. | |
35 // TODO(yoshiki): Reconsider when ARC supports multi-user. | |
36 ArcNotificationItem* item = new ArcNotificationItem( | |
37 this, g_browser_process->message_center(), data, main_profile_); | |
38 items_.insert(std::make_pair(data.key, item)); | |
hidehiko
2015/12/11 05:18:00
emplace?
yoshiki
2015/12/14 15:19:30
I changed std::map to ScopedPtrHashMap and use set
| |
39 } else { | |
40 items_[data.key]->UpdateWithArcNotificationData(data); | |
41 } | |
42 } | |
43 | |
44 void ArcNotificationManager::OnNotificationRemovedFromAndroid( | |
45 const std::string& key) { | |
46 Items::iterator it = items_.find(key); | |
47 if (it != items_.end()) { | |
48 ArcNotificationItem* item = it->second; | |
hidehiko
2015/12/11 05:18:00
Let's use scoped_ptr.
yoshiki
2015/12/14 15:19:30
Done.
| |
49 items_.erase(it); | |
50 | |
51 item->OnClosedFromAndroid(); | |
52 delete item; | |
53 } else { | |
54 VLOG(3) << "Android requested to remove a notification (key: " << key | |
55 << "), but it is already gone."; | |
56 } | |
57 } | |
58 | |
59 void ArcNotificationManager::SendNotificationRemovedFromChrome( | |
60 const std::string& key) { | |
61 // Note: This method may be also called by ArcNotificationItem during | |
62 // OnNotificationRemovedFromAndroid(), since that method should removes | |
63 // the notification on Chrome UI. | |
64 | |
65 Items::iterator it = items_.find(key); | |
66 if (it != items_.end()) { | |
67 ArcNotificationItem* item = it->second; | |
hidehiko
2015/12/11 05:18:00
Ditto.
yoshiki
2015/12/14 15:19:30
Done.
| |
68 items_.erase(it); | |
69 | |
70 arc::ArcBridgeService::Get()->SendNotificationEventToAndroid( | |
71 key, arc::ARC_NOTIFICATION_EVENT_CLOSED); | |
72 delete item; | |
73 } | |
74 } | |
75 | |
76 void ArcNotificationManager::SendNotificationClickedOnChrome( | |
77 const std::string& key) { | |
78 Items::iterator it = items_.find(key); | |
79 if (it != items_.end()) { | |
80 arc::ArcBridgeService::Get()->SendNotificationEventToAndroid( | |
81 key, arc::ARC_NOTIFICATION_EVENT_BODY_CLICKED); | |
82 } | |
83 } | |
84 | |
85 } // namespace chromeos | |
OLD | NEW |