Roll src/third_party/WebKit a3b4a2e:7441784 (svn 202551:202552)
[chromium-blink-merge.git] / extensions / browser / extension_pref_store.cc
blob80e7a08b9b92fc845ed39ae10da2e54cebb2cb5a
1 // Copyright 2014 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.
5 #include "extensions/browser/extension_pref_store.h"
7 #include "base/values.h"
8 #include "extensions/browser/extension_pref_value_map.h"
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);
18 void ExtensionPrefStore::OnInitializationCompleted() {
19 NotifyInitializationCompleted();
22 void ExtensionPrefStore::OnPrefValueChanged(const std::string& key) {
23 CHECK(extension_pref_value_map_);
24 const base::Value *winner =
25 extension_pref_value_map_->GetEffectivePrefValue(key,
26 incognito_pref_store_,
27 NULL);
28 if (winner) {
29 SetValue(key, winner->CreateDeepCopy(),
30 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
31 } else {
32 RemoveValue(key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
36 void ExtensionPrefStore::OnExtensionPrefValueMapDestruction() {
37 CHECK(extension_pref_value_map_);
38 extension_pref_value_map_->RemoveObserver(this);
39 extension_pref_value_map_ = NULL;
42 ExtensionPrefStore::~ExtensionPrefStore() {
43 if (extension_pref_value_map_)
44 extension_pref_value_map_->RemoveObserver(this);