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

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 the notification if the pin is already set.
59 PinStorage* pin_storage = PinStorageFactory::GetForProfile(profile);
60 if (pin_storage->IsPinSet())
61 return false;
62
63 // Do not show notification if this is a guest session.
64 if (profile->IsGuestSession())
65 return false;
stevenjb 2016/07/11 19:55:46 nit: test this first
malaykeshav 2016/07/11 21:55:35 Done
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 }
stevenjb 2016/07/11 19:55:46 nit: check this second (less expensive than gettin
malaykeshav 2016/07/11 21:55:35 Done
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
stevenjb 2016/07/11 19:55:46 Should we check ShouldShow here? It seems conceiva
malaykeshav 2016/07/11 21:55:35 +1 The state may change before the execution reac
96 UnregisterObserver();
97
98 // Create and add notification to notification manager.
99 std::unique_ptr<Notification> notification(CreateNotification());
100 g_browser_process->notification_ui_manager()->Add(*notification, profile_);
101 }
102
103 // message_center::NotificationDelegate override:
104 void QuickUnlockNotificationController::Close(bool by_user) {
105 if (by_user)
106 UpdatePreferenceForProfile(profile_);
107 }
108
109 // message_center::NotificationDelegate override:
110 void QuickUnlockNotificationController::Click() {
111 chrome::NavigateParams params(profile_,
112 GURL(kChromeAuthenticationSettingsURL),
113 ui::PAGE_TRANSITION_LINK);
114 params.disposition = NEW_FOREGROUND_TAB;
115 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
116 chrome::Navigate(&params);
117
118 UpdatePreferenceForProfile(profile_);
119
120 // Remove the notification from tray.
121 g_browser_process->notification_ui_manager()->CancelById(
122 id(), NotificationUIManager::GetProfileID(profile_));
123 }
124
125 void QuickUnlockNotificationController::UnregisterObserver() {
126 if (registrar_.IsRegistered(this,
127 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
128 content::NotificationService::AllSources())) {
129 registrar_.Remove(this, chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
130 content::NotificationService::AllSources());
131 }
132 }
133
134 Notification* QuickUnlockNotificationController::CreateNotification() {
135 return new Notification(
136 message_center::NOTIFICATION_TYPE_SIMPLE,
137 l10n_util::GetStringUTF16(IDS_ASH_QUICK_UNLOCK_NOTIFICATION_TITLE),
138 l10n_util::GetStringUTF16(IDS_ASH_QUICK_UNLOCK_NOTIFICATION_BODY),
139 // TODO(http://crbug.com/291747): Change this to actual icon for
140 // quick unlock feature notification.
141 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
142 IDR_SCREENSHOT_NOTIFICATION_ICON),
143 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
144 ash::system_notifier::kNotifierQuickUnlock),
145 l10n_util::GetStringUTF16(
146 IDS_MESSAGE_CENTER_NOTIFIER_QUICK_UNLOCK_FEATURE_NAME),
147 GURL(), kNotificationId, message_center::RichNotificationData(), this);
148 }
149
150 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698