| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/arc/notification/arc_notification_manager.h" | 5 #include "ui/arc/notification/arc_notification_manager.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/system/toast/toast_manager.h" | 8 #include "ash/system/toast/toast_manager.h" |
| 9 #include "base/memory/ptr_util.h" |
| 9 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 10 #include "ui/arc/notification/arc_notification_item.h" | 11 #include "ui/arc/notification/arc_notification_item.h" |
| 11 | 12 |
| 12 namespace arc { | 13 namespace arc { |
| 13 | 14 |
| 14 ArcNotificationManager::ArcNotificationManager(ArcBridgeService* bridge_service, | 15 ArcNotificationManager::ArcNotificationManager(ArcBridgeService* bridge_service, |
| 15 const AccountId& main_profile_id) | 16 const AccountId& main_profile_id) |
| 16 : ArcNotificationManager(bridge_service, | 17 : ArcNotificationManager(bridge_service, |
| 17 main_profile_id, | 18 main_profile_id, |
| 18 message_center::MessageCenter::Get()) {} | 19 message_center::MessageCenter::Get()) {} |
| (...skipping 23 matching lines...) Expand all Loading... |
| 42 } | 43 } |
| 43 | 44 |
| 44 notifications_instance->Init(binding_.CreateInterfacePtrAndBind()); | 45 notifications_instance->Init(binding_.CreateInterfacePtrAndBind()); |
| 45 ready_ = true; | 46 ready_ = true; |
| 46 } | 47 } |
| 47 | 48 |
| 48 void ArcNotificationManager::OnNotificationsInstanceClosed() { | 49 void ArcNotificationManager::OnNotificationsInstanceClosed() { |
| 49 DCHECK(ready_); | 50 DCHECK(ready_); |
| 50 while (!items_.empty()) { | 51 while (!items_.empty()) { |
| 51 auto it = items_.begin(); | 52 auto it = items_.begin(); |
| 52 scoped_ptr<ArcNotificationItem> item = std::move(it->second); | 53 std::unique_ptr<ArcNotificationItem> item = std::move(it->second); |
| 53 items_.erase(it); | 54 items_.erase(it); |
| 54 item->OnClosedFromAndroid(false /* by_user */); | 55 item->OnClosedFromAndroid(false /* by_user */); |
| 55 } | 56 } |
| 56 ready_ = false; | 57 ready_ = false; |
| 57 } | 58 } |
| 58 | 59 |
| 59 void ArcNotificationManager::OnNotificationPosted(ArcNotificationDataPtr data) { | 60 void ArcNotificationManager::OnNotificationPosted(ArcNotificationDataPtr data) { |
| 60 const std::string& key = data->key; | 61 const std::string& key = data->key; |
| 61 auto it = items_.find(key); | 62 auto it = items_.find(key); |
| 62 if (it == items_.end()) { | 63 if (it == items_.end()) { |
| 63 // Show a notification on the primary loged-in user's desktop. | 64 // Show a notification on the primary loged-in user's desktop. |
| 64 // TODO(yoshiki): Reconsider when ARC supports multi-user. | 65 // TODO(yoshiki): Reconsider when ARC supports multi-user. |
| 65 ArcNotificationItem* item = | 66 ArcNotificationItem* item = |
| 66 new ArcNotificationItem(this, message_center_, key, main_profile_id_); | 67 new ArcNotificationItem(this, message_center_, key, main_profile_id_); |
| 67 // TODO(yoshiki): Use emplacement for performance when it's available. | 68 // TODO(yoshiki): Use emplacement for performance when it's available. |
| 68 auto result = items_.insert(std::make_pair(key, make_scoped_ptr(item))); | 69 auto result = items_.insert(std::make_pair(key, base::WrapUnique(item))); |
| 69 DCHECK(result.second); | 70 DCHECK(result.second); |
| 70 it = result.first; | 71 it = result.first; |
| 71 } | 72 } |
| 72 it->second->UpdateWithArcNotificationData(*data); | 73 it->second->UpdateWithArcNotificationData(*data); |
| 73 } | 74 } |
| 74 | 75 |
| 75 void ArcNotificationManager::OnNotificationRemoved(const mojo::String& key) { | 76 void ArcNotificationManager::OnNotificationRemoved(const mojo::String& key) { |
| 76 auto it = items_.find(key.get()); | 77 auto it = items_.find(key.get()); |
| 77 if (it == items_.end()) { | 78 if (it == items_.end()) { |
| 78 VLOG(3) << "Android requests to remove a notification (key: " << key | 79 VLOG(3) << "Android requests to remove a notification (key: " << key |
| 79 << "), but it is already gone."; | 80 << "), but it is already gone."; |
| 80 return; | 81 return; |
| 81 } | 82 } |
| 82 | 83 |
| 83 scoped_ptr<ArcNotificationItem> item = std::move(it->second); | 84 std::unique_ptr<ArcNotificationItem> item = std::move(it->second); |
| 84 items_.erase(it); | 85 items_.erase(it); |
| 85 item->OnClosedFromAndroid(true /* by_user */); | 86 item->OnClosedFromAndroid(true /* by_user */); |
| 86 } | 87 } |
| 87 | 88 |
| 88 void ArcNotificationManager::SendNotificationRemovedFromChrome( | 89 void ArcNotificationManager::SendNotificationRemovedFromChrome( |
| 89 const std::string& key) { | 90 const std::string& key) { |
| 90 auto it = items_.find(key); | 91 auto it = items_.find(key); |
| 91 if (it == items_.end()) { | 92 if (it == items_.end()) { |
| 92 VLOG(3) << "Chrome requests to remove a notification (key: " << key | 93 VLOG(3) << "Chrome requests to remove a notification (key: " << key |
| 93 << "), but it is already gone."; | 94 << "), but it is already gone."; |
| 94 return; | 95 return; |
| 95 } | 96 } |
| 96 | 97 |
| 97 // The removed ArcNotificationItem needs to live in this scope, since the | 98 // The removed ArcNotificationItem needs to live in this scope, since the |
| 98 // given argument |key| may be a part of the removed item. | 99 // given argument |key| may be a part of the removed item. |
| 99 scoped_ptr<ArcNotificationItem> item = std::move(it->second); | 100 std::unique_ptr<ArcNotificationItem> item = std::move(it->second); |
| 100 items_.erase(it); | 101 items_.erase(it); |
| 101 | 102 |
| 102 auto notifications_instance = arc_bridge_service()->notifications_instance(); | 103 auto notifications_instance = arc_bridge_service()->notifications_instance(); |
| 103 | 104 |
| 104 // On shutdown, the ARC channel may quit earlier then notifications. | 105 // On shutdown, the ARC channel may quit earlier then notifications. |
| 105 if (!notifications_instance) { | 106 if (!notifications_instance) { |
| 106 VLOG(2) << "ARC Notification (key: " << key | 107 VLOG(2) << "ARC Notification (key: " << key |
| 107 << ") is closed, but the ARC channel has already gone."; | 108 << ") is closed, but the ARC channel has already gone."; |
| 108 return; | 109 return; |
| 109 } | 110 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 179 |
| 179 void ArcNotificationManager::OnToastPosted(ArcToastDataPtr data) { | 180 void ArcNotificationManager::OnToastPosted(ArcToastDataPtr data) { |
| 180 ash::Shell::GetInstance()->toast_manager()->Show(data->text, data->duration); | 181 ash::Shell::GetInstance()->toast_manager()->Show(data->text, data->duration); |
| 181 } | 182 } |
| 182 | 183 |
| 183 void ArcNotificationManager::OnToastCancelled(ArcToastDataPtr data) { | 184 void ArcNotificationManager::OnToastCancelled(ArcToastDataPtr data) { |
| 184 // TODO(yoshiki): Implement cancel. | 185 // TODO(yoshiki): Implement cancel. |
| 185 } | 186 } |
| 186 | 187 |
| 187 } // namespace arc | 188 } // namespace arc |
| OLD | NEW |