blob: b736ac3d79963533e37476812f9d59b6b40d3235 [file] [log] [blame]
[email protected]d3b05ea2012-01-24 22:57:051// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]277404c22010-04-22 13:09:452// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]03b9b4e2012-10-22 20:01:525#ifndef BASE_PREFS_PREF_STORE_H_
6#define BASE_PREFS_PREF_STORE_H_
[email protected]277404c22010-04-22 13:09:457
[email protected]acd78969c2010-12-08 09:49:118#include <string>
9
10#include "base/basictypes.h"
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/ref_counted.h"
[email protected]f59f33e2012-11-01 12:05:2712#include "base/prefs/base_prefs_export.h"
[email protected]acd78969c2010-12-08 09:49:1113
[email protected]f3a1c642011-07-12 19:15:0314namespace base {
[email protected]ce1850e92010-10-15 08:40:5815class Value;
[email protected]f3a1c642011-07-12 19:15:0316}
[email protected]277404c22010-04-22 13:09:4517
18// This is an abstract interface for reading and writing from/to a persistent
[email protected]acd78969c2010-12-08 09:49:1119// preference store, used by PrefService. An implementation using a JSON file
20// can be found in JsonPrefStore, while an implementation without any backing
21// store for testing can be found in TestingPrefStore. Furthermore, there is
22// CommandLinePrefStore, which bridges command line options to preferences and
23// ConfigurationPolicyPrefStore, which is used for hooking up configuration
24// policy with the preference subsystem.
[email protected]f59f33e2012-11-01 12:05:2725class BASE_PREFS_EXPORT PrefStore : public base::RefCounted<PrefStore> {
[email protected]277404c22010-04-22 13:09:4526 public:
[email protected]acd78969c2010-12-08 09:49:1127 // Observer interface for monitoring PrefStore.
[email protected]f59f33e2012-11-01 12:05:2728 class BASE_PREFS_EXPORT Observer {
[email protected]acd78969c2010-12-08 09:49:1129 public:
[email protected]acd78969c2010-12-08 09:49:1130 // 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.
[email protected]845b43a82011-05-11 10:14:4333 virtual void OnInitializationCompleted(bool succeeded) = 0;
[email protected]512d03f2012-06-26 01:06:0634
35 protected:
36 virtual ~Observer() {}
[email protected]acd78969c2010-12-08 09:49:1137 };
38
[email protected]acd78969c2010-12-08 09:49:1139 PrefStore() {}
[email protected]acd78969c2010-12-08 09:49:1140
41 // Add and remove observers.
[email protected]f2d1f612010-12-09 15:10:1742 virtual void AddObserver(Observer* observer) {}
43 virtual void RemoveObserver(Observer* observer) {}
[email protected]14e0ec62013-08-26 22:01:3944 virtual bool HasObservers() const;
[email protected]acd78969c2010-12-08 09:49:1145
46 // Whether the store has completed all asynchronous initialization.
[email protected]0f1afed2010-12-15 17:22:2847 virtual bool IsInitializationComplete() const;
[email protected]277404c22010-04-22 13:09:4548
[email protected]a78e9482011-07-14 19:22:2949 // Get the value for a given preference |key| and stores it in |*result|.
[email protected]892f1d62012-11-08 18:24:3450 // |*result| is only modified if the return value is true and if |result|
[email protected]a78e9482011-07-14 19:22:2951 // is not NULL. Ownership of the |*result| value remains with the PrefStore.
[email protected]892f1d62012-11-08 18:24:3452 virtual bool GetValue(const std::string& key,
53 const base::Value** result) const = 0;
[email protected]acd78969c2010-12-08 09:49:1154
[email protected]9a8c4022011-01-25 14:25:3355 protected:
56 friend class base::RefCounted<PrefStore>;
57 virtual ~PrefStore() {}
58
59 private:
[email protected]acd78969c2010-12-08 09:49:1160 DISALLOW_COPY_AND_ASSIGN(PrefStore);
[email protected]277404c22010-04-22 13:09:4561};
62
[email protected]03b9b4e2012-10-22 20:01:5263#endif // BASE_PREFS_PREF_STORE_H_