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

Side by Side Diff: chrome/browser/signin/easy_unlock_notification_controller_chromeos.cc

Issue 2968323002: [EasyUnlock] Introduce EasyUnlockNotificationController (Closed)
Patch Set: fix unittests Created 3 years, 5 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
(Empty)
1 // Copyright 2017 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/signin/easy_unlock_notification_controller_chromeos.h"
6
7 #include "ash/system/devicetype_utils.h"
8 #include "base/guid.h"
9 #include "base/memory/ptr_util.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/ui/chrome_pages.h"
12 #include "chrome/grit/generated_resources.h"
13 #include "chrome/grit/theme_resources.h"
14 #include "components/proximity_auth/screenlock_bridge.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/message_center/message_center_types.h"
18 #include "ui/message_center/notification_types.h"
19
20 namespace {
21
22 const char kEasyUnlockChromebookAddedNotifierId[] =
23 "easyunlock_notification_ids.chromebook_added";
24
25 const char kEasyUnlockPairingChangeNotifierId[] =
26 "easyunlock_notification_ids.pairing_change";
27
28 const char kEasyUnlockPairingChangeAppliedNotifierId[] =
29 "easyunlock_notification_ids.pairing_change_applied";
30
31 const char kEasyUnlockPromotionNotifierId[] =
32 "easyunlock_notification_ids.promotion";
33
34 const char kLockScreenSettingsSubpage[] = "lockScreen";
35
36 // Convenience function for creating a Notification.
37 std::unique_ptr<message_center::Notification> CreateNotification(
38 const std::string& id,
39 const base::string16& title,
40 const base::string16& message,
41 const gfx::Image& icon,
42 const message_center::RichNotificationData& rich_notification_data,
43 message_center::NotificationDelegate* delegate) {
44 return base::MakeUnique<message_center::Notification>(
45 message_center::NotificationType::NOTIFICATION_TYPE_SIMPLE, id, title,
46 message, icon, base::string16() /* display_source */,
47 GURL() /* origin_url */,
48 message_center::NotifierId(
49 message_center::NotifierId::NotifierType::SYSTEM_COMPONENT, id),
50 rich_notification_data, delegate);
51 }
52
53 } // namespace
54
55 EasyUnlockNotificationControllerChromeOS::
56 EasyUnlockNotificationControllerChromeOS(
57 Profile* profile,
58 message_center::MessageCenter* message_center)
59 : profile_(profile),
60 message_center_(message_center),
61 weak_ptr_factory_(this) {}
62
63 EasyUnlockNotificationControllerChromeOS::
64 ~EasyUnlockNotificationControllerChromeOS() {}
65
66 void EasyUnlockNotificationControllerChromeOS::
67 ShowChromebookAddedNotification() {
68 message_center::RichNotificationData rich_notification_data;
69 rich_notification_data.buttons.push_back(
70 message_center::ButtonInfo(l10n_util::GetStringUTF16(
71 IDS_EASY_UNLOCK_CHROMEBOOK_ADDED_NOTIFICATION_ABOUT_BUTTON)));
72
73 ShowNotification(CreateNotification(
74 kEasyUnlockChromebookAddedNotifierId,
75 l10n_util::GetStringUTF16(
76 IDS_EASY_UNLOCK_CHROMEBOOK_ADDED_NOTIFICATION_TITLE),
77 l10n_util::GetStringFUTF16(
78 IDS_EASY_UNLOCK_CHROMEBOOK_ADDED_NOTIFICATION_MESSAGE,
79 ash::GetChromeOSDeviceName()),
80 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
81 IDR_NOTIFICATION_EASYUNLOCK_ENABLED),
82 rich_notification_data,
83 new NotificationDelegate(kEasyUnlockChromebookAddedNotifierId,
84 weak_ptr_factory_.GetWeakPtr())));
85 }
86
87 void EasyUnlockNotificationControllerChromeOS::ShowPairingChangeNotification() {
88 message_center::RichNotificationData rich_notification_data;
89 rich_notification_data.buttons.push_back(
90 message_center::ButtonInfo(l10n_util::GetStringUTF16(
91 IDS_EASY_UNLOCK_PAIRING_CHANGED_NOTIFICATION_UPDATE_BUTTON)));
92 rich_notification_data.buttons.push_back(
93 message_center::ButtonInfo(l10n_util::GetStringUTF16(
94 IDS_EASY_UNLOCK_CHROMEBOOK_ADDED_NOTIFICATION_ABOUT_BUTTON)));
95
96 ShowNotification(CreateNotification(
97 kEasyUnlockPairingChangeNotifierId,
98 l10n_util::GetStringUTF16(
99 IDS_EASY_UNLOCK_PAIRING_CHANGED_NOTIFICATION_TITLE),
100 l10n_util::GetStringFUTF16(
101 IDS_EASY_UNLOCK_PAIRING_CHANGED_NOTIFICATION_MESSAGE,
102 ash::GetChromeOSDeviceName()),
103 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
104 IDR_NOTIFICATION_EASYUNLOCK_ENABLED),
105 rich_notification_data,
106 new NotificationDelegate(kEasyUnlockPairingChangeNotifierId,
107 weak_ptr_factory_.GetWeakPtr())));
108 }
109
110 void EasyUnlockNotificationControllerChromeOS::
111 ShowPairingChangeAppliedNotification(const std::string& phone_name) {
112 // Remove the pairing change notification if it is still being shown.
113 message_center_->RemoveNotification(kEasyUnlockPairingChangeNotifierId,
114 false /* by_user */);
115
116 message_center::RichNotificationData rich_notification_data;
117 rich_notification_data.buttons.push_back(
118 message_center::ButtonInfo(l10n_util::GetStringUTF16(
119 IDS_EASY_UNLOCK_CHROMEBOOK_ADDED_NOTIFICATION_ABOUT_BUTTON)));
120
121 ShowNotification(CreateNotification(
122 kEasyUnlockPairingChangeAppliedNotifierId,
123 l10n_util::GetStringUTF16(
124 IDS_EASY_UNLOCK_PAIRING_CHANGE_APPLIED_NOTIFICATION_TITLE),
125 l10n_util::GetStringFUTF16(
126 IDS_EASY_UNLOCK_PAIRING_CHANGE_APPLIED_NOTIFICATION_MESSAGE,
127 base::UTF8ToUTF16(phone_name), ash::GetChromeOSDeviceName()),
128 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
129 IDR_NOTIFICATION_EASYUNLOCK_ENABLED),
130 rich_notification_data,
131 new NotificationDelegate(kEasyUnlockPairingChangeAppliedNotifierId,
132 weak_ptr_factory_.GetWeakPtr())));
133 }
134
135 void EasyUnlockNotificationControllerChromeOS::ShowPromotionNotification() {
136 message_center::RichNotificationData rich_notification_data;
137 rich_notification_data.buttons.push_back(
138 message_center::ButtonInfo(l10n_util::GetStringUTF16(
139 IDS_EASY_UNLOCK_SETUP_NOTIFICATION_BUTTON_TITLE)));
140
141 ShowNotification(CreateNotification(
142 kEasyUnlockPromotionNotifierId,
143 l10n_util::GetStringUTF16(IDS_EASY_UNLOCK_SETUP_NOTIFICATION_TITLE),
144 l10n_util::GetStringFUTF16(IDS_EASY_UNLOCK_SETUP_NOTIFICATION_MESSAGE,
145 ash::GetChromeOSDeviceName()),
146 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
147 IDR_NOTIFICATION_EASYUNLOCK_PROMO),
148 rich_notification_data,
149 new NotificationDelegate(kEasyUnlockPromotionNotifierId,
150 weak_ptr_factory_.GetWeakPtr())));
151 }
152
153 void EasyUnlockNotificationControllerChromeOS::ShowNotification(
154 std::unique_ptr<message_center::Notification> notification) {
155 notification->SetSystemPriority();
156 std::string notification_id = notification->id();
157 if (message_center_->FindVisibleNotificationById(notification_id)) {
158 message_center_->UpdateNotification(notification_id,
159 std::move(notification));
160 } else {
161 message_center_->AddNotification(std::move(notification));
162 }
163 }
164
165 void EasyUnlockNotificationControllerChromeOS::LaunchEasyUnlockSettings() {
166 chrome::ShowSettingsSubPageForProfile(profile_, kLockScreenSettingsSubpage);
167 }
168
169 void EasyUnlockNotificationControllerChromeOS::LockScreen() {
170 proximity_auth::ScreenlockBridge::Get()->Lock();
171 }
172
173 EasyUnlockNotificationControllerChromeOS::NotificationDelegate::
174 NotificationDelegate(
175 const std::string& notification_id,
176 const base::WeakPtr<EasyUnlockNotificationControllerChromeOS>&
177 notification_controller)
178 : notification_id_(notification_id),
179 notification_controller_(notification_controller) {}
180
181 EasyUnlockNotificationControllerChromeOS::NotificationDelegate::
182 ~NotificationDelegate() {}
183
184 void EasyUnlockNotificationControllerChromeOS::NotificationDelegate::Click() {
185 if (!notification_controller_)
186 return;
187
188 if (notification_id_ == kEasyUnlockChromebookAddedNotifierId ||
189 notification_id_ == kEasyUnlockPairingChangeAppliedNotifierId ||
190 notification_id_ == kEasyUnlockPromotionNotifierId)
191 notification_controller_->LaunchEasyUnlockSettings();
192 }
193
194 void EasyUnlockNotificationControllerChromeOS::NotificationDelegate::
195 ButtonClick(int button_index) {
196 if (!notification_controller_)
197 return;
198
199 if (notification_id_ == kEasyUnlockChromebookAddedNotifierId ||
200 notification_id_ == kEasyUnlockPairingChangeAppliedNotifierId ||
201 notification_id_ == kEasyUnlockPromotionNotifierId) {
202 notification_controller_->LaunchEasyUnlockSettings();
203 } else if (notification_id_ == kEasyUnlockPairingChangeNotifierId) {
204 if (button_index == 0) {
205 notification_controller_->LockScreen();
206 } else if (button_index == 1) {
207 notification_controller_->LaunchEasyUnlockSettings();
208 }
209 }
210 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698