| Index: chrome/browser/chromeos/login/quick_unlock/feature_notification_controller.cc
|
| diff --git a/chrome/browser/chromeos/login/quick_unlock/feature_notification_controller.cc b/chrome/browser/chromeos/login/quick_unlock/feature_notification_controller.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..16c04f4243c5fa9fafeeb7f04af327d7593ab89e
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/login/quick_unlock/feature_notification_controller.cc
|
| @@ -0,0 +1,133 @@
|
| +// 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_controller.h"
|
| +
|
| +#include "ash/common/system/system_notifier.h"
|
| +#include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/chrome_notification_types.h"
|
| +#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
|
| +#include "chrome/browser/chromeos/profiles/profile_helper.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 "components/user_manager/user.h"
|
| +#include "components/user_manager/user_manager.h"
|
| +#include "content/public/browser/notification_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";
|
| +
|
| +Profile* GetProfileFromAccountId(const AccountId& account_id) {
|
| + const user_manager::User* user =
|
| + user_manager::UserManager::Get()->FindUser(account_id);
|
| + return chromeos::ProfileHelper::Get()->GetProfileByUser(user);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +namespace chromeos {
|
| +namespace quickunlock {
|
| +
|
| +FeatureNotificationController::FeatureNotificationController(
|
| + const AccountId& account_id)
|
| + : profile_(GetProfileFromAccountId(account_id)),
|
| + registrar_(new content::NotificationRegistrar) {
|
| + registrar_->Add(this, chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
|
| + content::NotificationService::AllSources());
|
| +}
|
| +
|
| +FeatureNotificationController::~FeatureNotificationController() {}
|
| +
|
| +// static
|
| +// TODO(http://crbug.com/291747): Add check for a policy that might disable
|
| +// quick unlock.
|
| +bool FeatureNotificationController::ShouldShowNotificationForAccountId(
|
| + const AccountId& account_id) {
|
| + Profile* profile = GetProfileFromAccountId(account_id);
|
| + // Do not show notification if this is a guest session.
|
| + 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;
|
| +}
|
| +
|
| +void FeatureNotificationController::Observe(
|
| + int type,
|
| + const content::NotificationSource& source,
|
| + const content::NotificationDetails& details) {
|
| + registrar_->Remove(this, chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
|
| + content::NotificationService::AllSources());
|
| + std::unique_ptr<Notification> notification(CreateNotification());
|
| + g_browser_process->notification_ui_manager()->Add(*notification, profile_);
|
| +}
|
| +
|
| +// 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(¶ms);
|
| +
|
| + 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) {
|
| + PrefService* pref_service = profile->GetPrefs();
|
| + pref_service->SetBoolean(prefs::kQuickUnlockFeatureNotificationShown, true);
|
| +}
|
| +
|
| +} // namespace quickunlock
|
| +} // namespace chromeos
|
|
|