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

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

Issue 2845003002: Merge ArcNotificationItem and ArcCustomNotificationItem (Closed)
Patch Set: Rebased Created 3 years, 7 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
« no previous file with comments | « ui/arc/notification/arc_notification_item_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/shell.h" 10 #include "ash/shell.h"
11 #include "ash/system/toast/toast_manager.h" 11 #include "ash/system/toast/toast_manager.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 auto item = base::MakeUnique<ArcNotificationItemImpl>(
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, std::move(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->OnUpdatedFromAndroid(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);
90 if (it == items_.end()) { 82 if (it == items_.end()) {
91 VLOG(3) << "Android requests to remove a notification (key: " << key 83 VLOG(3) << "Android requests to remove a notification (key: " << key
92 << "), but it is already gone."; 84 << "), but it is already gone.";
93 return; 85 return;
94 } 86 }
95 87
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 data->dismiss_text.has_value() ? *data->dismiss_text : std::string())); 267 data->dismiss_text.has_value() ? *data->dismiss_text : std::string()));
276 ash::Shell::Get()->toast_manager()->Show( 268 ash::Shell::Get()->toast_manager()->Show(
277 ash::ToastData(data->id, text16, data->duration, dismiss_text16)); 269 ash::ToastData(data->id, text16, data->duration, dismiss_text16));
278 } 270 }
279 271
280 void ArcNotificationManager::OnToastCancelled(mojom::ArcToastDataPtr data) { 272 void ArcNotificationManager::OnToastCancelled(mojom::ArcToastDataPtr data) {
281 ash::Shell::Get()->toast_manager()->Cancel(data->id); 273 ash::Shell::Get()->toast_manager()->Cancel(data->id);
282 } 274 }
283 275
284 } // namespace arc 276 } // namespace arc
OLDNEW
« no previous file with comments | « ui/arc/notification/arc_notification_item_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698