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 #pragma once |
| 8 |
| 9 #include <string> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "chrome/browser/extensions/extension_prefs.h" |
| 14 #include "content/public/browser/notification_observer.h" |
| 15 |
| 16 class PrefService; |
| 17 class PrefSetObserver; |
| 18 class Profile; |
| 19 |
| 20 namespace base { |
| 21 class Value; |
| 22 } |
| 23 |
| 24 namespace protector { |
| 25 |
| 26 class ProtectedPrefsWatcher : public content::NotificationObserver { |
| 27 public: |
| 28 explicit ProtectedPrefsWatcher(Profile* profile); |
| 29 virtual ~ProtectedPrefsWatcher(); |
| 30 |
| 31 // Registers prefs on a new Profile instance. |
| 32 static void RegisterUserPrefs(PrefService* prefs); |
| 33 |
| 34 // Returns the backup value for pref named |path| or |NULL| if the pref is |
| 35 // not protected or does not exist. The returned Value instance is owned by |
| 36 // the PrefService. |
| 37 const base::Value* GetBackupForPref(const std::string& path) const; |
| 38 |
| 39 // True if the backup was valid at the profile load time. |
| 40 bool is_backup_valid() { return is_backup_valid_; } |
| 41 |
| 42 private: |
| 43 friend class ProtectedPrefsWatcherTest; |
| 44 |
| 45 // content::NotificationObserver overrides: |
| 46 virtual void Observe(int type, |
| 47 const content::NotificationSource& source, |
| 48 const content::NotificationDetails& details) OVERRIDE; |
| 49 |
| 50 // Makes sure that all protected prefs have been migrated before starting to |
| 51 // observe them. |
| 52 void EnsurePrefsMigration(); |
| 53 |
| 54 // Updates cached prefs from their actual values and returns |true| if there |
| 55 // were any changes. |
| 56 bool UpdateCachedPrefs(); |
| 57 |
| 58 // Returns |false| if profile does not have a backup yet (needs to be |
| 59 // initialized). |
| 60 bool HasBackup() const; |
| 61 |
| 62 // Creates initial backup entries. |
| 63 void InitBackup(); |
| 64 |
| 65 // Updates the backup утекн for |pref_name| and кeturns |true| if the |
| 66 // backup has changed. |
| 67 bool UpdateBackupEntry(const std::string& pref_name); |
| 68 |
| 69 // Updates the backup signature. |
| 70 void UpdateBackupSignature(); |
| 71 |
| 72 // Perform a check that backup is valid and settings have not been modified. |
| 73 void ValidateBackup(); |
| 74 |
| 75 // Returns |true| if backup signature is valid. |
| 76 bool IsSignatureValid() const; |
| 77 |
| 78 // Returns data to be signed as string. |
| 79 std::string GetSignatureData(PrefService* prefs) const; |
| 80 |
| 81 // Cached set of extension IDs. They are not changed as frequently |
| 82 ExtensionPrefs::ExtensionIdSet cached_extension_ids_; |
| 83 |
| 84 scoped_ptr<PrefSetObserver> pref_observer_; |
| 85 |
| 86 // True if the backup was valid at the profile load time. |
| 87 bool is_backup_valid_; |
| 88 |
| 89 Profile* profile_; |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(ProtectedPrefsWatcher); |
| 92 }; |
| 93 |
| 94 } // namespace protector |
| 95 |
| 96 #endif // CHROME_BROWSER_PROTECTOR_PROTECTED_PREFS_WATCHER_H_ |
OLD | NEW |