[rAC, OSX] saveInChrome status now persistent.
[chromium-blink-merge.git] / base / prefs / pref_service_builder.h
blob7af43926233464654bdf2920d548ff624f8b0d7d
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.
5 #ifndef BASE_PREFS_PREF_SERVICE_BUILDER_H_
6 #define BASE_PREFS_PREF_SERVICE_BUILDER_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/prefs/base_prefs_export.h"
12 #include "base/prefs/persistent_pref_store.h"
13 #include "base/prefs/pref_registry.h"
14 #include "base/prefs/pref_store.h"
16 class PrefService;
18 namespace base {
19 class FilePath;
20 class SequencedTaskRunner;
23 // A class that allows convenient building of PrefService.
24 class BASE_PREFS_EXPORT PrefServiceBuilder {
25 public:
26 PrefServiceBuilder();
27 virtual ~PrefServiceBuilder();
29 // Functions for setting the various parameters of the PrefService to build.
30 // These take ownership of the |store| parameter.
31 PrefServiceBuilder& WithManagedPrefs(PrefStore* store);
32 PrefServiceBuilder& WithSupervisedUserPrefs(PrefStore* store);
33 PrefServiceBuilder& WithExtensionPrefs(PrefStore* store);
34 PrefServiceBuilder& WithCommandLinePrefs(PrefStore* store);
35 PrefServiceBuilder& WithUserPrefs(PersistentPrefStore* store);
36 PrefServiceBuilder& WithRecommendedPrefs(PrefStore* store);
38 // Sets up error callback for the PrefService. A do-nothing default
39 // is provided if this is not called.
40 PrefServiceBuilder& WithReadErrorCallback(
41 const base::Callback<void(PersistentPrefStore::PrefReadError)>&
42 read_error_callback);
44 // Specifies to use an actual file-backed user pref store.
45 PrefServiceBuilder& WithUserFilePrefs(
46 const base::FilePath& prefs_file,
47 base::SequencedTaskRunner* task_runner);
49 PrefServiceBuilder& WithAsync(bool async);
51 // Creates a PrefService object initialized with the parameters from
52 // this builder.
53 virtual PrefService* Create(PrefRegistry* registry);
55 protected:
56 virtual void ResetDefaultState();
58 scoped_refptr<PrefStore> managed_prefs_;
59 scoped_refptr<PrefStore> supervised_user_prefs_;
60 scoped_refptr<PrefStore> extension_prefs_;
61 scoped_refptr<PrefStore> command_line_prefs_;
62 scoped_refptr<PersistentPrefStore> user_prefs_;
63 scoped_refptr<PrefStore> recommended_prefs_;
65 base::Callback<void(PersistentPrefStore::PrefReadError)> read_error_callback_;
67 // Defaults to false.
68 bool async_;
70 private:
71 DISALLOW_COPY_AND_ASSIGN(PrefServiceBuilder);
74 #endif // BASE_PREFS_PREF_SERVICE_BUILDER_H_