Index: chrome/browser/chromeos/login/quick_unlock/quick_unlock_notification_controller.cc |
diff --git a/chrome/browser/chromeos/login/quick_unlock/quick_unlock_notification_controller.cc b/chrome/browser/chromeos/login/quick_unlock/quick_unlock_notification_controller.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1731dd8e7203dcbc8093d789aeb8468fc0c52e5e |
--- /dev/null |
+++ b/chrome/browser/chromeos/login/quick_unlock/quick_unlock_notification_controller.cc |
@@ -0,0 +1,136 @@ |
+// Copyright (c) 2016 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/chromeos/login/quick_unlock/quick_unlock_notification_controller.h" |
+ |
+#include "ash/common/system/system_notifier.h" |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/chrome_notification_types.h" |
jdufault
2016/07/08 21:15:41
Can you please verify that all of the includes are
malaykeshav
2016/07/09 00:43:55
Done
|
+#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
+#include "chrome/browser/chromeos/profiles/profile_helper.h" |
+#include "chrome/browser/notifications/notification_ui_manager.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/ui/browser_navigator.h" |
+#include "chrome/browser/ui/browser_navigator_params.h" |
+#include "chrome/common/pref_names.h" |
+#include "chrome/common/url_constants.h" |
+#include "components/prefs/pref_service.h" |
+#include "components/user_manager/user.h" |
+#include "components/user_manager/user_manager.h" |
+#include "content/public/browser/notification_service.h" |
+#include "grit/ash_strings.h" |
+#include "grit/theme_resources.h" |
+#include "ui/base/l10n/l10n_util.h" |
+#include "ui/base/resource/resource_bundle.h" |
+#include "ui/strings/grit/ui_strings.h" |
+ |
+namespace { |
+ |
+const char kDelegateId[] = "quickunlock_delegate"; |
+const char kNotificationId[] = "quickunlock_notification"; |
+ |
+void UpdatePreferenceForProfile(Profile* profile) { |
+ PrefService* pref_service = profile->GetPrefs(); |
+ pref_service->SetBoolean(prefs::kQuickUnlockFeatureNotificationShown, true); |
+} |
+ |
+} // namespace |
+ |
+namespace chromeos { |
+ |
+QuickUnlockNotificationController::QuickUnlockNotificationController( |
+ Profile* profile) |
+ : profile_(profile), registrar_(new content::NotificationRegistrar) { |
+ registrar_->Add(this, chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
+ content::NotificationService::AllSources()); |
+} |
+ |
+QuickUnlockNotificationController::~QuickUnlockNotificationController() { |
+ if (registrar_->IsRegistered(this, |
+ chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
+ content::NotificationService::AllSources())) { |
jdufault
2016/07/08 21:15:41
Move into a helper function, UnregisterNotificatio
malaykeshav
2016/07/09 00:43:55
Done
|
+ registrar_->Remove(this, chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
+ content::NotificationService::AllSources()); |
+ } |
+} |
+ |
+// static |
+// TODO(http://crbug.com/291747): Add check for a policy that might disable |
+// quick unlock. |
+bool QuickUnlockNotificationController::ShouldShowNotificationToProfile( |
+ Profile* profile) { |
+ // Do not show notification if this is a guest session. |
+ if (profile->IsGuestSession()) |
+ return false; |
+ |
+ // Do not show notification to user if already displayed in the past. |
+ if (profile->GetPrefs()->GetBoolean( |
+ prefs::kQuickUnlockFeatureNotificationShown)) { |
+ return false; |
+ } |
+ return true; |
jdufault
2016/07/08 21:15:41
Can you have this always return false for now with
malaykeshav
2016/07/09 00:43:55
Done
|
+} |
+ |
+// NotificationDelegate override: |
+std::string QuickUnlockNotificationController::id() const { |
+ return kDelegateId; |
+} |
+ |
+void QuickUnlockNotificationController::Observe( |
+ int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) { |
+ bool is_locked = *content::Details<bool>(details).ptr(); |
+ // If notification is not from screen unlock, then do nothing. |
jdufault
2016/07/08 21:15:41
Either update the comment or the variable name, si
malaykeshav
2016/07/09 00:43:55
Done
|
+ if (is_locked) |
+ return; |
+ // Remove self as observer. |
+ registrar_->Remove(this, chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
+ content::NotificationService::AllSources()); |
jdufault
2016/07/08 21:15:41
Call helper function UnregisterNotification()
malaykeshav
2016/07/09 00:43:55
Done
|
+ |
+ // Create and add notification to notification manager. |
+ std::unique_ptr<Notification> notification(CreateNotification()); |
jdufault
2016/07/08 21:15:41
This should verify that the notification type is N
malaykeshav
2016/07/09 00:43:55
Done
|
+ g_browser_process->notification_ui_manager()->Add(*notification, profile_); |
+} |
+ |
+// message_center::NotificationDelegate override: |
+void QuickUnlockNotificationController::Close(bool by_user) { |
+ if (by_user) |
+ UpdatePreferenceForProfile(profile_); |
+} |
+ |
+// message_center::NotificationDelegate override: |
+void QuickUnlockNotificationController::Click() { |
+ // TODO(http://crbug.com/291747): Redirect to specific checkbox location in |
+ // settings page. |
+ chrome::NavigateParams params(profile_, GURL(chrome::kChromeUISettingsURL), |
jdufault
2016/07/08 21:15:41
chrome://settings/quickUnlock/authenticate is the
malaykeshav
2016/07/09 00:43:55
Done
|
+ ui::PAGE_TRANSITION_LINK); |
+ params.disposition = NEW_FOREGROUND_TAB; |
+ params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
+ chrome::Navigate(¶ms); |
+ |
+ UpdatePreferenceForProfile(profile_); |
+ |
+ // Remove the notification from tray. |
+ g_browser_process->notification_ui_manager()->CancelById( |
+ id(), NotificationUIManager::GetProfileID(profile_)); |
+} |
+ |
+Notification* QuickUnlockNotificationController::CreateNotification() { |
+ return new Notification( |
+ message_center::NOTIFICATION_TYPE_SIMPLE, |
+ l10n_util::GetStringUTF16(IDS_ASH_QUICK_UNLOCK_NOTIFICATION_TITLE), |
+ l10n_util::GetStringUTF16(IDS_ASH_QUICK_UNLOCK_NOTIFICATION_BODY), |
+ // TODO(http://crbug.com/291747): Change this to actual icon for |
+ // quick unlock feature notiifcation. |
+ ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
+ IDR_SCREENSHOT_NOTIFICATION_ICON), |
+ message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, |
+ ash::system_notifier::kNotifierQuickUnlock), |
+ l10n_util::GetStringUTF16( |
+ IDS_MESSAGE_CENTER_NOTIFIER_QUICK_UNLOCK_FEATURE_NAME), |
+ GURL(), kNotificationId, message_center::RichNotificationData(), this); |
+} |
+ |
+} // namespace chromeos |