Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: base/prefs/pref_service_factory.cc

Issue 64193003: Clean up PrefServiceBuilder (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix memory ownership bug in ProxyPolicyTest Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/prefs/pref_service_factory.h ('k') | base/prefs/testing_pref_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/prefs/pref_service_builder.h" 5 #include "base/prefs/pref_service_factory.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/prefs/default_pref_store.h" 8 #include "base/prefs/default_pref_store.h"
9 #include "base/prefs/json_pref_store.h" 9 #include "base/prefs/json_pref_store.h"
10 #include "base/prefs/pref_notifier_impl.h" 10 #include "base/prefs/pref_notifier_impl.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 12
13 #include "base/prefs/pref_value_store.h" 13 #include "base/prefs/pref_value_store.h"
14 14
15 namespace base {
16
15 namespace { 17 namespace {
16 18
17 // Do-nothing default implementation. 19 // Do-nothing default implementation.
18 void DoNothingHandleReadError(PersistentPrefStore::PrefReadError error) { 20 void DoNothingHandleReadError(PersistentPrefStore::PrefReadError error) {
19 } 21 }
20 22
21 } // namespace 23 } // namespace
22 24
23 PrefServiceBuilder::PrefServiceBuilder() { 25 PrefServiceFactory::PrefServiceFactory()
24 ResetDefaultState(); 26 : managed_prefs_(NULL),
25 } 27 supervised_user_prefs_(NULL),
28 extension_prefs_(NULL),
29 command_line_prefs_(NULL),
30 user_prefs_(NULL),
31 recommended_prefs_(NULL),
32 read_error_callback_(base::Bind(&DoNothingHandleReadError)),
33 async_(false) {}
26 34
27 PrefServiceBuilder::~PrefServiceBuilder() { 35 PrefServiceFactory::~PrefServiceFactory() {}
28 }
29 36
30 PrefServiceBuilder& PrefServiceBuilder::WithManagedPrefs(PrefStore* store) { 37 void PrefServiceFactory::SetUserPrefsFile(
31 managed_prefs_ = store;
32 return *this;
33 }
34
35 PrefServiceBuilder& PrefServiceBuilder::WithSupervisedUserPrefs(
36 PrefStore* store) {
37 supervised_user_prefs_ = store;
38 return *this;
39 }
40
41 PrefServiceBuilder& PrefServiceBuilder::WithExtensionPrefs(PrefStore* store) {
42 extension_prefs_ = store;
43 return *this;
44 }
45
46 PrefServiceBuilder& PrefServiceBuilder::WithCommandLinePrefs(PrefStore* store) {
47 command_line_prefs_ = store;
48 return *this;
49 }
50
51 PrefServiceBuilder& PrefServiceBuilder::WithUserPrefs(
52 PersistentPrefStore* store) {
53 user_prefs_ = store;
54 return *this;
55 }
56
57 PrefServiceBuilder& PrefServiceBuilder::WithRecommendedPrefs(PrefStore* store) {
58 recommended_prefs_ = store;
59 return *this;
60 }
61
62 PrefServiceBuilder& PrefServiceBuilder::WithReadErrorCallback(
63 const base::Callback<void(PersistentPrefStore::PrefReadError)>&
64 read_error_callback) {
65 read_error_callback_ = read_error_callback;
66 return *this;
67 }
68
69 PrefServiceBuilder& PrefServiceBuilder::WithUserFilePrefs(
70 const base::FilePath& prefs_file, 38 const base::FilePath& prefs_file,
71 base::SequencedTaskRunner* task_runner) { 39 base::SequencedTaskRunner* task_runner) {
72 user_prefs_ = new JsonPrefStore(prefs_file, task_runner); 40 user_prefs_ = new JsonPrefStore(prefs_file, task_runner);
73 return *this;
74 } 41 }
75 42
76 PrefServiceBuilder& PrefServiceBuilder::WithAsync(bool async) { 43 scoped_ptr<PrefService> PrefServiceFactory::Create(
77 async_ = async; 44 PrefRegistry* pref_registry) {
78 return *this;
79 }
80
81 PrefService* PrefServiceBuilder::Create(PrefRegistry* pref_registry) {
82 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); 45 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl();
83 PrefService* pref_service = 46 scoped_ptr<PrefService> pref_service(
84 new PrefService(pref_notifier, 47 new PrefService(pref_notifier,
85 new PrefValueStore(managed_prefs_.get(), 48 new PrefValueStore(managed_prefs_.get(),
86 supervised_user_prefs_.get(), 49 supervised_user_prefs_.get(),
87 extension_prefs_.get(), 50 extension_prefs_.get(),
88 command_line_prefs_.get(), 51 command_line_prefs_.get(),
89 user_prefs_.get(), 52 user_prefs_.get(),
90 recommended_prefs_.get(), 53 recommended_prefs_.get(),
91 pref_registry->defaults().get(), 54 pref_registry->defaults().get(),
92 pref_notifier), 55 pref_notifier),
93 user_prefs_.get(), 56 user_prefs_.get(),
94 pref_registry, 57 pref_registry,
95 read_error_callback_, 58 read_error_callback_,
96 async_); 59 async_));
97 ResetDefaultState(); 60 return pref_service.Pass();
98 return pref_service;
99 } 61 }
100 62
101 void PrefServiceBuilder::ResetDefaultState() { 63 } // namespace base
102 managed_prefs_ = NULL;
103 supervised_user_prefs_ = NULL;
104 extension_prefs_ = NULL;
105 command_line_prefs_ = NULL;
106 user_prefs_ = NULL;
107 recommended_prefs_ = NULL;
108 read_error_callback_ = base::Bind(&DoNothingHandleReadError);
109 async_ = false;
110 }
OLDNEW
« no previous file with comments | « base/prefs/pref_service_factory.h ('k') | base/prefs/testing_pref_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698