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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/prefs/pref_service_factory.h ('k') | base/prefs/testing_pref_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/prefs/pref_service_factory.cc
diff --git a/base/prefs/pref_service_builder.cc b/base/prefs/pref_service_factory.cc
similarity index 44%
rename from base/prefs/pref_service_builder.cc
rename to base/prefs/pref_service_factory.cc
index 16b4565663b4ce67a7239d03d191b1d0b68e66bb..b420fcef5821861aec2ffc37cf15f6bb564e0fdd 100644
--- a/base/prefs/pref_service_builder.cc
+++ b/base/prefs/pref_service_factory.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/prefs/pref_service_builder.h"
+#include "base/prefs/pref_service_factory.h"
#include "base/bind.h"
#include "base/prefs/default_pref_store.h"
@@ -12,6 +12,8 @@
#include "base/prefs/pref_value_store.h"
+namespace base {
+
namespace {
// Do-nothing default implementation.
@@ -20,67 +22,28 @@ void DoNothingHandleReadError(PersistentPrefStore::PrefReadError error) {
} // namespace
-PrefServiceBuilder::PrefServiceBuilder() {
- ResetDefaultState();
-}
-
-PrefServiceBuilder::~PrefServiceBuilder() {
-}
-
-PrefServiceBuilder& PrefServiceBuilder::WithManagedPrefs(PrefStore* store) {
- managed_prefs_ = store;
- return *this;
-}
-
-PrefServiceBuilder& PrefServiceBuilder::WithSupervisedUserPrefs(
- PrefStore* store) {
- supervised_user_prefs_ = store;
- return *this;
-}
-
-PrefServiceBuilder& PrefServiceBuilder::WithExtensionPrefs(PrefStore* store) {
- extension_prefs_ = store;
- return *this;
-}
-
-PrefServiceBuilder& PrefServiceBuilder::WithCommandLinePrefs(PrefStore* store) {
- command_line_prefs_ = store;
- return *this;
-}
-
-PrefServiceBuilder& PrefServiceBuilder::WithUserPrefs(
- PersistentPrefStore* store) {
- user_prefs_ = store;
- return *this;
-}
-
-PrefServiceBuilder& PrefServiceBuilder::WithRecommendedPrefs(PrefStore* store) {
- recommended_prefs_ = store;
- return *this;
-}
+PrefServiceFactory::PrefServiceFactory()
+ : managed_prefs_(NULL),
+ supervised_user_prefs_(NULL),
+ extension_prefs_(NULL),
+ command_line_prefs_(NULL),
+ user_prefs_(NULL),
+ recommended_prefs_(NULL),
+ read_error_callback_(base::Bind(&DoNothingHandleReadError)),
+ async_(false) {}
-PrefServiceBuilder& PrefServiceBuilder::WithReadErrorCallback(
- const base::Callback<void(PersistentPrefStore::PrefReadError)>&
- read_error_callback) {
- read_error_callback_ = read_error_callback;
- return *this;
-}
+PrefServiceFactory::~PrefServiceFactory() {}
-PrefServiceBuilder& PrefServiceBuilder::WithUserFilePrefs(
+void PrefServiceFactory::SetUserPrefsFile(
const base::FilePath& prefs_file,
base::SequencedTaskRunner* task_runner) {
user_prefs_ = new JsonPrefStore(prefs_file, task_runner);
- return *this;
}
-PrefServiceBuilder& PrefServiceBuilder::WithAsync(bool async) {
- async_ = async;
- return *this;
-}
-
-PrefService* PrefServiceBuilder::Create(PrefRegistry* pref_registry) {
+scoped_ptr<PrefService> PrefServiceFactory::Create(
+ PrefRegistry* pref_registry) {
PrefNotifierImpl* pref_notifier = new PrefNotifierImpl();
- PrefService* pref_service =
+ scoped_ptr<PrefService> pref_service(
new PrefService(pref_notifier,
new PrefValueStore(managed_prefs_.get(),
supervised_user_prefs_.get(),
@@ -93,18 +56,8 @@ PrefService* PrefServiceBuilder::Create(PrefRegistry* pref_registry) {
user_prefs_.get(),
pref_registry,
read_error_callback_,
- async_);
- ResetDefaultState();
- return pref_service;
+ async_));
+ return pref_service.Pass();
}
-void PrefServiceBuilder::ResetDefaultState() {
- managed_prefs_ = NULL;
- supervised_user_prefs_ = NULL;
- extension_prefs_ = NULL;
- command_line_prefs_ = NULL;
- user_prefs_ = NULL;
- recommended_prefs_ = NULL;
- read_error_callback_ = base::Bind(&DoNothingHandleReadError);
- async_ = false;
-}
+} // namespace base
« 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