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

Side by Side Diff: chrome/browser/prefs/pref_service_builder.cc

Issue 11570009: Split PrefService into PrefService, PrefServiceSimple and PrefServiceSyncable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 8 years 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
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 "chrome/browser/prefs/pref_service_builder.h" 5 #include "chrome/browser/prefs/pref_service_builder.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 "chrome/browser/prefs/pref_notifier_impl.h" 10 #include "chrome/browser/prefs/pref_notifier_impl.h"
11 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/browser/prefs/pref_value_store.h" 12 #include "chrome/browser/prefs/pref_value_store.h"
13 13
14 namespace { 14 namespace {
15 15
16 // Do-nothing default implementation. 16 // Do-nothing default implementation.
17 void DoNothingHandleReadError(PersistentPrefStore::PrefReadError error) { 17 void DoNothingHandleReadError(PersistentPrefStore::PrefReadError error) {
18 } 18 }
19 19
20 } // namespace 20 } // namespace
21 21
22 PrefServiceBuilder::PrefServiceBuilder() 22 PrefServiceBuilder::PrefServiceBuilder() {
23 : sync_associator_(NULL) {
24 ResetDefaultState(); 23 ResetDefaultState();
25 } 24 }
26 25
27 PrefServiceBuilder::~PrefServiceBuilder() { 26 PrefServiceBuilder::~PrefServiceBuilder() {
28 } 27 }
29 28
30 PrefServiceBuilder& PrefServiceBuilder::WithManagedPrefs(PrefStore* store) { 29 PrefServiceBuilder& PrefServiceBuilder::WithManagedPrefs(PrefStore* store) {
31 managed_prefs_ = store; 30 managed_prefs_ = store;
32 return *this; 31 return *this;
33 } 32 }
(...skipping 12 matching lines...) Expand all
46 PersistentPrefStore* store) { 45 PersistentPrefStore* store) {
47 user_prefs_ = store; 46 user_prefs_ = store;
48 return *this; 47 return *this;
49 } 48 }
50 49
51 PrefServiceBuilder& PrefServiceBuilder::WithRecommendedPrefs(PrefStore* store) { 50 PrefServiceBuilder& PrefServiceBuilder::WithRecommendedPrefs(PrefStore* store) {
52 recommended_prefs_ = store; 51 recommended_prefs_ = store;
53 return *this; 52 return *this;
54 } 53 }
55 54
56 PrefServiceBuilder& PrefServiceBuilder::WithSyncAssociator(
57 PrefModelAssociator* associator) {
58 sync_associator_ = associator;
59 return *this;
60 }
61
62 PrefServiceBuilder& PrefServiceBuilder::WithReadErrorCallback( 55 PrefServiceBuilder& PrefServiceBuilder::WithReadErrorCallback(
63 const base::Callback<void(PersistentPrefStore::PrefReadError)>& 56 const base::Callback<void(PersistentPrefStore::PrefReadError)>&
64 read_error_callback) { 57 read_error_callback) {
65 read_error_callback_ = read_error_callback; 58 read_error_callback_ = read_error_callback;
66 return *this; 59 return *this;
67 } 60 }
68 61
69 PrefServiceBuilder& PrefServiceBuilder::WithUserFilePrefs( 62 PrefServiceBuilder& PrefServiceBuilder::WithUserFilePrefs(
70 const FilePath& prefs_file, 63 const FilePath& prefs_file,
71 base::SequencedTaskRunner* task_runner) { 64 base::SequencedTaskRunner* task_runner) {
72 user_prefs_ = new JsonPrefStore(prefs_file, task_runner); 65 user_prefs_ = new JsonPrefStore(prefs_file, task_runner);
73 return *this; 66 return *this;
74 } 67 }
75 68
76 PrefServiceBuilder& PrefServiceBuilder::WithAsync(bool async) { 69 PrefServiceBuilder& PrefServiceBuilder::WithAsync(bool async) {
77 async_ = async; 70 async_ = async;
78 return *this; 71 return *this;
79 } 72 }
80 73
81 PrefService* PrefServiceBuilder::Create() { 74 PrefService* PrefServiceBuilder::Build(PrefService* pref_service) {
82 DefaultPrefStore* default_pref_store = new DefaultPrefStore(); 75 DefaultPrefStore* default_pref_store = new DefaultPrefStore();
83 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); 76 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl();
84 PrefService* pref_service = 77 pref_service->Initialize(
85 new PrefService( 78 pref_notifier,
86 pref_notifier, 79 new PrefValueStore(
87 new PrefValueStore( 80 managed_prefs_.get(),
88 managed_prefs_.get(), 81 extension_prefs_.get(),
89 extension_prefs_.get(), 82 command_line_prefs_.get(),
90 command_line_prefs_.get(),
91 user_prefs_.get(),
92 recommended_prefs_.get(),
93 default_pref_store,
94 sync_associator_,
95 pref_notifier),
96 user_prefs_.get(), 83 user_prefs_.get(),
84 recommended_prefs_.get(),
97 default_pref_store, 85 default_pref_store,
98 sync_associator_, 86 pref_notifier),
99 read_error_callback_, 87 user_prefs_.get(),
100 async_); 88 default_pref_store,
89 read_error_callback_,
90 async_);
91 ResetDefaultState();
92 return pref_service;
93 }
94
95 void PrefServiceBuilder::ResetDefaultState() {
101 managed_prefs_ = NULL; 96 managed_prefs_ = NULL;
102 extension_prefs_ = NULL; 97 extension_prefs_ = NULL;
103 command_line_prefs_ = NULL; 98 command_line_prefs_ = NULL;
104 user_prefs_ = NULL; 99 user_prefs_ = NULL;
105 recommended_prefs_ = NULL; 100 recommended_prefs_ = NULL;
106 sync_associator_ = NULL;
107 ResetDefaultState();
108
109 return pref_service;
110 }
111
112 void PrefServiceBuilder::ResetDefaultState() {
113 read_error_callback_ = base::Bind(&DoNothingHandleReadError); 101 read_error_callback_ = base::Bind(&DoNothingHandleReadError);
114 async_ = false; 102 async_ = false;
115 } 103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698