Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <map> | |
| 10 #include <set> | |
| 11 | |
| 12 #include "base/time.h" | |
| 9 #include "chrome/browser/prefs/value_map_pref_store.h" | 13 #include "chrome/browser/prefs/value_map_pref_store.h" |
| 10 | 14 |
| 11 // A PrefStore implementation that holds preferences set by extensions. | 15 class ExtensionPrefValueMap; |
| 12 class ExtensionPrefStore : public ValueMapPrefStore { | 16 |
| 17 // A (non-persistent) PrefStore implementation that holds preferences set by | |
| 18 // extensions. | |
| 19 // The semantics of the ExtensionPrefStore are: | |
| 20 // - The precedence of extensions is determined by their installation time. | |
| 21 // The extension that has been installed later takes higher precedence. | |
| 22 // - If two extensions set a value for the same preference, the following | |
| 23 // rules determine which value becomes effective (visible). | |
| 24 // - The effective regular extension pref value is determined by the regular | |
| 25 // extension pref value of the extension with the highest precedence. | |
| 26 // - The effective incognito extension pref value is determined by the incognito | |
| 27 // extension pref value of the extension with the highest precedence, unless | |
| 28 // another extension with higher precedence overrides it with a regular | |
| 29 // extension pref value. | |
| 30 // | |
| 31 // The following table illustrates the behavior: | |
| 32 // A.reg | A.inc | B.reg | B.inc | E.reg | E.inc | |
| 33 // 1 | - | - | - | 1 | 1 | |
| 34 // 1 | 2 | - | - | 1 | 2 | |
| 35 // 1 | - | 3 | - | 3 | 3 | |
| 36 // 1 | - | - | 4 | 1 | 4 | |
| 37 // 1 | 2 | 3 | - | 3 | 3(!) | |
| 38 // 1 | 2 | - | 4 | 1 | 4 | |
| 39 // 1 | 2 | 3 | 4 | 3 | 4 | |
| 40 // A = extension A, B = extension B, E = effective value | |
| 41 // .reg = regular value | |
| 42 // .inc = incognito value | |
| 43 // Extension B has higher precedence than A. | |
| 44 // | |
| 45 // Large parts of ExtensionPrefStore's logic are implemented in | |
| 46 // ExtensionPrefValueMap. | |
|
Mattias Nissler (ping if slow)
2011/01/05 12:08:07
Maybe it's useful to put the semantics comment abo
battre
2011/01/05 20:23:08
Done.
| |
| 47 class ExtensionPrefStore : public ValueMapPrefStore, | |
| 48 public PrefStore::Observer { | |
| 13 public: | 49 public: |
| 14 ExtensionPrefStore(); | 50 // Constructs an ExtensionPrefStore for a regular or an incognito profile. |
| 15 virtual ~ExtensionPrefStore() {} | 51 explicit ExtensionPrefStore(bool incognito_pref_store); |
| 52 virtual ~ExtensionPrefStore(); | |
| 16 | 53 |
| 17 // Set an extension preference |value| for |key|. Takes ownership of |value|. | 54 // Does not assume ownership of |extension_pref_value_map|. |
| 18 void SetExtensionPref(const std::string& key, Value* value); | 55 void SetExtensionPrefValueMap( |
| 19 | 56 ExtensionPrefValueMap* extension_pref_value_map); |
|
Mattias Nissler (ping if slow)
2011/01/05 12:08:07
Why can't we pass this to the constructor?
battre
2011/01/05 20:23:08
Done.
| |
| 20 // Remove the extension preference value for |key|. | |
| 21 void RemoveExtensionPref(const std::string& key); | |
| 22 | |
| 23 // Tell the store it's now fully initialized. | |
| 24 void OnInitializationCompleted(); | |
| 25 | 57 |
| 26 private: | 58 private: |
| 27 // PrefStore overrides: | 59 // Overrides for PrefStore::Observer: |
| 28 virtual bool IsInitializationComplete() const; | 60 virtual void OnInitializationCompleted(); |
| 61 virtual void OnPrefValueChanged(const std::string& key); | |
| 29 | 62 |
| 30 bool initialization_complete_; | 63 ExtensionPrefValueMap* extension_pref_value_map_; // Weak pointer. |
| 64 bool incognito_pref_store_; | |
| 31 | 65 |
| 32 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefStore); | 66 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefStore); |
| 33 }; | 67 }; |
| 34 | 68 |
| 35 | |
| 36 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_STORE_H_ | 69 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_STORE_H_ |
| OLD | NEW |