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

Side by Side Diff: chrome/browser/chromeos/login/quick_unlock/quick_unlock_notification_controller.cc

Issue 2128053002: Implements the feature notification for Quick Unlock (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Implements the feature notification for Quick Unlock Created 4 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 (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"
10 #include "chrome/browser/chromeos/login/quick_unlock/pin_storage.h"
11 #include "chrome/browser/chromeos/login/quick_unlock/pin_storage_factory.h"
12 #include "chrome/browser/notifications/notification.h"
13 #include "chrome/browser/notifications/notification_ui_manager.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser_navigator.h"
16 #include "chrome/browser/ui/browser_navigator_params.h"
17 #include "chrome/common/pref_names.h"
18 #include "chrome/common/url_constants.h"
19 #include "components/prefs/pref_service.h"
20 #include "content/public/browser/notification_service.h"
21 #include "grit/ash_strings.h"
22 #include "grit/theme_resources.h"
23 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/strings/grit/ui_strings.h"
26
27 namespace {
28
29 const char kDelegateId[] = "quickunlock_delegate";
30 const char kNotificationId[] = "quickunlock_notification";
31 const char kChromeAuthenticationSettingsURL[] =
32 "chrome://md-settings/quickUnlock/authenticate";
33
34 void UpdatePreferenceForProfile(Profile* profile) {
35 PrefService* pref_service = profile->GetPrefs();
36 pref_service->SetBoolean(prefs::kQuickUnlockFeatureNotificationShown, true);
37 }
38
39 } // namespace
40
41 namespace chromeos {
42
43 QuickUnlockNotificationController::QuickUnlockNotificationController(
44 Profile* profile)
45 : profile_(profile) {
46 registrar_.Add(this, chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
47 content::NotificationService::AllSources());
48 }
49
50 QuickUnlockNotificationController::~QuickUnlockNotificationController() {
51 UnregisterObserver();
52 }
53
54 // static
55 // TODO(http://crbug.com/291747): Add check for a policy that might disable
56 // quick unlock.
57 bool QuickUnlockNotificationController::ShouldShow(Profile* profile) {
58 // Do not show notification if this is a guest session.
59 if (profile->IsGuestSession())
60 return false;
61
62 // Do not show notification to user if already displayed in the past.
63 if (profile->GetPrefs()->GetBoolean(
64 prefs::kQuickUnlockFeatureNotificationShown)) {
65 return false;
66 }
67
68 // Do not show the notification if the pin is already set.
69 PinStorage* pin_storage = PinStorageFactory::GetForProfile(profile);
70 if (pin_storage->IsPinSet())
71 return false;
72
73 // TODO(jdufault): Enable once quick unlock settings land(crbug.com/291747).
74 return false;
75 }
76
77 // NotificationDelegate override:
78 std::string QuickUnlockNotificationController::id() const {
79 return kDelegateId;
80 }
81
82 void QuickUnlockNotificationController::Observe(
83 int type,
84 const content::NotificationSource& source,
85 const content::NotificationDetails& details) {
86 if (type != chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED)
87 return;
88
89 bool is_screen_locked = *content::Details<bool>(details).ptr();
90
91 // Return if the screen is locked, indicating that the notification was
92 // emitted due to a screen lock event.
93 if (is_screen_locked)
94 return;
95
96 UnregisterObserver();
97
98 // The user may have enabled the quick unlock feature during the current
99 // session and after the notificaiton controller has already been initialized.
100 if (ShouldShow(profile_)) {
stevenjb 2016/07/11 22:06:34 Shouldn't this be !ShouldShow ?
101 UpdatePreferenceForProfile(profile_);
102 return;
103 }
104
105 // Create and add notification to notification manager.
106 std::unique_ptr<Notification> notification(CreateNotification());
107 g_browser_process->notification_ui_manager()->Add(*notification, profile_);
108 }
109
110 // message_center::NotificationDelegate override:
111 void QuickUnlockNotificationController::Close(bool by_user) {
112 if (by_user)
113 UpdatePreferenceForProfile(profile_);
114 }
115
116 // message_center::NotificationDelegate override:
117 void QuickUnlockNotificationController::Click() {
118 chrome::NavigateParams params(profile_,
119 GURL(kChromeAuthenticationSettingsURL),
120 ui::PAGE_TRANSITION_LINK);
121 params.disposition = NEW_FOREGROUND_TAB;
122 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
123 chrome::Navigate(&params);
124
125 UpdatePreferenceForProfile(profile_);
126
127 // Remove the notification from tray.
128 g_browser_process->notification_ui_manager()->CancelById(
129 id(), NotificationUIManager::GetProfileID(profile_));
130 }
131
132 void QuickUnlockNotificationController::UnregisterObserver() {
133 if (registrar_.IsRegistered(this,
134 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
135 content::NotificationService::AllSources())) {
136 registrar_.Remove(this, chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
137 content::NotificationService::AllSources());
138 }
139 }
140
141 Notification* QuickUnlockNotificationController::CreateNotification() {
142 return new Notification(
143 message_center::NOTIFICATION_TYPE_SIMPLE,
144 l10n_util::GetStringUTF16(IDS_ASH_QUICK_UNLOCK_NOTIFICATION_TITLE),
145 l10n_util::GetStringUTF16(IDS_ASH_QUICK_UNLOCK_NOTIFICATION_BODY),
146 // TODO(http://crbug.com/291747): Change this to actual icon for
147 // quick unlock feature notification.
148 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
149 IDR_SCREENSHOT_NOTIFICATION_ICON),
150 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
151 ash::system_notifier::kNotifierQuickUnlock),
152 l10n_util::GetStringUTF16(
153 IDS_MESSAGE_CENTER_NOTIFIER_QUICK_UNLOCK_FEATURE_NAME),
154 GURL(), kNotificationId, message_center::RichNotificationData(), this);
155 }
156
157 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698