OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_PROTECTOR_PROTECTED_PREFS_WATCHER_H_ | |
6 #define CHROME_BROWSER_PROTECTOR_PROTECTED_PREFS_WATCHER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/prefs/public/pref_change_registrar.h" | |
13 #include "chrome/browser/extensions/extension_prefs.h" | |
14 | |
15 class PrefService; | |
16 class Profile; | |
17 | |
18 namespace base { | |
19 class Value; | |
20 } | |
21 | |
22 namespace protector { | |
23 | |
24 class ProtectedPrefsWatcher { | |
25 public: | |
26 // Current backup version. | |
27 static const int kCurrentVersionNumber; | |
28 | |
29 explicit ProtectedPrefsWatcher(Profile* profile); | |
30 virtual ~ProtectedPrefsWatcher(); | |
31 | |
32 // Registers prefs on a new Profile instance. | |
33 static void RegisterUserPrefs(PrefService* prefs); | |
34 | |
35 // Returns true if pref named |path| has changed and the backup is valid. | |
36 bool DidPrefChange(const std::string& path) const; | |
37 | |
38 // Returns the backup value for pref named |path| or |NULL| if the pref is not | |
39 // protected, does not exist or the backup is invalid. The returned Value | |
40 // instance is owned by the PrefService. | |
41 const base::Value* GetBackupForPref(const std::string& path) const; | |
42 | |
43 // Forces a valid backup, matching actual preferences (overwriting any | |
44 // previous data). Should only be when protector service is disabled. | |
45 void ForceUpdateBackup(); | |
46 | |
47 // True if the backup was valid at the profile load time. | |
48 bool is_backup_valid() { return is_backup_valid_; } | |
49 | |
50 private: | |
51 friend class ProtectedPrefsWatcherTest; | |
52 | |
53 void OnPreferenceChanged(const std::string& pref_name); | |
54 | |
55 // Makes sure that all protected prefs have been migrated before starting to | |
56 // observe them. | |
57 void EnsurePrefsMigration(); | |
58 | |
59 // Updates cached prefs from their actual values and returns |true| if there | |
60 // were any changes. | |
61 bool UpdateCachedPrefs(); | |
62 | |
63 // Returns |false| if profile does not have a backup yet (needs to be | |
64 // initialized). | |
65 bool HasBackup() const; | |
66 | |
67 // Creates initial backup entries. | |
68 void InitBackup(); | |
69 | |
70 // Migrates backup if it is an older version. | |
71 void MigrateOldBackupIfNeeded(); | |
72 | |
73 // Updates the backup entry for |path| and returns |true| if the backup has | |
74 // changed. | |
75 bool UpdateBackupEntry(const std::string& path); | |
76 | |
77 // Perform a check that backup is valid and settings have not been modified. | |
78 void ValidateBackup(); | |
79 | |
80 // Returns |true| if backup signature is valid. | |
81 bool IsSignatureValid() const; | |
82 | |
83 // Updates the backup signature. | |
84 void UpdateBackupSignature(); | |
85 | |
86 // Returns data to be signed as string. | |
87 std::string GetSignatureData(PrefService* prefs) const; | |
88 | |
89 // Cached set of extension IDs. They are not changed as frequently | |
90 extensions::ExtensionIdList cached_extension_ids_; | |
91 | |
92 PrefChangeRegistrar pref_observer_; | |
93 | |
94 // True if the backup was valid at the profile load time. | |
95 bool is_backup_valid_; | |
96 | |
97 Profile* profile_; | |
98 | |
99 DISALLOW_COPY_AND_ASSIGN(ProtectedPrefsWatcher); | |
100 }; | |
101 | |
102 } // namespace protector | |
103 | |
104 #endif // CHROME_BROWSER_PROTECTOR_PROTECTED_PREFS_WATCHER_H_ | |
OLD | NEW |