Index: chrome/browser/signin/easy_unlock_notification_controller_chromeos.cc |
diff --git a/chrome/browser/signin/easy_unlock_notification_controller_chromeos.cc b/chrome/browser/signin/easy_unlock_notification_controller_chromeos.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4b9da5f2e26739632cf05cabfdc36c91174822a5 |
--- /dev/null |
+++ b/chrome/browser/signin/easy_unlock_notification_controller_chromeos.cc |
@@ -0,0 +1,166 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/signin/easy_unlock_notification_controller_chromeos.h" |
+ |
+#include "ash/system/devicetype_utils.h" |
+#include "base/guid.h" |
+#include "base/memory/ptr_util.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "chrome/browser/ui/chrome_pages.h" |
+#include "chrome/grit/generated_resources.h" |
+#include "chrome/grit/theme_resources.h" |
+#include "components/proximity_auth/screenlock_bridge.h" |
+#include "ui/base/l10n/l10n_util.h" |
+#include "ui/base/resource/resource_bundle.h" |
+#include "ui/message_center/message_center_types.h" |
+#include "ui/message_center/notification_types.h" |
+ |
+namespace { |
+ |
+const char kEasyUnlockChromebookAddedNotifierId[] = |
+ "easyunlock_notification_ids.chromebook_added"; |
+ |
+const char kEasyUnlockPairingChangeNotifierId[] = |
+ "easyunlock_notification_ids.pairing_change"; |
+ |
+const char kEasyUnlockPairingChangeAppliedNotifierId[] = |
+ "easyunlock_notification_ids.pairing_change_applied"; |
+ |
+const char kLockScreenSettingsSubpage[] = "lockScreen"; |
+ |
+std::unique_ptr<message_center::Notification> CreateNotification( |
+ const std::string& id, |
+ const base::string16& title, |
+ const base::string16& message, |
+ const gfx::Image& icon, |
+ 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.
|
+ return base::MakeUnique<message_center::Notification>( |
+ message_center::NotificationType::NOTIFICATION_TYPE_SIMPLE, id, title, |
+ message, icon, base::string16() /* display_source */, |
+ GURL() /* origin_url */, |
+ message_center::NotifierId( |
+ message_center::NotifierId::NotifierType::SYSTEM_COMPONENT, id), |
+ rich_notification_data, nullptr); |
+} |
+ |
+} // namespace |
+ |
+EasyUnlockNotificationControllerChromeOS:: |
+ EasyUnlockNotificationControllerChromeOS( |
+ Profile* profile, |
+ message_center::MessageCenter* message_center) |
+ : profile_(profile), message_center_(message_center) { |
+ 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.
|
+} |
+ |
+EasyUnlockNotificationControllerChromeOS:: |
+ ~EasyUnlockNotificationControllerChromeOS() { |
+ message_center_->RemoveObserver(this); |
+} |
+ |
+void EasyUnlockNotificationControllerChromeOS:: |
+ ShowChromebookAddedNotification() { |
+ message_center::RichNotificationData rich_notification_data; |
+ rich_notification_data.buttons.push_back( |
+ message_center::ButtonInfo(l10n_util::GetStringUTF16( |
+ IDS_EASY_UNLOCK_CHROMEBOOK_ADDED_NOTIFICATION_ABOUT_BUTTON))); |
+ |
+ ShowNotification(CreateNotification( |
+ kEasyUnlockChromebookAddedNotifierId, |
+ l10n_util::GetStringUTF16( |
+ IDS_EASY_UNLOCK_CHROMEBOOK_ADDED_NOTIFICATION_TITLE), |
+ l10n_util::GetStringFUTF16( |
+ IDS_EASY_UNLOCK_CHROMEBOOK_ADDED_NOTIFICATION_MESSAGE, |
+ ash::GetChromeOSDeviceName()), |
+ ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
+ IDR_NOTIFICATION_EASYUNLOCK_ENABLED), |
+ rich_notification_data)); |
+} |
+ |
+void EasyUnlockNotificationControllerChromeOS::ShowPairingChangeNotification() { |
+ message_center::RichNotificationData rich_notification_data; |
+ rich_notification_data.buttons.push_back( |
+ message_center::ButtonInfo(l10n_util::GetStringUTF16( |
+ IDS_EASY_UNLOCK_PAIRING_CHANGED_NOTIFICATION_UPDATE_BUTTON))); |
+ rich_notification_data.buttons.push_back( |
+ message_center::ButtonInfo(l10n_util::GetStringUTF16( |
+ IDS_EASY_UNLOCK_CHROMEBOOK_ADDED_NOTIFICATION_ABOUT_BUTTON))); |
+ |
+ ShowNotification(CreateNotification( |
+ kEasyUnlockPairingChangeNotifierId, |
+ l10n_util::GetStringUTF16( |
+ IDS_EASY_UNLOCK_PAIRING_CHANGED_NOTIFICATION_TITLE), |
+ l10n_util::GetStringFUTF16( |
+ IDS_EASY_UNLOCK_PAIRING_CHANGED_NOTIFICATION_MESSAGE, |
+ ash::GetChromeOSDeviceName()), |
+ ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
+ IDR_NOTIFICATION_EASYUNLOCK_ENABLED), |
+ rich_notification_data)); |
+} |
+ |
+void EasyUnlockNotificationControllerChromeOS:: |
+ ShowPairingChangeAppliedNotification(const std::string& phone_name) { |
+ // Remove the pairing change notification if it is still being shown. |
+ message_center_->RemoveNotification(kEasyUnlockPairingChangeNotifierId, |
+ false /* by_user */); |
+ |
+ message_center::RichNotificationData rich_notification_data; |
+ rich_notification_data.buttons.push_back( |
+ message_center::ButtonInfo(l10n_util::GetStringUTF16( |
+ IDS_EASY_UNLOCK_CHROMEBOOK_ADDED_NOTIFICATION_ABOUT_BUTTON))); |
+ |
+ ShowNotification(CreateNotification( |
+ kEasyUnlockPairingChangeAppliedNotifierId, |
+ l10n_util::GetStringUTF16( |
+ IDS_EASY_UNLOCK_PAIRING_CHANGE_APPLIED_NOTIFICATION_TITLE), |
+ l10n_util::GetStringFUTF16( |
+ IDS_EASY_UNLOCK_PAIRING_CHANGE_APPLIED_NOTIFICATION_MESSAGE, |
+ base::UTF8ToUTF16(phone_name), ash::GetChromeOSDeviceName()), |
+ ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
+ IDR_NOTIFICATION_EASYUNLOCK_ENABLED), |
+ rich_notification_data)); |
+} |
+ |
+void EasyUnlockNotificationControllerChromeOS::ShowNotification( |
+ std::unique_ptr<message_center::Notification> notification) { |
+ notification->SetSystemPriority(); |
+ std::string notification_id = notification->id(); |
+ if (message_center_->FindVisibleNotificationById(notification_id)) { |
+ message_center_->UpdateNotification(notification_id, |
+ std::move(notification)); |
+ } else { |
+ message_center_->AddNotification(std::move(notification)); |
+ } |
+} |
+ |
+void EasyUnlockNotificationControllerChromeOS::OnNotificationClicked( |
+ const std::string& notification_id) { |
+ if (notification_id == kEasyUnlockChromebookAddedNotifierId || |
+ notification_id == kEasyUnlockPairingChangeAppliedNotifierId) |
+ LaunchEasyUnlockSettings(); |
+} |
+ |
+void EasyUnlockNotificationControllerChromeOS::OnNotificationButtonClicked( |
+ const std::string& notification_id, |
+ int button_index) { |
+ if (notification_id == kEasyUnlockChromebookAddedNotifierId || |
+ notification_id == kEasyUnlockPairingChangeAppliedNotifierId) { |
+ LaunchEasyUnlockSettings(); |
+ } else if (notification_id == kEasyUnlockPairingChangeNotifierId) { |
+ if (button_index == 0) { |
+ LockScreen(); |
+ } else if (button_index == 1) { |
+ LaunchEasyUnlockSettings(); |
+ } |
+ } |
+} |
+ |
+void EasyUnlockNotificationControllerChromeOS::LaunchEasyUnlockSettings() { |
+ chrome::ShowSettingsSubPageForProfile(profile_, kLockScreenSettingsSubpage); |
+} |
+ |
+void EasyUnlockNotificationControllerChromeOS::LockScreen() { |
+ proximity_auth::ScreenlockBridge::Get()->Lock(); |
+} |