OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_PROTECTOR_PROTECTED_PREFS_WATCHER_H_ | 5 #ifndef CHROME_BROWSER_PROTECTOR_PROTECTED_PREFS_WATCHER_H_ |
6 #define CHROME_BROWSER_PROTECTOR_PROTECTED_PREFS_WATCHER_H_ | 6 #define CHROME_BROWSER_PROTECTOR_PROTECTED_PREFS_WATCHER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/prefs/public/pref_change_registrar.h" | 12 #include "base/prefs/public/pref_change_registrar.h" |
| 13 #include "base/prefs/public/pref_observer.h" |
13 #include "chrome/browser/extensions/extension_prefs.h" | 14 #include "chrome/browser/extensions/extension_prefs.h" |
14 #include "content/public/browser/notification_observer.h" | |
15 | 15 |
16 class PrefService; | 16 class PrefService; |
17 class Profile; | 17 class Profile; |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class Value; | 20 class Value; |
21 } | 21 } |
22 | 22 |
23 namespace protector { | 23 namespace protector { |
24 | 24 |
25 class ProtectedPrefsWatcher : public content::NotificationObserver { | 25 class ProtectedPrefsWatcher : public PrefObserver { |
26 public: | 26 public: |
27 // Current backup version. | 27 // Current backup version. |
28 static const int kCurrentVersionNumber; | 28 static const int kCurrentVersionNumber; |
29 | 29 |
30 explicit ProtectedPrefsWatcher(Profile* profile); | 30 explicit ProtectedPrefsWatcher(Profile* profile); |
31 virtual ~ProtectedPrefsWatcher(); | 31 virtual ~ProtectedPrefsWatcher(); |
32 | 32 |
33 // Registers prefs on a new Profile instance. | 33 // Registers prefs on a new Profile instance. |
34 static void RegisterUserPrefs(PrefService* prefs); | 34 static void RegisterUserPrefs(PrefService* prefs); |
35 | 35 |
36 // Returns true if pref named |path| has changed and the backup is valid. | 36 // Returns true if pref named |path| has changed and the backup is valid. |
37 bool DidPrefChange(const std::string& path) const; | 37 bool DidPrefChange(const std::string& path) const; |
38 | 38 |
39 // Returns the backup value for pref named |path| or |NULL| if the pref is not | 39 // Returns the backup value for pref named |path| or |NULL| if the pref is not |
40 // protected, does not exist or the backup is invalid. The returned Value | 40 // protected, does not exist or the backup is invalid. The returned Value |
41 // instance is owned by the PrefService. | 41 // instance is owned by the PrefService. |
42 const base::Value* GetBackupForPref(const std::string& path) const; | 42 const base::Value* GetBackupForPref(const std::string& path) const; |
43 | 43 |
44 // Forces a valid backup, matching actual preferences (overwriting any | 44 // Forces a valid backup, matching actual preferences (overwriting any |
45 // previous data). Should only be when protector service is disabled. | 45 // previous data). Should only be when protector service is disabled. |
46 void ForceUpdateBackup(); | 46 void ForceUpdateBackup(); |
47 | 47 |
48 // True if the backup was valid at the profile load time. | 48 // True if the backup was valid at the profile load time. |
49 bool is_backup_valid() { return is_backup_valid_; } | 49 bool is_backup_valid() { return is_backup_valid_; } |
50 | 50 |
51 private: | 51 private: |
52 friend class ProtectedPrefsWatcherTest; | 52 friend class ProtectedPrefsWatcherTest; |
53 | 53 |
54 // content::NotificationObserver overrides: | 54 // PrefObserver overrides: |
55 virtual void Observe(int type, | 55 virtual void OnPreferenceChanged(PrefServiceBase* service, |
56 const content::NotificationSource& source, | 56 const std::string& pref_name) OVERRIDE; |
57 const content::NotificationDetails& details) OVERRIDE; | |
58 | 57 |
59 // Makes sure that all protected prefs have been migrated before starting to | 58 // Makes sure that all protected prefs have been migrated before starting to |
60 // observe them. | 59 // observe them. |
61 void EnsurePrefsMigration(); | 60 void EnsurePrefsMigration(); |
62 | 61 |
63 // Updates cached prefs from their actual values and returns |true| if there | 62 // Updates cached prefs from their actual values and returns |true| if there |
64 // were any changes. | 63 // were any changes. |
65 bool UpdateCachedPrefs(); | 64 bool UpdateCachedPrefs(); |
66 | 65 |
67 // Returns |false| if profile does not have a backup yet (needs to be | 66 // Returns |false| if profile does not have a backup yet (needs to be |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 bool is_backup_valid_; | 98 bool is_backup_valid_; |
100 | 99 |
101 Profile* profile_; | 100 Profile* profile_; |
102 | 101 |
103 DISALLOW_COPY_AND_ASSIGN(ProtectedPrefsWatcher); | 102 DISALLOW_COPY_AND_ASSIGN(ProtectedPrefsWatcher); |
104 }; | 103 }; |
105 | 104 |
106 } // namespace protector | 105 } // namespace protector |
107 | 106 |
108 #endif // CHROME_BROWSER_PROTECTOR_PROTECTED_PREFS_WATCHER_H_ | 107 #endif // CHROME_BROWSER_PROTECTOR_PROTECTED_PREFS_WATCHER_H_ |
OLD | NEW |