1 // Copyright 2013 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.
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_RECOMMENDATION_RESTORER_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_RECOMMENDATION_RESTORER_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/prefs/pref_change_registrar.h"
13 #include "base/timer/timer.h"
14 #include "components/keyed_service/core/keyed_service.h"
15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
17 #include "ui/base/user_activity/user_activity_observer.h"
23 // Observes a set of prefs in the login profile. If any of the prefs has a
24 // recommended value, its user setting is cleared so that the recommendation can
25 // take effect. This happens immediately when the login screen is shown, when
26 // a session is being started and whenever recommended values change during a
27 // user session. On the login screen, user settings are cleared when the user
28 // becomes idle for one minute.
29 class RecommendationRestorer
: public KeyedService
,
30 public content::NotificationObserver
,
31 public ui::UserActivityObserver
{
33 explicit RecommendationRestorer(Profile
* profile
);
34 ~RecommendationRestorer() override
;
37 void Shutdown() override
;
39 // content::NotificationObserver:
40 void Observe(int type
,
41 const content::NotificationSource
& source
,
42 const content::NotificationDetails
& details
) override
;
44 // ui::UserActivityObserver:
45 void OnUserActivity(const ui::Event
* event
) override
;
47 // If a recommended value and a user setting exist for |pref_name|, clears the
48 // user setting so that the recommended value can take effect. If
49 // |allow_delay| is |true| and the login screen is being shown, a timer is
50 // started that will clear the setting when the user becomes idle for one
51 // minute. Otherwise, the setting is cleared immediately.
52 void Restore(bool allow_delay
, const std::string
& pref_name
);
55 friend class RecommendationRestorerTest
;
62 PrefChangeRegistrar pref_change_registrar_
;
63 content::NotificationRegistrar notification_registrar_
;
67 base::OneShotTimer
<RecommendationRestorer
> restore_timer_
;
69 DISALLOW_COPY_AND_ASSIGN(RecommendationRestorer
);
74 #endif // CHROME_BROWSER_CHROMEOS_POLICY_RECOMMENDATION_RESTORER_H_