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

Side by Side Diff: ui/arc/notification/arc_notification_manager.cc

Issue 2723143002: Add unittests of ArcCustomNotificationView (Closed)
Patch Set: Created 3 years, 9 months 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
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 "base/strings/utf_string_conversions.h"
15 #include "components/arc/arc_bridge_service.h" 15 #include "components/arc/arc_bridge_service.h"
16 #include "ui/arc/notification/arc_custom_notification_item.h" 16 #include "ui/arc/notification/arc_notification_item_impl.h"
17 #include "ui/arc/notification/arc_notification_item.h"
18 17
19 namespace arc { 18 namespace arc {
20 19
21 ArcNotificationManager::ArcNotificationManager(ArcBridgeService* bridge_service, 20 ArcNotificationManager::ArcNotificationManager(ArcBridgeService* bridge_service,
22 const AccountId& main_profile_id) 21 const AccountId& main_profile_id)
23 : ArcNotificationManager(bridge_service, 22 : ArcNotificationManager(bridge_service,
24 main_profile_id, 23 main_profile_id,
25 message_center::MessageCenter::Get()) {} 24 message_center::MessageCenter::Get()) {}
26 25
27 ArcNotificationManager::ArcNotificationManager( 26 ArcNotificationManager::ArcNotificationManager(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 item->OnClosedFromAndroid(); 58 item->OnClosedFromAndroid();
60 } 59 }
61 ready_ = false; 60 ready_ = false;
62 } 61 }
63 62
64 void ArcNotificationManager::OnNotificationPosted( 63 void ArcNotificationManager::OnNotificationPosted(
65 mojom::ArcNotificationDataPtr data) { 64 mojom::ArcNotificationDataPtr data) {
66 const std::string& key = data->key; 65 const std::string& key = data->key;
67 auto it = items_.find(key); 66 auto it = items_.find(key);
68 if (it == items_.end()) { 67 if (it == items_.end()) {
69 // Old client with version < 5 would have use_custom_notification default,
70 // which is false.
71 const bool use_custom_notification = data->use_custom_notification;
72 // Show a notification on the primary logged-in user's desktop. 68 // Show a notification on the primary logged-in user's desktop.
73 // TODO(yoshiki): Reconsider when ARC supports multi-user. 69 // TODO(yoshiki): Reconsider when ARC supports multi-user.
74 ArcNotificationItem* item = 70 ArcNotificationItem* item = new ArcNotificationItemImpl(
hidehiko 2017/03/02 15:38:17 nit: maybe auto item = base::MakeUnique<>() then y
75 use_custom_notification 71 this, message_center_, key, main_profile_id_);
76 ? new ArcCustomNotificationItem(this, message_center_, key,
77 main_profile_id_)
78 : new ArcNotificationItem(this, message_center_, key,
79 main_profile_id_);
80 // TODO(yoshiki): Use emplacement for performance when it's available. 72 // TODO(yoshiki): Use emplacement for performance when it's available.
81 auto result = items_.insert(std::make_pair(key, base::WrapUnique(item))); 73 auto result = items_.insert(std::make_pair(key, base::WrapUnique(item)));
82 DCHECK(result.second); 74 DCHECK(result.second);
83 it = result.first; 75 it = result.first;
84 } 76 }
85 it->second->UpdateWithArcNotificationData(std::move(data)); 77 it->second->UpdateWithArcNotificationData(std::move(data));
86 } 78 }
87 79
88 void ArcNotificationManager::OnNotificationRemoved(const std::string& key) { 80 void ArcNotificationManager::OnNotificationRemoved(const std::string& key) {
89 auto it = items_.find(key); 81 auto it = items_.find(key);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 data->dismiss_text.has_value() ? *data->dismiss_text : std::string())); 239 data->dismiss_text.has_value() ? *data->dismiss_text : std::string()));
248 ash::WmShell::Get()->toast_manager()->Show( 240 ash::WmShell::Get()->toast_manager()->Show(
249 ash::ToastData(data->id, text16, data->duration, dismiss_text16)); 241 ash::ToastData(data->id, text16, data->duration, dismiss_text16));
250 } 242 }
251 243
252 void ArcNotificationManager::OnToastCancelled(mojom::ArcToastDataPtr data) { 244 void ArcNotificationManager::OnToastCancelled(mojom::ArcToastDataPtr data) {
253 ash::WmShell::Get()->toast_manager()->Cancel(data->id); 245 ash::WmShell::Get()->toast_manager()->Cancel(data->id);
254 } 246 }
255 247
256 } // namespace arc 248 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698