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

Unified Diff: chrome/browser/chromeos/login/quick_unlock/feature_notification.cc

Issue 2128053002: Implements the feature notification for Quick Unlock (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/quick_unlock/feature_notification.cc
diff --git a/chrome/browser/chromeos/login/quick_unlock/feature_notification.cc b/chrome/browser/chromeos/login/quick_unlock/feature_notification.cc
new file mode 100644
index 0000000000000000000000000000000000000000..10dff8502541c1ec491f067571977264167771ea
--- /dev/null
+++ b/chrome/browser/chromeos/login/quick_unlock/feature_notification.cc
@@ -0,0 +1,108 @@
+// 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/feature_notification.h"
+
+#include "ash/common/system/system_notifier.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.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 "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";
+
+} // namespace
+
+namespace chromeos {
+namespace quickunlock {
+
+FeatureNotificationController::FeatureNotificationController(Profile* profile)
+ : profile_(profile) {
+ std::unique_ptr<Notification> notification(CreateNotification());
+ g_browser_process->notification_ui_manager()->Add(*notification, profile_);
+}
+
+FeatureNotificationController::~FeatureNotificationController() {}
+
+// static
+// TODO(http://crbug.com/291747): Add check for a policy that might disable
+// quick unlock.
+bool FeatureNotificationController::ShouldShowNotificationToProfile(
+ Profile* profile) {
+ // 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
+ 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;
+}
+
+// NotificationDelegate override:
+std::string FeatureNotificationController::id() const {
+ return kDelegateId;
+}
+
+// message_center::NotificationDelegate override:
+void FeatureNotificationController::Close(bool by_user) {
+ if (by_user)
+ UpdatePreferenceForProfile(profile_);
+}
+
+// message_center::NotificationDelegate override:
+void FeatureNotificationController::Click() {
+ // TODO(http://crbug.com/291747): Redirect to specific checkbox location in
+ // settings page.
+ chrome::NavigateParams params(profile_, GURL(chrome::kChromeUISettingsURL),
+ ui::PAGE_TRANSITION_LINK);
+ params.disposition = NEW_FOREGROUND_TAB;
+ params.window_action = chrome::NavigateParams::SHOW_WINDOW;
+ chrome::Navigate(&params);
+
+ UpdatePreferenceForProfile(profile_);
+
+ // Remove the notification from tray.
+ g_browser_process->notification_ui_manager()->CancelById(
+ id(), NotificationUIManager::GetProfileID(profile_));
+}
+
+Notification* FeatureNotificationController::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);
+}
+
+void FeatureNotificationController::UpdatePreferenceForProfile(
+ 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.
+ PrefService* pref_service = profile->GetPrefs();
+ pref_service->SetBoolean(prefs::kQuickUnlockFeatureNotificationShown, true);
+}
+
+} // namespace quickunlock
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698