 Chromium Code Reviews
 Chromium Code Reviews Issue 5441002:
  Clean up pref change notification handling.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 5441002:
  Clean up pref change notification handling.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_EXTENSIONS_EXTENSION_PREF_STORE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_STORE_H_ | 
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_STORE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_STORE_H_ | 
| 7 #pragma once | 7 #pragma once | 
| 8 | 8 | 
| 9 #include <list> | 9 #include <list> | 
| 10 #include <map> | 10 #include <map> | 
| 11 #include <string> | 11 #include <string> | 
| 12 #include <utility> | 12 #include <utility> | 
| 13 #include <vector> | 13 #include <vector> | 
| 14 | 14 | 
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" | 
| 16 #include "base/scoped_ptr.h" | 16 #include "base/scoped_ptr.h" | 
| 17 #include "base/stl_util-inl.h" | 17 #include "base/stl_util-inl.h" | 
| 18 #include "chrome/browser/prefs/pref_notifier.h" | |
| 19 #include "chrome/common/notification_observer.h" | 18 #include "chrome/common/notification_observer.h" | 
| 20 #include "chrome/common/notification_registrar.h" | 19 #include "chrome/common/notification_registrar.h" | 
| 21 #include "chrome/common/pref_store.h" | 20 #include "chrome/common/pref_store_base.h" | 
| 22 | 21 | 
| 23 class DictionaryValue; | 22 class DictionaryValue; | 
| 24 class Extension; | 23 class Extension; | 
| 25 class PrefService; | 24 class PrefService; | 
| 26 class Profile; | 25 class Profile; | 
| 27 class Value; | 26 class Value; | 
| 28 | 27 | 
| 29 // This PrefStore keeps track of preferences set by extensions: for example, | 28 // This PrefStore keeps track of preferences set by extensions: for example, | 
| 30 // proxy settings. A stack of relevant extensions is stored in order of | 29 // proxy settings. A stack of relevant extensions is stored in order of | 
| 31 // their addition to this PrefStore. For each preference, the last-added | 30 // their addition to this PrefStore. For each preference, the last-added | 
| 32 // enabled extension that tries to set it overrules any others. | 31 // enabled extension that tries to set it overrules any others. | 
| 33 class ExtensionPrefStore : public PrefStore, | 32 class ExtensionPrefStore : public PrefStoreBase, | 
| 34 public NotificationObserver { | 33 public NotificationObserver { | 
| 
battre (please use the other)
2010/12/02 10:41:19
ExtensionPrefStore will be replaced by something c
 
Mattias Nissler (ping if slow)
2010/12/02 16:38:24
I treat this as an FYI even though I already knew
 | |
| 35 public: | 34 public: | 
| 36 // Maps preference paths to their values. | 35 // Maps preference paths to their values. | 
| 37 typedef std::map<const char*, Value*> PrefValueMap; | 36 typedef std::map<const char*, Value*> PrefValueMap; | 
| 38 | 37 | 
| 39 // The type passed as Details for an EXTENSION_PREF_CHANGED notification. | 38 // The type passed as Details for an EXTENSION_PREF_CHANGED notification. | 
| 40 // The nested pairs are <extension, <pref_path, pref_value> >. This is here, | 39 // The nested pairs are <extension, <pref_path, pref_value> >. This is here, | 
| 41 // rather than in (say) notification_type.h, to keep the dependency on | 40 // rather than in (say) notification_type.h, to keep the dependency on | 
| 42 // std::pair out of the many places that include notification_type.h. | 41 // std::pair out of the many places that include notification_type.h. | 
| 43 typedef std::pair<const Extension*, std::pair<const char*, Value*> > | 42 typedef std::pair<const Extension*, std::pair<const char*, Value*> > | 
| 44 ExtensionPrefDetails; | 43 ExtensionPrefDetails; | 
| 45 | 44 | 
| 46 ExtensionPrefStore(Profile* profile, PrefNotifier::PrefStoreType type); | 45 ExtensionPrefStore(Profile* profile); | 
| 47 virtual ~ExtensionPrefStore(); | 46 virtual ~ExtensionPrefStore(); | 
| 48 | 47 | 
| 49 // Begins tracking the preference and value an extension wishes to set. This | 48 // Begins tracking the preference and value an extension wishes to set. This | 
| 50 // must be called each time an extension API tries to set a preference. | 49 // must be called each time an extension API tries to set a preference. | 
| 51 // The ExtensionPrefStore will take ownership of the |pref_value|. | 50 // The ExtensionPrefStore will take ownership of the |pref_value|. | 
| 52 virtual void InstallExtensionPref(const Extension* extension, | 51 virtual void InstallExtensionPref(const Extension* extension, | 
| 53 const char* pref_path, | 52 const char* pref_path, | 
| 54 Value* pref_value); | 53 Value* pref_value); | 
| 55 | 54 | 
| 56 // Removes an extension and all its preference settings from this PrefStore. | 55 // Removes an extension and all its preference settings from this PrefStore. | 
| 57 // This must be called when an extension is uninstalled or disabled. | 56 // This must be called when an extension is uninstalled or disabled. | 
| 58 virtual void UninstallExtension(const Extension* extension); | 57 virtual void UninstallExtension(const Extension* extension); | 
| 59 | 58 | 
| 60 // PrefStore methods: | 59 // PrefStore methods: | 
| 61 virtual DictionaryValue* prefs() const { return prefs_.get(); } | 60 virtual DictionaryValue* prefs() const { return prefs_.get(); } | 
| 62 | 61 | 
| 63 virtual PrefReadError ReadPrefs() { return PREF_READ_ERROR_NONE; } | 62 virtual PrefReadError ReadPrefs() { return PREF_READ_ERROR_NONE; } | 
| 64 | 63 | 
| 65 protected: | 64 protected: | 
| 66 // Returns a vector of the extension IDs in the extension_stack_. | 65 // Returns a vector of the extension IDs in the extension_stack_. | 
| 67 // This should only be accessed by subclasses for unit-testing. | 66 // This should only be accessed by subclasses for unit-testing. | 
| 68 void GetExtensionIDs(std::vector<std::string>* result); | 67 void GetExtensionIDs(std::vector<std::string>* result); | 
| 69 | 68 | 
| 70 // Returns the applicable pref service from the profile (if we have one) or | |
| 71 // the browser's local state. This should only be accessed or overridden by | |
| 72 // subclasses for unit-testing. | |
| 73 virtual PrefService* GetPrefService(); | |
| 74 | |
| 75 private: | 69 private: | 
| 76 // Associates an extension with the prefs it sets. Owns the pref values. | 70 // Associates an extension with the prefs it sets. Owns the pref values. | 
| 77 struct ExtensionPrefs { | 71 struct ExtensionPrefs { | 
| 78 ExtensionPrefs(const Extension* extension, PrefValueMap* values); | 72 ExtensionPrefs(const Extension* extension, PrefValueMap* values); | 
| 79 ~ExtensionPrefs(); | 73 ~ExtensionPrefs(); | 
| 80 | 74 | 
| 81 const Extension* extension; | 75 const Extension* extension; | 
| 82 PrefValueMap* pref_values; | 76 PrefValueMap* pref_values; | 
| 83 }; | 77 }; | 
| 84 | 78 | 
| (...skipping 23 matching lines...) Expand all Loading... | |
| 108 | 102 | 
| 109 ExtensionStack extension_stack_; | 103 ExtensionStack extension_stack_; | 
| 110 | 104 | 
| 111 NotificationRegistrar notification_registrar_; | 105 NotificationRegistrar notification_registrar_; | 
| 112 | 106 | 
| 113 // Weak reference to the profile whose extensions we're interested in. May be | 107 // Weak reference to the profile whose extensions we're interested in. May be | 
| 114 // NULL (for the local-state preferences), in which case we watch all | 108 // NULL (for the local-state preferences), in which case we watch all | 
| 115 // extensions. | 109 // extensions. | 
| 116 Profile* profile_; | 110 Profile* profile_; | 
| 117 | 111 | 
| 118 // My PrefStore type, assigned by the PrefValueStore. | |
| 119 PrefNotifier::PrefStoreType type_; | |
| 120 | |
| 121 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefStore); | 112 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefStore); | 
| 122 }; | 113 }; | 
| 123 | 114 | 
| 124 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_STORE_H_ | 115 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_STORE_H_ | 
| OLD | NEW |