summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_pref_store.cc
blob: 67beed15ab9b96c148c91eedd23f681f37938e3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) 2012 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.

#include "chrome/browser/extensions/extension_pref_store.h"

#include "base/values.h"
#include "chrome/browser/extensions/extension_pref_value_map.h"

ExtensionPrefStore::ExtensionPrefStore(
    ExtensionPrefValueMap* extension_pref_value_map,
    bool incognito_pref_store)
    : extension_pref_value_map_(extension_pref_value_map),
      incognito_pref_store_(incognito_pref_store) {
  extension_pref_value_map_->AddObserver(this);
}

void ExtensionPrefStore::OnInitializationCompleted() {
  NotifyInitializationCompleted();
}

void ExtensionPrefStore::OnPrefValueChanged(const std::string& key) {
  CHECK(extension_pref_value_map_);
  const Value *winner =
      extension_pref_value_map_->GetEffectivePrefValue(key,
                                                       incognito_pref_store_,
                                                       NULL);
  if (winner)
    SetValue(key, winner->DeepCopy());
  else
    RemoveValue(key);
}

void ExtensionPrefStore::OnExtensionPrefValueMapDestruction() {
  CHECK(extension_pref_value_map_);
  extension_pref_value_map_->RemoveObserver(this);
  extension_pref_value_map_ = NULL;
}

ExtensionPrefStore::~ExtensionPrefStore() {
  if (extension_pref_value_map_)
    extension_pref_value_map_->RemoveObserver(this);
}