| 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 <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/common/system/toast/toast_manager.h" | 10 #include "ash/common/system/toast/toast_manager.h" |
| 11 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "components/arc/arc_bridge_service.h" | 15 #include "components/arc/arc_bridge_service.h" |
| 15 #include "mojo/common/common_type_converters.h" | 16 #include "mojo/common/common_type_converters.h" |
| 16 #include "ui/arc/notification/arc_custom_notification_item.h" | 17 #include "ui/arc/notification/arc_custom_notification_item.h" |
| 17 #include "ui/arc/notification/arc_notification_item.h" | 18 #include "ui/arc/notification/arc_notification_item.h" |
| 18 | 19 |
| 19 namespace arc { | 20 namespace arc { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // Min version to support Create/CloseNotificationWindow. | 24 // Min version to support Create/CloseNotificationWindow. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 : new ArcNotificationItem(this, message_center_, key, | 86 : new ArcNotificationItem(this, message_center_, key, |
| 86 main_profile_id_); | 87 main_profile_id_); |
| 87 // TODO(yoshiki): Use emplacement for performance when it's available. | 88 // TODO(yoshiki): Use emplacement for performance when it's available. |
| 88 auto result = items_.insert(std::make_pair(key, base::WrapUnique(item))); | 89 auto result = items_.insert(std::make_pair(key, base::WrapUnique(item))); |
| 89 DCHECK(result.second); | 90 DCHECK(result.second); |
| 90 it = result.first; | 91 it = result.first; |
| 91 } | 92 } |
| 92 it->second->UpdateWithArcNotificationData(std::move(data)); | 93 it->second->UpdateWithArcNotificationData(std::move(data)); |
| 93 } | 94 } |
| 94 | 95 |
| 95 void ArcNotificationManager::OnNotificationRemoved(const mojo::String& key) { | 96 void ArcNotificationManager::OnNotificationRemoved(const std::string& key) { |
| 96 auto it = items_.find(key.get()); | 97 auto it = items_.find(key); |
| 97 if (it == items_.end()) { | 98 if (it == items_.end()) { |
| 98 VLOG(3) << "Android requests to remove a notification (key: " << key | 99 VLOG(3) << "Android requests to remove a notification (key: " << key |
| 99 << "), but it is already gone."; | 100 << "), but it is already gone."; |
| 100 return; | 101 return; |
| 101 } | 102 } |
| 102 | 103 |
| 103 std::unique_ptr<ArcNotificationItem> item = std::move(it->second); | 104 std::unique_ptr<ArcNotificationItem> item = std::move(it->second); |
| 104 items_.erase(it); | 105 items_.erase(it); |
| 105 item->OnClosedFromAndroid(); | 106 item->OnClosedFromAndroid(); |
| 106 } | 107 } |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 auto* notifications_instance = | 230 auto* notifications_instance = |
| 230 arc_bridge_service()->notifications()->GetInstanceForMethod( | 231 arc_bridge_service()->notifications()->GetInstanceForMethod( |
| 231 "CloseNotificationWindow", kMinVersionNotificationWindow); | 232 "CloseNotificationWindow", kMinVersionNotificationWindow); |
| 232 if (!notifications_instance) | 233 if (!notifications_instance) |
| 233 return; | 234 return; |
| 234 | 235 |
| 235 notifications_instance->CloseNotificationWindow(key); | 236 notifications_instance->CloseNotificationWindow(key); |
| 236 } | 237 } |
| 237 | 238 |
| 238 void ArcNotificationManager::OnToastPosted(mojom::ArcToastDataPtr data) { | 239 void ArcNotificationManager::OnToastPosted(mojom::ArcToastDataPtr data) { |
| 240 const base::string16 text16( |
| 241 base::UTF8ToUTF16(data->text.has_value() ? *data->text : std::string())); |
| 242 const base::string16 dismiss_text16(base::UTF8ToUTF16( |
| 243 data->dismiss_text.has_value() ? *data->dismiss_text : std::string())); |
| 239 ash::WmShell::Get()->toast_manager()->Show( | 244 ash::WmShell::Get()->toast_manager()->Show( |
| 240 ash::ToastData(data->id, data->text.To<base::string16>(), data->duration, | 245 ash::ToastData(data->id, text16, data->duration, dismiss_text16)); |
| 241 data->dismiss_text.To<base::string16>())); | |
| 242 } | 246 } |
| 243 | 247 |
| 244 void ArcNotificationManager::OnToastCancelled(mojom::ArcToastDataPtr data) { | 248 void ArcNotificationManager::OnToastCancelled(mojom::ArcToastDataPtr data) { |
| 245 ash::WmShell::Get()->toast_manager()->Cancel(data->id); | 249 ash::WmShell::Get()->toast_manager()->Cancel(data->id); |
| 246 } | 250 } |
| 247 | 251 |
| 248 } // namespace arc | 252 } // namespace arc |
| OLD | NEW |