Chromium Code Reviews| Index: chrome/browser/extensions/extension_pref_value_map.h |
| diff --git a/chrome/browser/extensions/extension_pref_value_map.h b/chrome/browser/extensions/extension_pref_value_map.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7fdb55cc87680ffc222d7a973ac0259e319ec5b3 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/extension_pref_value_map.h |
| @@ -0,0 +1,106 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_VALUE_MAP_H_ |
| +#define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_VALUE_MAP_H_ |
| +#pragma once |
| + |
| +#include <map> |
| +#include <set> |
| + |
| +#include "base/time.h" |
| +#include "chrome/browser/prefs/value_map_pref_store.h" |
| + |
| +// Non-persistent data container that is shared by ExtensionPrefStores. All |
| +// extension pref values (incognito and regular) are stored herein and |
| +// provided to ExtensionPrefStores. |
| +class ExtensionPrefValueMap { |
|
battre
2011/01/05 09:59:40
If you find a better name for this class, I'd be h
|
| + public: |
| + ExtensionPrefValueMap(); |
| + virtual ~ExtensionPrefValueMap(); |
| + |
| + // Set an extension preference |value| for |key| of extension |ext_id|. |
| + // Takes ownership of |value|. |
| + // Note that regular extension pref values need to be reported to |
| + // incognito and to regular ExtensionPrefStores. |
| + // Precondition: the extension must be registered. |
| + void SetExtensionPref(const std::string& ext_id, |
| + const std::string& key, |
| + bool incognito, |
| + Value* value); |
| + |
| + // Remove the extension preference value for |key| of extension |ext_id|. |
| + // Precondition: the extension must be registered. |
| + void RemoveExtensionPref(const std::string& ext_id, |
| + const std::string& key, |
| + bool incognito); |
| + |
| + // Tell the store it's now fully initialized. |
| + void OnInitializationCompleted(); |
| + |
| + // Registers the time when an extension |ext_id| is installed. |
| + void RegisterExtension(const std::string& ext_id, |
| + const base::Time& install_time, |
| + bool is_enabled); |
| + |
| + // Deletes all entries related to extension |ext_id|. |
| + void UnregisterExtension(const std::string& ext_id); |
| + |
| + // Hides or makes the extension preference values of the specified extension |
| + // visible. |
| + void UpdateExtensionsState(const std::string& ext_id, |
| + bool is_enabled); |
|
Mattias Nissler (ping if slow)
2011/01/05 12:08:07
Would SetExtensionState be a more precise name for
battre
2011/01/05 20:23:08
The SetExtensionState name collides with SetExtens
|
| + |
| + // Adds an observer that is always notified if a regular or incognito |
| + // extension pref value changes - regardless whether this change is |
| + // visible or hidden due to another extension with a higher precedence. |
| + // Observers can query GetEffectivePrefValue to see the effective value. |
| + void AddObserver(PrefStore::Observer* observer); |
| + |
| + void RemoveObserver(PrefStore::Observer* observer); |
|
Mattias Nissler (ping if slow)
2011/01/05 12:08:07
I can see that it's convenient to reuse the PrefSt
battre
2011/01/05 20:23:08
Done.
|
| + |
| + const Value* GetEffectivePrefValue(const std::string& key, |
| + bool incognito) const; |
| + private: |
|
Mattias Nissler (ping if slow)
2011/01/05 12:08:07
newline before private: declaration.
battre
2011/01/05 20:23:08
Done.
|
| + struct ExtensionEntry { |
| + // Installation time of the extension. |
| + base::Time install_time; |
| + // Whether extension is enabled in the profile. |
| + bool enabled; |
| + // Regular preferences. |
| + PrefValueMap reg_preferences; |
| + // Incognito preferences, empty for regular ExtensionPerfStore. |
|
Mattias Nissler (ping if slow)
2011/01/05 12:08:07
s/Perf/Pref/
battre
2011/01/05 20:23:08
Done.
|
| + PrefValueMap inc_preferences; |
| + }; |
| + |
| + typedef std::map<std::string, ExtensionEntry*> ExtensionEntryMap; |
| + |
| + const PrefValueMap* GetExtensionPrefValueMap(const std::string& ext_id, |
| + bool incognito) const; |
| + |
| + PrefValueMap* GetExtensionPrefValueMap(const std::string& ext_id, |
| + bool incognito); |
| + |
| + // Returns all keys of pref values that are set by |ext_id|, regardless |
| + // whether they are set for incognito or regular pref values. |
| + void GetExtensionControlledKeys(const std::string& ext_id, |
| + std::set<std::string>* out) const; |
| + |
| + void NotifyInitializationCompleted(); |
| + void NotifyPrefValueChanged(const std::string& key); |
| + void NotifyPrefValueChanged(const std::set<std::string>& keys); |
| + |
| + bool initialization_complete_; |
| + |
| + // Mapping of which extension set which preference value. The effective |
| + // preferences values (i.e. the ones with the highest precedence) |
| + // are stored in the datastructures of the base class. |
| + ExtensionEntryMap entries_; |
| + |
| + ObserverList<PrefStore::Observer, true> observers_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ExtensionPrefValueMap); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_STORE_H_ |