Chromium Code Reviews| 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::ArcBridgeService::Get()); | |
|
elijahtaylor1
2015/12/09 06:41:25
comments on https://codereview.chromium.org/149572
yoshiki
2015/12/09 17:11:09
I want to ensure that this is initialized after th
| |
| 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. | |
|
elijahtaylor1
2015/12/09 06:41:26
is this actually guaranteed?
yoshiki
2015/12/09 17:11:09
It's guaranteed in the definition order in chrome_
| |
| 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 // Show a notification on the main user's desktop as for now. | |
| 34 // TODO(yoshiki): Consider multi-user. | |
|
elijahtaylor1
2015/12/09 06:41:26
I don't know how multi-user works but I would assu
yoshiki
2015/12/09 17:11:09
I meant that "multi-user" is simultaneous multi-us
| |
| 35 ArcNotificationItem* item = new ArcNotificationItem( | |
| 36 this, g_browser_process->message_center(), data, main_profile_); | |
| 37 items_.insert(make_pair(data.key, item)); | |
| 38 } | |
| 39 | |
| 40 void ArcNotificationManager::OnNotificationRemovedFromAndroid( | |
| 41 const std::string& key) { | |
| 42 Items::iterator it = items_.find(key); | |
| 43 if (it != items_.end()) { | |
| 44 ArcNotificationItem* item = it->second; | |
| 45 items_.erase(it); | |
| 46 | |
| 47 item->OnClosedFromAndroid(); | |
| 48 delete item; | |
| 49 } else { | |
| 50 VLOG(3) << "Android requested to remove the notification (key: " << key | |
|
elijahtaylor1
2015/12/09 06:41:25
s/the/a/
yoshiki
2015/12/09 17:11:09
Done.
| |
| 51 << "), but it has already gone."; | |
|
elijahtaylor1
2015/12/09 06:41:26
s/has/is/
yoshiki
2015/12/09 17:11:09
Done.
| |
| 52 } | |
| 53 } | |
| 54 | |
| 55 void ArcNotificationManager::NotifyNotificationRemovedFromChrome( | |
| 56 const std::string& key) { | |
| 57 // Note: This method may be also called by ArcNotificationItem during | |
| 58 // OnNotificationRemovedFromAndroid(), since that method should removes | |
| 59 // the notification on Chrome UI. | |
| 60 | |
| 61 Items::iterator it = items_.find(key); | |
| 62 if (it != items_.end()) { | |
| 63 ArcNotificationItem* item = it->second; | |
| 64 items_.erase(it); | |
| 65 | |
| 66 arc::ArcBridgeService::Get()->SendNotificationEventToAndroid( | |
| 67 key, arc::ArcNotificationEvent::CLOSED); | |
| 68 delete item; | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 void ArcNotificationManager::NotifyNotificationClickedFromChrome( | |
| 73 const std::string& key) { | |
| 74 Items::iterator it = items_.find(key); | |
| 75 if (it != items_.end()) { | |
| 76 arc::ArcBridgeService::Get()->SendNotificationEventToAndroid( | |
| 77 key, arc::ArcNotificationEvent::BODY_CLICKED); | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 } // namespace chromeos | |
| OLD | NEW |