| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_RECOMMENDATION_RESTORER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_POLICY_RECOMMENDATION_RESTORER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "ash/wm/user_activity_observer.h" | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/compiler_specific.h" | |
| 13 #include "base/prefs/pref_change_registrar.h" | |
| 14 #include "base/timer.h" | |
| 15 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | |
| 16 #include "content/public/browser/notification_observer.h" | |
| 17 #include "content/public/browser/notification_registrar.h" | |
| 18 | |
| 19 class Profile; | |
| 20 | |
| 21 namespace policy { | |
| 22 | |
| 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 BrowserContextKeyedService, | |
| 30 public content::NotificationObserver, | |
| 31 public ash::UserActivityObserver { | |
| 32 public: | |
| 33 explicit RecommendationRestorer(Profile* profile); | |
| 34 virtual ~RecommendationRestorer(); | |
| 35 | |
| 36 // BrowserContextKeyedService: | |
| 37 virtual void Shutdown() OVERRIDE; | |
| 38 | |
| 39 // content::NotificationObserver: | |
| 40 virtual void Observe(int type, | |
| 41 const content::NotificationSource& source, | |
| 42 const content::NotificationDetails& details) OVERRIDE; | |
| 43 | |
| 44 // ash::UserActivityObserver::Observer: | |
| 45 virtual void OnUserActivity() OVERRIDE; | |
| 46 | |
| 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); | |
| 53 | |
| 54 private: | |
| 55 friend class RecommendationRestorerTest; | |
| 56 | |
| 57 void RestoreAll(); | |
| 58 | |
| 59 void StartTimer(); | |
| 60 void StopTimer(); | |
| 61 | |
| 62 PrefChangeRegistrar pref_change_registrar_; | |
| 63 content::NotificationRegistrar notification_registrar_; | |
| 64 | |
| 65 bool logged_in_; | |
| 66 | |
| 67 base::OneShotTimer<RecommendationRestorer> restore_timer_; | |
| 68 | |
| 69 DISALLOW_COPY_AND_ASSIGN(RecommendationRestorer); | |
| 70 }; | |
| 71 | |
| 72 } // namespace policy | |
| 73 | |
| 74 #endif // CHROME_BROWSER_CHROMEOS_POLICY_RECOMMENDATION_RESTORER_H_ | |
| OLD | NEW |