• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/extensions/extension_pref_store.h"
6 
7 #include "base/values.h"
8 #include "chrome/browser/extensions/extension_pref_value_map.h"
9 
ExtensionPrefStore(ExtensionPrefValueMap * extension_pref_value_map,bool incognito_pref_store)10 ExtensionPrefStore::ExtensionPrefStore(
11     ExtensionPrefValueMap* extension_pref_value_map,
12     bool incognito_pref_store)
13     : extension_pref_value_map_(extension_pref_value_map),
14       incognito_pref_store_(incognito_pref_store) {
15   extension_pref_value_map_->AddObserver(this);
16 }
17 
~ExtensionPrefStore()18 ExtensionPrefStore::~ExtensionPrefStore() {
19   if (extension_pref_value_map_)
20     extension_pref_value_map_->RemoveObserver(this);
21 }
22 
OnInitializationCompleted()23 void ExtensionPrefStore::OnInitializationCompleted() {
24   NotifyInitializationCompleted();
25 }
26 
OnPrefValueChanged(const std::string & key)27 void ExtensionPrefStore::OnPrefValueChanged(const std::string& key) {
28   CHECK(extension_pref_value_map_);
29   const Value *winner =
30       extension_pref_value_map_->GetEffectivePrefValue(key,
31                                                        incognito_pref_store_,
32                                                        NULL);
33   if (winner)
34     SetValue(key, winner->DeepCopy());
35   else
36     RemoveValue(key);
37 }
38 
OnExtensionPrefValueMapDestruction()39 void ExtensionPrefStore::OnExtensionPrefValueMapDestruction() {
40   CHECK(extension_pref_value_map_);
41   extension_pref_value_map_->RemoveObserver(this);
42   extension_pref_value_map_ = NULL;
43 }
44