blob: 6c7eac9f59588cee215a29c2aa19cf20acd7c6fb [file] [log] [blame]
[email protected]b1de2c72013-02-06 02:45:471// 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
[email protected]3853a4c2013-02-11 17:15:575#ifndef BASE_PREFS_PREF_REGISTRY_H_
6#define BASE_PREFS_PREF_REGISTRY_H_
[email protected]b1de2c72013-02-06 02:45:477
8#include "base/callback.h"
9#include "base/memory/ref_counted.h"
[email protected]3853a4c2013-02-11 17:15:5710#include "base/prefs/base_prefs_export.h"
[email protected]b1de2c72013-02-06 02:45:4711#include "base/prefs/pref_value_map.h"
12
13namespace base {
14class Value;
15}
16
17class DefaultPrefStore;
18class PrefStore;
19
20// Preferences need to be registered with a type and default value
21// before they are used.
22//
23// The way you use a PrefRegistry is that you register all required
24// preferences on it (via one of its subclasses), then pass it as a
25// construction parameter to PrefService.
26//
27// Currently, registrations after constructing the PrefService will
28// also work, but this is being deprecated.
[email protected]3853a4c2013-02-11 17:15:5729class BASE_PREFS_EXPORT PrefRegistry : public base::RefCounted<PrefRegistry> {
[email protected]b1de2c72013-02-06 02:45:4730 public:
31 typedef PrefValueMap::const_iterator const_iterator;
32 typedef base::Callback<void(const char*, base::Value*)> RegistrationCallback;
[email protected]b1de2c72013-02-06 02:45:4733
34 PrefRegistry();
35
36 // Gets the registered defaults.
37 scoped_refptr<PrefStore> defaults();
38
39 // Allows iteration over defaults.
40 const_iterator begin() const;
41 const_iterator end() const;
42
[email protected]5879cef2013-03-02 17:02:2543 // Changes the default value for a preference. Takes ownership of |value|.
44 //
45 // |pref_name| must be a previously registered preference.
46 void SetDefaultPrefValue(const char* pref_name, base::Value* value);
47
[email protected]eeec6ca2013-02-21 15:10:4348 // Exactly one callback can be set for registration. The callback
49 // will be invoked each time registration has been performed on this
50 // object.
[email protected]b1de2c72013-02-06 02:45:4751 //
[email protected]eeec6ca2013-02-21 15:10:4352 // Calling this method after a callback has already been set will
53 // make the object forget the previous callback and use the new one
54 // instead.
[email protected]b1de2c72013-02-06 02:45:4755 void SetRegistrationCallback(const RegistrationCallback& callback);
[email protected]b1de2c72013-02-06 02:45:4756
57 protected:
58 friend class base::RefCounted<PrefRegistry>;
59 virtual ~PrefRegistry();
60
[email protected]b1de2c72013-02-06 02:45:4761 // Used by subclasses to register a default value for a preference.
62 void RegisterPreference(const char* path, base::Value* default_value);
63
[email protected]c753f142013-02-10 13:14:0464 scoped_refptr<DefaultPrefStore> defaults_;
65
[email protected]b1de2c72013-02-06 02:45:4766 private:
67 RegistrationCallback registration_callback_;
[email protected]b1de2c72013-02-06 02:45:4768
69 DISALLOW_COPY_AND_ASSIGN(PrefRegistry);
70};
71
[email protected]3853a4c2013-02-11 17:15:5772#endif // BASE_PREFS_PREF_REGISTRY_H_