Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016 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/chromeos/login/quick_unlock/quick_unlock_notification_c ontroller.h" | |
| 6 | |
| 7 #include "ash/common/system/system_notifier.h" | |
| 8 #include "chrome/browser/browser_process.h" | |
| 9 #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
| |
| 10 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | |
| 11 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 12 #include "chrome/browser/notifications/notification_ui_manager.h" | |
| 13 #include "chrome/browser/profiles/profile.h" | |
| 14 #include "chrome/browser/ui/browser_navigator.h" | |
| 15 #include "chrome/browser/ui/browser_navigator_params.h" | |
| 16 #include "chrome/common/pref_names.h" | |
| 17 #include "chrome/common/url_constants.h" | |
| 18 #include "components/prefs/pref_service.h" | |
| 19 #include "components/user_manager/user.h" | |
| 20 #include "components/user_manager/user_manager.h" | |
| 21 #include "content/public/browser/notification_service.h" | |
| 22 #include "grit/ash_strings.h" | |
| 23 #include "grit/theme_resources.h" | |
| 24 #include "ui/base/l10n/l10n_util.h" | |
| 25 #include "ui/base/resource/resource_bundle.h" | |
| 26 #include "ui/strings/grit/ui_strings.h" | |
| 27 | |
| 28 namespace { | |
| 29 | |
| 30 const char kDelegateId[] = "quickunlock_delegate"; | |
| 31 const char kNotificationId[] = "quickunlock_notification"; | |
| 32 | |
| 33 void UpdatePreferenceForProfile(Profile* profile) { | |
| 34 PrefService* pref_service = profile->GetPrefs(); | |
| 35 pref_service->SetBoolean(prefs::kQuickUnlockFeatureNotificationShown, true); | |
| 36 } | |
| 37 | |
| 38 } // namespace | |
| 39 | |
| 40 namespace chromeos { | |
| 41 | |
| 42 QuickUnlockNotificationController::QuickUnlockNotificationController( | |
| 43 Profile* profile) | |
| 44 : profile_(profile), registrar_(new content::NotificationRegistrar) { | |
| 45 registrar_->Add(this, chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | |
| 46 content::NotificationService::AllSources()); | |
| 47 } | |
| 48 | |
| 49 QuickUnlockNotificationController::~QuickUnlockNotificationController() { | |
| 50 if (registrar_->IsRegistered(this, | |
| 51 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | |
| 52 content::NotificationService::AllSources())) { | |
|
jdufault
2016/07/08 21:15:41
Move into a helper function, UnregisterNotificatio
malaykeshav
2016/07/09 00:43:55
Done
| |
| 53 registrar_->Remove(this, chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | |
| 54 content::NotificationService::AllSources()); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 // static | |
| 59 // TODO(http://crbug.com/291747): Add check for a policy that might disable | |
| 60 // quick unlock. | |
| 61 bool QuickUnlockNotificationController::ShouldShowNotificationToProfile( | |
| 62 Profile* profile) { | |
| 63 // Do not show notification if this is a guest session. | |
| 64 if (profile->IsGuestSession()) | |
| 65 return false; | |
| 66 | |
| 67 // Do not show notification to user if already displayed in the past. | |
| 68 if (profile->GetPrefs()->GetBoolean( | |
| 69 prefs::kQuickUnlockFeatureNotificationShown)) { | |
| 70 return false; | |
| 71 } | |
| 72 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
| |
| 73 } | |
| 74 | |
| 75 // NotificationDelegate override: | |
| 76 std::string QuickUnlockNotificationController::id() const { | |
| 77 return kDelegateId; | |
| 78 } | |
| 79 | |
| 80 void QuickUnlockNotificationController::Observe( | |
| 81 int type, | |
| 82 const content::NotificationSource& source, | |
| 83 const content::NotificationDetails& details) { | |
| 84 bool is_locked = *content::Details<bool>(details).ptr(); | |
| 85 // 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
| |
| 86 if (is_locked) | |
| 87 return; | |
| 88 // Remove self as observer. | |
| 89 registrar_->Remove(this, chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | |
| 90 content::NotificationService::AllSources()); | |
|
jdufault
2016/07/08 21:15:41
Call helper function UnregisterNotification()
malaykeshav
2016/07/09 00:43:55
Done
| |
| 91 | |
| 92 // Create and add notification to notification manager. | |
| 93 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
| |
| 94 g_browser_process->notification_ui_manager()->Add(*notification, profile_); | |
| 95 } | |
| 96 | |
| 97 // message_center::NotificationDelegate override: | |
| 98 void QuickUnlockNotificationController::Close(bool by_user) { | |
| 99 if (by_user) | |
| 100 UpdatePreferenceForProfile(profile_); | |
| 101 } | |
| 102 | |
| 103 // message_center::NotificationDelegate override: | |
| 104 void QuickUnlockNotificationController::Click() { | |
| 105 // TODO(http://crbug.com/291747): Redirect to specific checkbox location in | |
| 106 // settings page. | |
| 107 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
| |
| 108 ui::PAGE_TRANSITION_LINK); | |
| 109 params.disposition = NEW_FOREGROUND_TAB; | |
| 110 params.window_action = chrome::NavigateParams::SHOW_WINDOW; | |
| 111 chrome::Navigate(¶ms); | |
| 112 | |
| 113 UpdatePreferenceForProfile(profile_); | |
| 114 | |
| 115 // Remove the notification from tray. | |
| 116 g_browser_process->notification_ui_manager()->CancelById( | |
| 117 id(), NotificationUIManager::GetProfileID(profile_)); | |
| 118 } | |
| 119 | |
| 120 Notification* QuickUnlockNotificationController::CreateNotification() { | |
| 121 return new Notification( | |
| 122 message_center::NOTIFICATION_TYPE_SIMPLE, | |
| 123 l10n_util::GetStringUTF16(IDS_ASH_QUICK_UNLOCK_NOTIFICATION_TITLE), | |
| 124 l10n_util::GetStringUTF16(IDS_ASH_QUICK_UNLOCK_NOTIFICATION_BODY), | |
| 125 // TODO(http://crbug.com/291747): Change this to actual icon for | |
| 126 // quick unlock feature notiifcation. | |
| 127 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
| 128 IDR_SCREENSHOT_NOTIFICATION_ICON), | |
| 129 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, | |
| 130 ash::system_notifier::kNotifierQuickUnlock), | |
| 131 l10n_util::GetStringUTF16( | |
| 132 IDS_MESSAGE_CENTER_NOTIFIER_QUICK_UNLOCK_FEATURE_NAME), | |
| 133 GURL(), kNotificationId, message_center::RichNotificationData(), this); | |
| 134 } | |
| 135 | |
| 136 } // namespace chromeos | |
| OLD | NEW |