Home | History | Annotate | Download | only in prefs
      1 // Copyright (c) 2012 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 "base/prefs/default_pref_store.h"
      6 #include "base/logging.h"
      7 
      8 using base::Value;
      9 
     10 DefaultPrefStore::DefaultPrefStore() {}
     11 
     12 bool DefaultPrefStore::GetValue(const std::string& key,
     13                                 const Value** result) const {
     14   return prefs_.GetValue(key, result);
     15 }
     16 
     17 void DefaultPrefStore::AddObserver(PrefStore::Observer* observer) {
     18   observers_.AddObserver(observer);
     19 }
     20 
     21 void DefaultPrefStore::RemoveObserver(PrefStore::Observer* observer) {
     22   observers_.RemoveObserver(observer);
     23 }
     24 
     25 bool DefaultPrefStore::HasObservers() const {
     26   return observers_.might_have_observers();
     27 }
     28 
     29 void DefaultPrefStore::SetDefaultValue(const std::string& key,
     30                                        scoped_ptr<Value> value) {
     31   DCHECK(!GetValue(key, NULL));
     32   prefs_.SetValue(key, value.release());
     33 }
     34 
     35 void DefaultPrefStore::ReplaceDefaultValue(const std::string& key,
     36                                            scoped_ptr<Value> value) {
     37   const Value* old_value = NULL;
     38   GetValue(key, &old_value);
     39   bool notify = !old_value->Equals(value.get());
     40   prefs_.SetValue(key, value.release());
     41   if (notify)
     42     FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key));
     43 }
     44 
     45 DefaultPrefStore::const_iterator DefaultPrefStore::begin() const {
     46   return prefs_.begin();
     47 }
     48 
     49 DefaultPrefStore::const_iterator DefaultPrefStore::end() const {
     50   return prefs_.end();
     51 }
     52 
     53 DefaultPrefStore::~DefaultPrefStore() {}
     54