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#ifndef CHROME_COMMON_PREF_STORE_H_ 6#define CHROME_COMMON_PREF_STORE_H_ 7#pragma once 8 9#include <string> 10 11#include "base/basictypes.h" 12#include "base/memory/ref_counted.h" 13 14class Value; 15 16// This is an abstract interface for reading and writing from/to a persistent 17// preference store, used by PrefService. An implementation using a JSON file 18// can be found in JsonPrefStore, while an implementation without any backing 19// store for testing can be found in TestingPrefStore. Furthermore, there is 20// CommandLinePrefStore, which bridges command line options to preferences and 21// ConfigurationPolicyPrefStore, which is used for hooking up configuration 22// policy with the preference subsystem. 23class PrefStore : public base::RefCounted<PrefStore> { 24 public: 25 // Observer interface for monitoring PrefStore. 26 class Observer { 27 public: 28 virtual ~Observer() {} 29 30 // Called when the value for the given |key| in the store changes. 31 virtual void OnPrefValueChanged(const std::string& key) = 0; 32 // Notification about the PrefStore being fully initialized. 33 virtual void OnInitializationCompleted() = 0; 34 }; 35 36 // Return values for GetValue(). 37 enum ReadResult { 38 // Value found and returned. 39 READ_OK, 40 // No value present, but skip other pref stores and use default. 41 READ_USE_DEFAULT, 42 // No value present. 43 READ_NO_VALUE, 44 }; 45 46 PrefStore() {} 47 48 // Add and remove observers. 49 virtual void AddObserver(Observer* observer) {} 50 virtual void RemoveObserver(Observer* observer) {} 51 52 // Whether the store has completed all asynchronous initialization. 53 virtual bool IsInitializationComplete() const; 54 55 // Get the value for a given preference |key| and stores it in |result|. 56 // |result| is only modified if the return value is READ_OK. Ownership of the 57 // |result| value remains with the PrefStore. 58 virtual ReadResult GetValue(const std::string& key, 59 const Value** result) const = 0; 60 61 protected: 62 friend class base::RefCounted<PrefStore>; 63 virtual ~PrefStore() {} 64 65 private: 66 DISALLOW_COPY_AND_ASSIGN(PrefStore); 67}; 68 69#endif // CHROME_COMMON_PREF_STORE_H_ 70