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

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

Issue 2968323002: [EasyUnlock] Introduce EasyUnlockNotificationController (Closed)
Patch Set: Notification test. 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 kLockScreenSettingsSubpage[] = "lockScreen";
32
33 std::unique_ptr<message_center::Notification> CreateNotification(
34 const std::string& id,
35 const base::string16& title,
36 const base::string16& message,
37 const gfx::Image& icon,
38 const message_center::RichNotificationData rich_notification_data) {
Peter Beverloo 2017/07/07 18:36:58 nit: const& (saves the unnecessary copy)
Tim Song 2017/07/07 19:54:04 Done.
39 return base::MakeUnique<message_center::Notification>(
40 message_center::NotificationType::NOTIFICATION_TYPE_SIMPLE, id, title,
41 message, icon, base::string16() /* display_source */,
42 GURL() /* origin_url */,
43 message_center::NotifierId(
44 message_center::NotifierId::NotifierType::SYSTEM_COMPONENT, id),
45 rich_notification_data, nullptr);
46 }
47
48 } // namespace
49
50 EasyUnlockNotificationControllerChromeOS::
51 EasyUnlockNotificationControllerChromeOS(
52 Profile* profile,
53 message_center::MessageCenter* message_center)
54 : profile_(profile), message_center_(message_center) {
55 message_center_->AddObserver(this);
Peter Beverloo 2017/07/07 18:36:58 Please provide a delegate to the Notification obje
Tim Song 2017/07/07 19:54:04 Done.
56 }
57
58 EasyUnlockNotificationControllerChromeOS::
59 ~EasyUnlockNotificationControllerChromeOS() {
60 message_center_->RemoveObserver(this);
61 }
62
63 void EasyUnlockNotificationControllerChromeOS::
64 ShowChromebookAddedNotification() {
65 message_center::RichNotificationData rich_notification_data;
66 rich_notification_data.buttons.push_back(
67 message_center::ButtonInfo(l10n_util::GetStringUTF16(
68 IDS_EASY_UNLOCK_CHROMEBOOK_ADDED_NOTIFICATION_ABOUT_BUTTON)));
69
70 ShowNotification(CreateNotification(
71 kEasyUnlockChromebookAddedNotifierId,
72 l10n_util::GetStringUTF16(
73 IDS_EASY_UNLOCK_CHROMEBOOK_ADDED_NOTIFICATION_TITLE),
74 l10n_util::GetStringFUTF16(
75 IDS_EASY_UNLOCK_CHROMEBOOK_ADDED_NOTIFICATION_MESSAGE,
76 ash::GetChromeOSDeviceName()),
77 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
78 IDR_NOTIFICATION_EASYUNLOCK_ENABLED),
79 rich_notification_data));
80 }
81
82 void EasyUnlockNotificationControllerChromeOS::ShowPairingChangeNotification() {
83 message_center::RichNotificationData rich_notification_data;
84 rich_notification_data.buttons.push_back(
85 message_center::ButtonInfo(l10n_util::GetStringUTF16(
86 IDS_EASY_UNLOCK_PAIRING_CHANGED_NOTIFICATION_UPDATE_BUTTON)));
87 rich_notification_data.buttons.push_back(
88 message_center::ButtonInfo(l10n_util::GetStringUTF16(
89 IDS_EASY_UNLOCK_CHROMEBOOK_ADDED_NOTIFICATION_ABOUT_BUTTON)));
90
91 ShowNotification(CreateNotification(
92 kEasyUnlockPairingChangeNotifierId,
93 l10n_util::GetStringUTF16(
94 IDS_EASY_UNLOCK_PAIRING_CHANGED_NOTIFICATION_TITLE),
95 l10n_util::GetStringFUTF16(
96 IDS_EASY_UNLOCK_PAIRING_CHANGED_NOTIFICATION_MESSAGE,
97 ash::GetChromeOSDeviceName()),
98 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
99 IDR_NOTIFICATION_EASYUNLOCK_ENABLED),
100 rich_notification_data));
101 }
102
103 void EasyUnlockNotificationControllerChromeOS::
104 ShowPairingChangeAppliedNotification(const std::string& phone_name) {
105 // Remove the pairing change notification if it is still being shown.
106 message_center_->RemoveNotification(kEasyUnlockPairingChangeNotifierId,
107 false /* by_user */);
108
109 message_center::RichNotificationData rich_notification_data;
110 rich_notification_data.buttons.push_back(
111 message_center::ButtonInfo(l10n_util::GetStringUTF16(
112 IDS_EASY_UNLOCK_CHROMEBOOK_ADDED_NOTIFICATION_ABOUT_BUTTON)));
113
114 ShowNotification(CreateNotification(
115 kEasyUnlockPairingChangeAppliedNotifierId,
116 l10n_util::GetStringUTF16(
117 IDS_EASY_UNLOCK_PAIRING_CHANGE_APPLIED_NOTIFICATION_TITLE),
118 l10n_util::GetStringFUTF16(
119 IDS_EASY_UNLOCK_PAIRING_CHANGE_APPLIED_NOTIFICATION_MESSAGE,
120 base::UTF8ToUTF16(phone_name), ash::GetChromeOSDeviceName()),
121 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
122 IDR_NOTIFICATION_EASYUNLOCK_ENABLED),
123 rich_notification_data));
124 }
125
126 void EasyUnlockNotificationControllerChromeOS::ShowNotification(
127 std::unique_ptr<message_center::Notification> notification) {
128 notification->SetSystemPriority();
129 std::string notification_id = notification->id();
130 if (message_center_->FindVisibleNotificationById(notification_id)) {
131 message_center_->UpdateNotification(notification_id,
132 std::move(notification));
133 } else {
134 message_center_->AddNotification(std::move(notification));
135 }
136 }
137
138 void EasyUnlockNotificationControllerChromeOS::OnNotificationClicked(
139 const std::string& notification_id) {
140 if (notification_id == kEasyUnlockChromebookAddedNotifierId ||
141 notification_id == kEasyUnlockPairingChangeAppliedNotifierId)
142 LaunchEasyUnlockSettings();
143 }
144
145 void EasyUnlockNotificationControllerChromeOS::OnNotificationButtonClicked(
146 const std::string& notification_id,
147 int button_index) {
148 if (notification_id == kEasyUnlockChromebookAddedNotifierId ||
149 notification_id == kEasyUnlockPairingChangeAppliedNotifierId) {
150 LaunchEasyUnlockSettings();
151 } else if (notification_id == kEasyUnlockPairingChangeNotifierId) {
152 if (button_index == 0) {
153 LockScreen();
154 } else if (button_index == 1) {
155 LaunchEasyUnlockSettings();
156 }
157 }
158 }
159
160 void EasyUnlockNotificationControllerChromeOS::LaunchEasyUnlockSettings() {
161 chrome::ShowSettingsSubPageForProfile(profile_, kLockScreenSettingsSubpage);
162 }
163
164 void EasyUnlockNotificationControllerChromeOS::LockScreen() {
165 proximity_auth::ScreenlockBridge::Get()->Lock();
166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698