Commit d8e897e8 authored by Qiang Xu's avatar Qiang Xu Committed by Commit Bot

cros: move recommendation restorer to ash

This CL moves RecommendationRestorer class to ash. The class exposes
an ObservePrefs method to let caller start observing recommended values
for a pref name.

TBR=bartfab@chromium.org

Bug: 839150
Test: covered by tests and enterprise-enrolled device test
Change-Id: I57b80c49ff8b0d5ab27102abf57b9a21b6b95c0a
Reviewed-on: https://chromium-review.googlesource.com/1023158
Commit-Queue: Qiang Xu <warx@google.com>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561591}
parent 7f0cff2a
...@@ -429,6 +429,8 @@ component("ash") { ...@@ -429,6 +429,8 @@ component("ash") {
"note_taking_controller.h", "note_taking_controller.h",
"pointer_watcher_adapter_classic.cc", "pointer_watcher_adapter_classic.cc",
"pointer_watcher_adapter_classic.h", "pointer_watcher_adapter_classic.h",
"policy/policy_recommendation_restorer.cc",
"policy/policy_recommendation_restorer.h",
"root_window_controller.cc", "root_window_controller.cc",
"root_window_controller.h", "root_window_controller.h",
"root_window_settings.cc", "root_window_settings.cc",
...@@ -1697,6 +1699,7 @@ test("ash_unittests") { ...@@ -1697,6 +1699,7 @@ test("ash_unittests") {
"multi_device_setup/multi_device_notification_presenter_unittest.cc", "multi_device_setup/multi_device_notification_presenter_unittest.cc",
"mus_property_mirror_ash_unittest.cc", "mus_property_mirror_ash_unittest.cc",
"pointer_watcher_adapter_classic_unittest.cc", "pointer_watcher_adapter_classic_unittest.cc",
"policy/policy_recommendation_restorer_unittest.cc",
"root_window_controller_unittest.cc", "root_window_controller_unittest.cc",
"rotator/screen_rotation_animation_unittest.cc", "rotator/screen_rotation_animation_unittest.cc",
"rotator/screen_rotation_animator_unittest.cc", "rotator/screen_rotation_animator_unittest.cc",
...@@ -1903,6 +1906,7 @@ test("ash_unittests") { ...@@ -1903,6 +1906,7 @@ test("ash_unittests") {
"//components/password_manager/core/browser:hash_password_manager", "//components/password_manager/core/browser:hash_password_manager",
"//components/prefs:test_support", "//components/prefs:test_support",
"//components/quirks", "//components/quirks",
"//components/sync_preferences:test_support",
"//components/user_manager", "//components/user_manager",
"//components/user_manager:test_support", "//components/user_manager:test_support",
"//device/bluetooth", "//device/bluetooth",
......
...@@ -118,6 +118,9 @@ specific_include_rules = { ...@@ -118,6 +118,9 @@ specific_include_rules = {
"message_center_controller\.*": [ "message_center_controller\.*": [
"+components/arc/common/notifications.mojom.h" "+components/arc/common/notifications.mojom.h"
], ],
"policy_recommendation_restorer_unittest.cc": [
"+components/sync_preferences/testing_pref_service_syncable.h"
],
"root_window_controller\.*": [ "root_window_controller\.*": [
"+ash/host" "+ash/host"
], ],
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ash/autoclick/autoclick_controller.h" #include "ash/autoclick/autoclick_controller.h"
#include "ash/components/autoclick/public/mojom/autoclick.mojom.h" #include "ash/components/autoclick/public/mojom/autoclick.mojom.h"
#include "ash/high_contrast/high_contrast_controller.h" #include "ash/high_contrast/high_contrast_controller.h"
#include "ash/policy/policy_recommendation_restorer.h"
#include "ash/public/cpp/ash_pref_names.h" #include "ash/public/cpp/ash_pref_names.h"
#include "ash/public/cpp/config.h" #include "ash/public/cpp/config.h"
#include "ash/public/cpp/shell_window_ids.h" #include "ash/public/cpp/shell_window_ids.h"
...@@ -52,6 +53,17 @@ namespace { ...@@ -52,6 +53,17 @@ namespace {
constexpr char kNotificationId[] = "chrome://settings/accessibility"; constexpr char kNotificationId[] = "chrome://settings/accessibility";
constexpr char kNotifierAccessibility[] = "ash.accessibility"; constexpr char kNotifierAccessibility[] = "ash.accessibility";
// TODO(warx): Signin screen has more controllable accessibility prefs. We may
// want to expand this to a complete list. If so, merge this with
// |kCopiedOnSigninAccessibilityPrefs|.
constexpr const char* const kA11yPrefsForRecommendedValueOnSignin[]{
prefs::kAccessibilityLargeCursorEnabled,
prefs::kAccessibilityHighContrastEnabled,
prefs::kAccessibilityScreenMagnifierEnabled,
prefs::kAccessibilitySpokenFeedbackEnabled,
prefs::kAccessibilityVirtualKeyboardEnabled,
};
// List of accessibility prefs that are to be copied (if changed by the user) on // List of accessibility prefs that are to be copied (if changed by the user) on
// signin screen profile to a newly created user profile or a guest session. // signin screen profile to a newly created user profile or a guest session.
constexpr const char* const kCopiedOnSigninAccessibilityPrefs[]{ constexpr const char* const kCopiedOnSigninAccessibilityPrefs[]{
...@@ -594,6 +606,14 @@ void AccessibilityController::SetAccessibilityPanelFullscreen(bool fullscreen) { ...@@ -594,6 +606,14 @@ void AccessibilityController::SetAccessibilityPanelFullscreen(bool fullscreen) {
void AccessibilityController::OnSigninScreenPrefServiceInitialized( void AccessibilityController::OnSigninScreenPrefServiceInitialized(
PrefService* prefs) { PrefService* prefs) {
// Make |kA11yPrefsForRecommendedValueOnSignin| observing recommended values
// on signin screen. See PolicyRecommendationRestorer.
PolicyRecommendationRestorer* policy_recommendation_restorer =
Shell::Get()->policy_recommendation_restorer();
for (auto* const pref_name : kA11yPrefsForRecommendedValueOnSignin)
policy_recommendation_restorer->ObservePref(pref_name);
// Observe user settings. This must happen after PolicyRecommendationRestorer.
ObservePrefs(prefs); ObservePrefs(prefs);
} }
......
// Copyright 2013 The Chromium Authors. All rights reserved. // Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/chromeos/policy/recommendation_restorer.h" #include "ash/policy/policy_recommendation_restorer.h"
#include "ash/public/cpp/ash_pref_names.h" #include "ash/session/session_controller.h"
#include "ash/shell.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/location.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/time/time.h" #include "base/stl_util.h"
#include "base/values.h" #include "components/prefs/pref_change_registrar.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "ui/base/user_activity/user_activity_detector.h" #include "ui/base/user_activity/user_activity_detector.h"
namespace policy { namespace ash {
namespace { namespace {
// The amount of idle time after which recommended values are restored.
const int kRestoreDelayInMs = 60 * 1000; // 1 minute.
} // namespace
RecommendationRestorer::RecommendationRestorer(Profile* profile)
: logged_in_(false) {
if (!chromeos::ProfileHelper::IsSigninProfile(profile))
return;
pref_change_registrar_.Init(profile->GetPrefs()); // The amount of idle time after which recommended values are restored.
pref_change_registrar_.Add(ash::prefs::kAccessibilityLargeCursorEnabled, constexpr base::TimeDelta kRestoreDelayInMinutes =
base::Bind(&RecommendationRestorer::Restore, base::TimeDelta::FromMinutes(1);
base::Unretained(this), true));
pref_change_registrar_.Add(ash::prefs::kAccessibilitySpokenFeedbackEnabled,
base::Bind(&RecommendationRestorer::Restore,
base::Unretained(this), true));
pref_change_registrar_.Add(ash::prefs::kAccessibilityHighContrastEnabled,
base::Bind(&RecommendationRestorer::Restore,
base::Unretained(this), true));
pref_change_registrar_.Add(ash::prefs::kAccessibilityScreenMagnifierEnabled,
base::Bind(&RecommendationRestorer::Restore,
base::Unretained(this), true));
pref_change_registrar_.Add(ash::prefs::kAccessibilityVirtualKeyboardEnabled,
base::Bind(&RecommendationRestorer::Restore,
base::Unretained(this), true));
notification_registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED,
content::NotificationService::AllSources());
RestoreAll(); } // namespace
}
RecommendationRestorer::~RecommendationRestorer() { PolicyRecommendationRestorer::PolicyRecommendationRestorer() {
Shell::Get()->session_controller()->AddObserver(this);
} }
void RecommendationRestorer::Shutdown() { PolicyRecommendationRestorer::~PolicyRecommendationRestorer() {
StopTimer(); StopTimer();
pref_change_registrar_.RemoveAll(); Shell::Get()->session_controller()->RemoveObserver(this);
notification_registrar_.RemoveAll();
} }
void RecommendationRestorer::Observe( void PolicyRecommendationRestorer::ObservePref(const std::string& pref_name) {
int type, PrefService* prefs =
const content::NotificationSource& source, Shell::Get()->session_controller()->GetSigninScreenPrefService();
const content::NotificationDetails& details) { DCHECK(prefs);
DCHECK_EQ(chrome::NOTIFICATION_LOGIN_USER_CHANGED, type); DCHECK(!base::ContainsKey(pref_names_, pref_name));
if (!pref_change_registrar_) {
pref_change_registrar_ = std::make_unique<PrefChangeRegistrar>();
pref_change_registrar_->Init(prefs);
}
pref_change_registrar_->Add(
pref_name, base::BindRepeating(&PolicyRecommendationRestorer::Restore,
base::Unretained(this), true));
pref_names_.insert(pref_name);
Restore(false /* allow_delay */, pref_name);
}
logged_in_ = true; void PolicyRecommendationRestorer::OnActiveUserPrefServiceChanged(
notification_registrar_.RemoveAll(); PrefService* pref_service) {
active_user_pref_connected_ = true;
StopTimer(); StopTimer();
RestoreAll(); RestoreAll();
} }
void RecommendationRestorer::OnUserActivity(const ui::Event* event) { void PolicyRecommendationRestorer::OnUserActivity(const ui::Event* event) {
if (restore_timer_.IsRunning()) if (restore_timer_.IsRunning())
restore_timer_.Reset(); restore_timer_.Reset();
} }
void RecommendationRestorer::Restore(bool allow_delay, void PolicyRecommendationRestorer::Restore(bool allow_delay,
const std::string& pref_name) { const std::string& pref_name) {
const PrefService::Preference* pref = const PrefService::Preference* pref =
pref_change_registrar_.prefs()->FindPreference(pref_name.c_str()); pref_change_registrar_->prefs()->FindPreference(pref_name);
if (!pref) { if (!pref) {
NOTREACHED(); NOTREACHED();
return; return;
...@@ -93,10 +74,11 @@ void RecommendationRestorer::Restore(bool allow_delay, ...@@ -93,10 +74,11 @@ void RecommendationRestorer::Restore(bool allow_delay,
if (!pref->GetRecommendedValue() || !pref->HasUserSetting()) if (!pref->GetRecommendedValue() || !pref->HasUserSetting())
return; return;
if (logged_in_) { if (active_user_pref_connected_) {
allow_delay = false; allow_delay = false;
} else if (allow_delay) { } else if (allow_delay) {
// Skip the delay if there has been no user input since the browser started. // Skip the delay if there has been no user input since |pref_name| is
// started observing recommended value.
const ui::UserActivityDetector* user_activity_detector = const ui::UserActivityDetector* user_activity_detector =
ui::UserActivityDetector::Get(); ui::UserActivityDetector::Get();
if (user_activity_detector && if (user_activity_detector &&
...@@ -108,21 +90,18 @@ void RecommendationRestorer::Restore(bool allow_delay, ...@@ -108,21 +90,18 @@ void RecommendationRestorer::Restore(bool allow_delay,
if (allow_delay) if (allow_delay)
StartTimer(); StartTimer();
else else
pref_change_registrar_.prefs()->ClearPref(pref->name().c_str()); pref_change_registrar_->prefs()->ClearPref(pref->name());
} }
void RecommendationRestorer::RestoreAll() { void PolicyRecommendationRestorer::RestoreAll() {
Restore(false, ash::prefs::kAccessibilityLargeCursorEnabled); for (const auto& pref_name : pref_names_)
Restore(false, ash::prefs::kAccessibilitySpokenFeedbackEnabled); Restore(false, pref_name);
Restore(false, ash::prefs::kAccessibilityHighContrastEnabled);
Restore(false, ash::prefs::kAccessibilityScreenMagnifierEnabled);
Restore(false, ash::prefs::kAccessibilityVirtualKeyboardEnabled);
} }
void RecommendationRestorer::StartTimer() { void PolicyRecommendationRestorer::StartTimer() {
// Listen for user activity so that the timer can be reset while the user is // Listen for user activity so that the timer can be reset while the user is
// active, causing it to fire only when the user remains idle for // active, causing it to fire only when the user remains idle for
// |kRestoreDelayInMs|. // |kRestoreDelayInMinutes|.
ui::UserActivityDetector* user_activity_detector = ui::UserActivityDetector* user_activity_detector =
ui::UserActivityDetector::Get(); ui::UserActivityDetector::Get();
if (user_activity_detector && !user_activity_detector->HasObserver(this)) if (user_activity_detector && !user_activity_detector->HasObserver(this))
...@@ -136,16 +115,16 @@ void RecommendationRestorer::StartTimer() { ...@@ -136,16 +115,16 @@ void RecommendationRestorer::StartTimer() {
// case of a recommended value changing, a single timer is a close // case of a recommended value changing, a single timer is a close
// approximation of the behavior that would be obtained by resetting the timer // approximation of the behavior that would be obtained by resetting the timer
// for the affected pref only. // for the affected pref only.
restore_timer_.Start(FROM_HERE, restore_timer_.Start(
base::TimeDelta::FromMilliseconds(kRestoreDelayInMs), FROM_HERE, kRestoreDelayInMinutes,
base::Bind(&RecommendationRestorer::RestoreAll, base::BindRepeating(&PolicyRecommendationRestorer::RestoreAll,
base::Unretained(this))); base::Unretained(this)));
} }
void RecommendationRestorer::StopTimer() { void PolicyRecommendationRestorer::StopTimer() {
restore_timer_.Stop(); restore_timer_.Stop();
if (ui::UserActivityDetector::Get()) if (ui::UserActivityDetector::Get())
ui::UserActivityDetector::Get()->RemoveObserver(this); ui::UserActivityDetector::Get()->RemoveObserver(this);
} }
} // namespace policy } // namespace ash
// Copyright 2018 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.
#ifndef ASH_POLICY_POLICY_RECOMMENDATION_RESTORER_H_
#define ASH_POLICY_POLICY_RECOMMENDATION_RESTORER_H_
#include <memory>
#include <set>
#include <string>
#include "ash/session/session_observer.h"
#include "base/macros.h"
#include "base/timer/timer.h"
#include "ui/base/user_activity/user_activity_observer.h"
class PrefChangeRegistrar;
class PrefService;
namespace ash {
// Manages observing a set of prefs on signin screen. If any of the prefs has a
// recommended value on observing, or changed to have recommended value or
// active user session started, its user settings is cleared so that the
// recommendation can take effect. On signin screen prefs, user settings are
// cleared when the user becomes idle for one minute.
//
// The above efforts are made to ensure that the observed prefs are *policy*
// overridden and can be restored properly. For example, a demo device on a
// store shelf. One customer walks up to device and enables some a11y features,
// leaving the device in a "funny" state (high contrast, screen magnifier,
// spoken feedback enabled). After some time, another customer won't feel the
// device looks "broken".
class PolicyRecommendationRestorer : public SessionObserver,
public ui::UserActivityObserver {
public:
PolicyRecommendationRestorer();
~PolicyRecommendationRestorer() override;
// Caller calls to start observing recommended value for |pref_name|. It
// should be called when signin pref service is connected but before
// observing/loading user settings for |pref_name|.
void ObservePref(const std::string& pref_name);
// SessionObserver:
void OnActiveUserPrefServiceChanged(PrefService* pref_service) override;
// ui::UserActivityObserver:
void OnUserActivity(const ui::Event* event) override;
base::OneShotTimer* restore_timer_for_test() { return &restore_timer_; }
private:
// If a recommended value and a user setting exist for |pref_name|, clears the
// user setting so that the recommended value can take effect. If
// |allow_delay| is |true| and user prefs not started yet, a timer is started
// that will clear the setting when the user becomes idle for one minute.
// Otherwise, the setting is cleared immediately.
void Restore(bool allow_delay, const std::string& pref_name);
void RestoreAll();
void StartTimer();
void StopTimer();
std::set<std::string> pref_names_;
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
bool active_user_pref_connected_ = false;
base::OneShotTimer restore_timer_;
DISALLOW_COPY_AND_ASSIGN(PolicyRecommendationRestorer);
};
} // namespace ash
#endif // ASH_POLICY_POLICY_RECOMMENDATION_RESTORER_H_
This diff is collapsed.
...@@ -22,6 +22,8 @@ namespace ash { ...@@ -22,6 +22,8 @@ namespace ash {
namespace { namespace {
bool g_provide_signin_pref_service = true;
// Returns the "canonicalized" email from a given |email| address. Note // Returns the "canonicalized" email from a given |email| address. Note
// production code should use gaia::CanonicalizeEmail. This is used in tests // production code should use gaia::CanonicalizeEmail. This is used in tests
// without introducing dependency on google_api. // without introducing dependency on google_api.
...@@ -33,6 +35,11 @@ std::string GetUserIdFromEmail(const std::string& email) { ...@@ -33,6 +35,11 @@ std::string GetUserIdFromEmail(const std::string& email) {
} // namespace } // namespace
// static
void TestSessionControllerClient::DisableAutomaticallyProvideSigninPref() {
g_provide_signin_pref_service = false;
}
TestSessionControllerClient::TestSessionControllerClient( TestSessionControllerClient::TestSessionControllerClient(
SessionController* controller) SessionController* controller)
: controller_(controller), binding_(this) { : controller_(controller), binding_(this) {
...@@ -64,7 +71,8 @@ void TestSessionControllerClient::Reset() { ...@@ -64,7 +71,8 @@ void TestSessionControllerClient::Reset() {
controller_->ClearUserSessionsForTest(); controller_->ClearUserSessionsForTest();
controller_->SetSessionInfo(session_info_->Clone()); controller_->SetSessionInfo(session_info_->Clone());
if (!controller_->GetSigninScreenPrefService()) { if (g_provide_signin_pref_service &&
!controller_->GetSigninScreenPrefService()) {
auto pref_service = std::make_unique<TestingPrefServiceSimple>(); auto pref_service = std::make_unique<TestingPrefServiceSimple>();
Shell::RegisterSigninProfilePrefs(pref_service->registry(), Shell::RegisterSigninProfilePrefs(pref_service->registry(),
true /* for_test */); true /* for_test */);
......
...@@ -33,6 +33,8 @@ class TestSessionControllerClient : public ash::mojom::SessionControllerClient { ...@@ -33,6 +33,8 @@ class TestSessionControllerClient : public ash::mojom::SessionControllerClient {
explicit TestSessionControllerClient(SessionController* controller); explicit TestSessionControllerClient(SessionController* controller);
~TestSessionControllerClient() override; ~TestSessionControllerClient() override;
static void DisableAutomaticallyProvideSigninPref();
// Initialize using existing info in |controller| and bind as its client. // Initialize using existing info in |controller| and bind as its client.
void InitializeAndBind(); void InitializeAndBind();
......
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
#include "ash/multi_device_setup/multi_device_notification_presenter.h" #include "ash/multi_device_setup/multi_device_notification_presenter.h"
#include "ash/new_window_controller.h" #include "ash/new_window_controller.h"
#include "ash/note_taking_controller.h" #include "ash/note_taking_controller.h"
#include "ash/policy/policy_recommendation_restorer.h"
#include "ash/public/cpp/ash_constants.h" #include "ash/public/cpp/ash_constants.h"
#include "ash/public/cpp/ash_features.h" #include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/ash_switches.h" #include "ash/public/cpp/ash_switches.h"
...@@ -878,6 +879,7 @@ Shell::~Shell() { ...@@ -878,6 +879,7 @@ Shell::~Shell() {
accessibility_controller_.reset(); accessibility_controller_.reset();
accessibility_delegate_.reset(); accessibility_delegate_.reset();
accessibility_focus_ring_controller_.reset(); accessibility_focus_ring_controller_.reset();
policy_recommendation_restorer_.reset();
// Balances the Install() in Initialize(). // Balances the Install() in Initialize().
views::FocusManagerFactory::Install(nullptr); views::FocusManagerFactory::Install(nullptr);
...@@ -976,6 +978,8 @@ void Shell::Init(ui::ContextFactory* context_factory, ...@@ -976,6 +978,8 @@ void Shell::Init(ui::ContextFactory* context_factory,
detachable_base_notification_controller_ = detachable_base_notification_controller_ =
std::make_unique<DetachableBaseNotificationController>( std::make_unique<DetachableBaseNotificationController>(
detachable_base_handler_.get()); detachable_base_handler_.get());
policy_recommendation_restorer_ =
std::make_unique<PolicyRecommendationRestorer>();
screen_switch_check_controller_ = screen_switch_check_controller_ =
std::make_unique<ScreenSwitchCheckController>(); std::make_unique<ScreenSwitchCheckController>();
// Connector can be null in tests. // Connector can be null in tests.
......
...@@ -142,6 +142,7 @@ class OverlayEventFilter; ...@@ -142,6 +142,7 @@ class OverlayEventFilter;
class PartialMagnificationController; class PartialMagnificationController;
class PeripheralBatteryNotifier; class PeripheralBatteryNotifier;
class PersistentWindowController; class PersistentWindowController;
class PolicyRecommendationRestorer;
class PowerButtonController; class PowerButtonController;
class PowerEventObserver; class PowerEventObserver;
class PowerPrefs; class PowerPrefs;
...@@ -460,6 +461,9 @@ class ASH_EXPORT Shell : public SessionObserver, ...@@ -460,6 +461,9 @@ class ASH_EXPORT Shell : public SessionObserver,
PartialMagnificationController* partial_magnification_controller() { PartialMagnificationController* partial_magnification_controller() {
return partial_magnification_controller_.get(); return partial_magnification_controller_.get();
} }
PolicyRecommendationRestorer* policy_recommendation_restorer() {
return policy_recommendation_restorer_.get();
}
PowerButtonController* power_button_controller() { PowerButtonController* power_button_controller() {
return power_button_controller_.get(); return power_button_controller_.get();
} }
...@@ -756,6 +760,7 @@ class ASH_EXPORT Shell : public SessionObserver, ...@@ -756,6 +760,7 @@ class ASH_EXPORT Shell : public SessionObserver,
std::unique_ptr<SessionController> session_controller_; std::unique_ptr<SessionController> session_controller_;
std::unique_ptr<NightLightController> night_light_controller_; std::unique_ptr<NightLightController> night_light_controller_;
std::unique_ptr<NoteTakingController> note_taking_controller_; std::unique_ptr<NoteTakingController> note_taking_controller_;
std::unique_ptr<PolicyRecommendationRestorer> policy_recommendation_restorer_;
std::unique_ptr<ScreenSwitchCheckController> screen_switch_check_controller_; std::unique_ptr<ScreenSwitchCheckController> screen_switch_check_controller_;
std::unique_ptr<ShelfController> shelf_controller_; std::unique_ptr<ShelfController> shelf_controller_;
std::unique_ptr<ShelfWindowWatcher> shelf_window_watcher_; std::unique_ptr<ShelfWindowWatcher> shelf_window_watcher_;
......
...@@ -1394,10 +1394,6 @@ source_set("chromeos") { ...@@ -1394,10 +1394,6 @@ source_set("chromeos") {
"policy/policy_oauth2_token_fetcher.h", "policy/policy_oauth2_token_fetcher.h",
"policy/pre_signin_policy_fetcher.cc", "policy/pre_signin_policy_fetcher.cc",
"policy/pre_signin_policy_fetcher.h", "policy/pre_signin_policy_fetcher.h",
"policy/recommendation_restorer.cc",
"policy/recommendation_restorer.h",
"policy/recommendation_restorer_factory.cc",
"policy/recommendation_restorer_factory.h",
"policy/remote_commands/affiliated_remote_commands_invalidator.cc", "policy/remote_commands/affiliated_remote_commands_invalidator.cc",
"policy/remote_commands/affiliated_remote_commands_invalidator.h", "policy/remote_commands/affiliated_remote_commands_invalidator.h",
"policy/remote_commands/device_command_fetch_status_job.cc", "policy/remote_commands/device_command_fetch_status_job.cc",
...@@ -2061,7 +2057,6 @@ source_set("unit_tests") { ...@@ -2061,7 +2057,6 @@ source_set("unit_tests") {
"policy/off_hours/off_hours_proto_parser_unittest.cc", "policy/off_hours/off_hours_proto_parser_unittest.cc",
"policy/off_hours/weekly_time_unittest.cc", "policy/off_hours/weekly_time_unittest.cc",
"policy/pre_signin_policy_fetcher_unittest.cc", "policy/pre_signin_policy_fetcher_unittest.cc",
"policy/recommendation_restorer_unittest.cc",
"policy/remote_commands/device_command_screenshot_job_unittest.cc", "policy/remote_commands/device_command_screenshot_job_unittest.cc",
"policy/remote_commands/device_command_set_volume_job_unittest.cc", "policy/remote_commands/device_command_set_volume_job_unittest.cc",
"policy/secondary_google_account_signin_policy_handler_unittest.cc", "policy/secondary_google_account_signin_policy_handler_unittest.cc",
......
// Copyright 2013 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.
#ifndef CHROME_BROWSER_CHROMEOS_POLICY_RECOMMENDATION_RESTORER_H_
#define CHROME_BROWSER_CHROMEOS_POLICY_RECOMMENDATION_RESTORER_H_
#include <string>
#include "base/macros.h"
#include "base/timer/timer.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/prefs/pref_change_registrar.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/base/user_activity/user_activity_observer.h"
class Profile;
namespace policy {
// Observes a set of prefs in the login profile. If any of the prefs has a
// recommended value, its user setting is cleared so that the recommendation can
// take effect. This happens immediately when the login screen is shown, when
// a session is being started and whenever recommended values change during a
// user session. On the login screen, user settings are cleared when the user
// becomes idle for one minute.
class RecommendationRestorer : public KeyedService,
public content::NotificationObserver,
public ui::UserActivityObserver {
public:
explicit RecommendationRestorer(Profile* profile);
~RecommendationRestorer() override;
// KeyedService:
void Shutdown() override;
// content::NotificationObserver:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
// ui::UserActivityObserver:
void OnUserActivity(const ui::Event* event) override;
// If a recommended value and a user setting exist for |pref_name|, clears the
// user setting so that the recommended value can take effect. If
// |allow_delay| is |true| and the login screen is being shown, a timer is
// started that will clear the setting when the user becomes idle for one
// minute. Otherwise, the setting is cleared immediately.
void Restore(bool allow_delay, const std::string& pref_name);
private:
friend class RecommendationRestorerTest;
void RestoreAll();
void StartTimer();
void StopTimer();
PrefChangeRegistrar pref_change_registrar_;
content::NotificationRegistrar notification_registrar_;
bool logged_in_;
base::OneShotTimer restore_timer_;
DISALLOW_COPY_AND_ASSIGN(RecommendationRestorer);
};
} // namespace policy
#endif // CHROME_BROWSER_CHROMEOS_POLICY_RECOMMENDATION_RESTORER_H_
// Copyright 2013 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/policy/recommendation_restorer_factory.h"
#include "chrome/browser/chromeos/policy/recommendation_restorer.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "content/public/browser/browser_context.h"
namespace policy {
// static
RecommendationRestorerFactory* RecommendationRestorerFactory::GetInstance() {
return base::Singleton<RecommendationRestorerFactory>::get();
}
// static
RecommendationRestorer* RecommendationRestorerFactory::GetForProfile(
Profile* profile) {
return reinterpret_cast<RecommendationRestorer*>(
GetInstance()->GetServiceForBrowserContext(profile, false));
}
KeyedService* RecommendationRestorerFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new RecommendationRestorer(static_cast<Profile*>(context));
}
bool RecommendationRestorerFactory::ServiceIsCreatedWithBrowserContext() const {
return true;
}
RecommendationRestorerFactory::RecommendationRestorerFactory()
: BrowserContextKeyedServiceFactory(
"RecommendationRestorer",
BrowserContextDependencyManager::GetInstance()) {
}
RecommendationRestorerFactory::~RecommendationRestorerFactory() {
}
} // namespace policy
// Copyright 2013 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.
#ifndef CHROME_BROWSER_CHROMEOS_POLICY_RECOMMENDATION_RESTORER_FACTORY_H_
#define CHROME_BROWSER_CHROMEOS_POLICY_RECOMMENDATION_RESTORER_FACTORY_H_
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class Profile;
namespace policy {
class RecommendationRestorer;
class RecommendationRestorerFactory : public BrowserContextKeyedServiceFactory {
public:
static RecommendationRestorerFactory* GetInstance();
static RecommendationRestorer* GetForProfile(Profile* profile);
protected:
// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
bool ServiceIsCreatedWithBrowserContext() const override;
private:
friend struct base::DefaultSingletonTraits<RecommendationRestorerFactory>;
RecommendationRestorerFactory();
~RecommendationRestorerFactory() override;
DISALLOW_COPY_AND_ASSIGN(RecommendationRestorerFactory);
};
} // namespace policy
#endif // CHROME_BROWSER_CHROMEOS_POLICY_RECOMMENDATION_RESTORER_FACTORY_H_
...@@ -105,7 +105,6 @@ ...@@ -105,7 +105,6 @@
#include "chrome/browser/chromeos/cryptauth/chrome_cryptauth_service_factory.h" #include "chrome/browser/chromeos/cryptauth/chrome_cryptauth_service_factory.h"
#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_factory.h" #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_factory.h"
#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
#include "chrome/browser/chromeos/policy/recommendation_restorer_factory.h"
#include "chrome/browser/chromeos/policy/user_cloud_policy_token_forwarder_factory.h" #include "chrome/browser/chromeos/policy/user_cloud_policy_token_forwarder_factory.h"
#include "chrome/browser/chromeos/policy/user_network_configuration_updater_factory.h" #include "chrome/browser/chromeos/policy/user_network_configuration_updater_factory.h"
#include "chrome/browser/chromeos/policy/user_policy_manager_factory_chromeos.h" #include "chrome/browser/chromeos/policy/user_policy_manager_factory_chromeos.h"
...@@ -320,7 +319,6 @@ void ChromeBrowserMainExtraPartsProfiles:: ...@@ -320,7 +319,6 @@ void ChromeBrowserMainExtraPartsProfiles::
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
chromeos::OwnerSettingsServiceChromeOSFactory::GetInstance(); chromeos::OwnerSettingsServiceChromeOSFactory::GetInstance();
policy::PolicyCertServiceFactory::GetInstance(); policy::PolicyCertServiceFactory::GetInstance();
policy::RecommendationRestorerFactory::GetInstance();
policy::UserPolicyManagerFactoryChromeOS::GetInstance(); policy::UserPolicyManagerFactoryChromeOS::GetInstance();
policy::UserCloudPolicyTokenForwarderFactory::GetInstance(); policy::UserCloudPolicyTokenForwarderFactory::GetInstance();
policy::UserNetworkConfigurationUpdaterFactory::GetInstance(); policy::UserNetworkConfigurationUpdaterFactory::GetInstance();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment