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/feature_notification.h" | |
| 6 | |
| 7 #include "ash/common/system/system_notifier.h" | |
| 8 #include "chrome/browser/browser_process.h" | |
| 9 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | |
| 10 #include "chrome/browser/notifications/notification_ui_manager.h" | |
| 11 #include "chrome/browser/profiles/profile.h" | |
| 12 #include "chrome/browser/ui/browser_navigator.h" | |
| 13 #include "chrome/browser/ui/browser_navigator_params.h" | |
| 14 #include "chrome/common/pref_names.h" | |
| 15 #include "chrome/common/url_constants.h" | |
| 16 #include "components/prefs/pref_service.h" | |
| 17 #include "grit/ash_strings.h" | |
| 18 #include "grit/theme_resources.h" | |
| 19 #include "ui/base/l10n/l10n_util.h" | |
| 20 #include "ui/base/resource/resource_bundle.h" | |
| 21 #include "ui/strings/grit/ui_strings.h" | |
| 22 | |
| 23 namespace { | |
| 24 | |
| 25 const char kDelegateId[] = "quickunlock_delegate"; | |
| 26 const char kNotificationId[] = "quickunlock_notification"; | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 namespace chromeos { | |
| 31 namespace quickunlock { | |
| 32 | |
| 33 FeatureNotificationController::FeatureNotificationController(Profile* profile) | |
| 34 : profile_(profile) { | |
| 35 std::unique_ptr<Notification> notification(CreateNotification()); | |
| 36 g_browser_process->notification_ui_manager()->Add(*notification, profile_); | |
| 37 } | |
| 38 | |
| 39 FeatureNotificationController::~FeatureNotificationController() {} | |
| 40 | |
| 41 // static | |
| 42 // TODO(http://crbug.com/291747): Add check for a policy that might disable | |
| 43 // quick unlock. | |
| 44 bool FeatureNotificationController::ShouldShowNotificationToProfile( | |
| 45 Profile* profile) { | |
| 46 // Do not show survey if this is a guest session. | |
|
jdufault
2016/07/06 21:06:43
Update comment (don't mention 'survey')
malaykeshav
2016/07/07 21:39:22
Done
| |
| 47 if (profile->IsGuestSession()) | |
| 48 return false; | |
| 49 | |
| 50 // Do not show notification to user if already displayed in the past. | |
| 51 if (profile->GetPrefs()->GetBoolean( | |
| 52 prefs::kQuickUnlockFeatureNotificationShown)) | |
| 53 return false; | |
| 54 return true; | |
| 55 } | |
| 56 | |
| 57 // NotificationDelegate override: | |
| 58 std::string FeatureNotificationController::id() const { | |
| 59 return kDelegateId; | |
| 60 } | |
| 61 | |
| 62 // message_center::NotificationDelegate override: | |
| 63 void FeatureNotificationController::Close(bool by_user) { | |
| 64 if (by_user) | |
| 65 UpdatePreferenceForProfile(profile_); | |
| 66 } | |
| 67 | |
| 68 // message_center::NotificationDelegate override: | |
| 69 void FeatureNotificationController::Click() { | |
| 70 // TODO(http://crbug.com/291747): Redirect to specific checkbox location in | |
| 71 // settings page. | |
| 72 chrome::NavigateParams params(profile_, GURL(chrome::kChromeUISettingsURL), | |
| 73 ui::PAGE_TRANSITION_LINK); | |
| 74 params.disposition = NEW_FOREGROUND_TAB; | |
| 75 params.window_action = chrome::NavigateParams::SHOW_WINDOW; | |
| 76 chrome::Navigate(¶ms); | |
| 77 | |
| 78 UpdatePreferenceForProfile(profile_); | |
| 79 | |
| 80 // Remove the notification from tray. | |
| 81 g_browser_process->notification_ui_manager()->CancelById( | |
| 82 id(), NotificationUIManager::GetProfileID(profile_)); | |
| 83 } | |
| 84 | |
| 85 Notification* FeatureNotificationController::CreateNotification() { | |
| 86 return new Notification( | |
| 87 message_center::NOTIFICATION_TYPE_SIMPLE, | |
| 88 l10n_util::GetStringUTF16(IDS_ASH_QUICK_UNLOCK_NOTIFICATION_TITLE), | |
| 89 l10n_util::GetStringUTF16(IDS_ASH_QUICK_UNLOCK_NOTIFICATION_BODY), | |
| 90 // TODO(http://crbug.com/291747): Change this to actual icon for | |
| 91 // quick unlock feature notiifcation. | |
| 92 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
| 93 IDR_SCREENSHOT_NOTIFICATION_ICON), | |
| 94 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, | |
| 95 ash::system_notifier::kNotifierQuickUnlock), | |
| 96 l10n_util::GetStringUTF16( | |
| 97 IDS_MESSAGE_CENTER_NOTIFIER_QUICK_UNLOCK_FEATURE_NAME), | |
| 98 GURL(), kNotificationId, message_center::RichNotificationData(), this); | |
| 99 } | |
| 100 | |
| 101 void FeatureNotificationController::UpdatePreferenceForProfile( | |
| 102 Profile* profile) { | |
|
jdufault
2016/07/06 21:06:43
Drop the profile parameter; just use profile_ dire
malaykeshav
2016/07/07 21:39:22
Isn't it cleaner and more readable to make the met
jdufault
2016/07/07 22:08:01
That's fine - but then you should move this functi
malaykeshav
2016/07/07 22:39:42
Moving to anonymous namespace.
| |
| 103 PrefService* pref_service = profile->GetPrefs(); | |
| 104 pref_service->SetBoolean(prefs::kQuickUnlockFeatureNotificationShown, true); | |
| 105 } | |
| 106 | |
| 107 } // namespace quickunlock | |
| 108 } // namespace chromeos | |
| OLD | NEW |