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

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

Issue 1332283003: Remove dependency of PrefSyncableService on PrefsTabHelper. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pref_service_syncable_util
Patch Set: Update PrefServiceSyncable::CreateIncognitoPrefService comment Created 5 years, 3 months 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
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_syncable.h" 5 #include "chrome/browser/prefs/pref_service_syncable.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h"
8 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
9 #include "base/prefs/default_pref_store.h" 10 #include "base/prefs/default_pref_store.h"
10 #include "base/prefs/overlay_user_pref_store.h" 11 #include "base/prefs/overlay_user_pref_store.h"
11 #include "base/prefs/pref_notifier_impl.h" 12 #include "base/prefs/pref_notifier_impl.h"
12 #include "base/prefs/pref_registry.h" 13 #include "base/prefs/pref_registry.h"
13 #include "base/prefs/pref_value_store.h" 14 #include "base/prefs/pref_value_store.h"
14 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
15 #include "base/value_conversions.h" 16 #include "base/value_conversions.h"
16 #include "chrome/browser/prefs/pref_model_associator.h" 17 #include "chrome/browser/prefs/pref_model_associator.h"
17 #include "chrome/browser/prefs/pref_service_syncable_observer.h" 18 #include "chrome/browser/prefs/pref_service_syncable_observer.h"
18 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
19 #include "components/pref_registry/pref_registry_syncable.h" 19 #include "components/pref_registry/pref_registry_syncable.h"
20 20
21 PrefServiceSyncable::PrefServiceSyncable( 21 PrefServiceSyncable::PrefServiceSyncable(
22 PrefNotifierImpl* pref_notifier, 22 PrefNotifierImpl* pref_notifier,
23 PrefValueStore* pref_value_store, 23 PrefValueStore* pref_value_store,
24 PersistentPrefStore* user_prefs, 24 PersistentPrefStore* user_prefs,
25 user_prefs::PrefRegistrySyncable* pref_registry, 25 user_prefs::PrefRegistrySyncable* pref_registry,
26 base::Callback<void(PersistentPrefStore::PrefReadError)> 26 base::Callback<void(PersistentPrefStore::PrefReadError)>
27 read_error_callback, 27 read_error_callback,
28 bool async) 28 bool async)
29 : PrefService(pref_notifier, 29 : PrefService(pref_notifier,
30 pref_value_store, 30 pref_value_store,
31 user_prefs, 31 user_prefs,
32 pref_registry, 32 pref_registry,
33 read_error_callback, 33 read_error_callback,
34 async), 34 async),
35 pref_sync_associator_(syncer::PREFERENCES), 35 pref_sync_associator_(syncer::PREFERENCES),
36 priority_pref_sync_associator_(syncer::PRIORITY_PREFERENCES) { 36 priority_pref_sync_associator_(syncer::PRIORITY_PREFERENCES) {
37 pref_sync_associator_.SetPrefService(this); 37 pref_sync_associator_.SetPrefService(this);
38 priority_pref_sync_associator_.SetPrefService(this); 38 priority_pref_sync_associator_.SetPrefService(this);
39 39
40 // Let PrefModelAssociators know about changes to preference values. 40 // Let PrefModelAssociators know about changes to preference values.
41 pref_value_store->set_callback( 41 pref_value_store->set_callback(base::Bind(
42 base::Bind(&PrefServiceSyncable::ProcessPrefChange, 42 &PrefServiceSyncable::ProcessPrefChange, base::Unretained(this)));
43 base::Unretained(this)));
44 43
45 // Add already-registered syncable preferences to PrefModelAssociator. 44 // Add already-registered syncable preferences to PrefModelAssociator.
46 for (PrefRegistry::const_iterator it = pref_registry->begin(); 45 for (PrefRegistry::const_iterator it = pref_registry->begin();
47 it != pref_registry->end(); ++it) { 46 it != pref_registry->end(); ++it) {
48 const std::string& path = it->first; 47 const std::string& path = it->first;
49 AddRegisteredSyncablePreference(path, 48 AddRegisteredSyncablePreference(path,
50 pref_registry_->GetRegistrationFlags(path)); 49 pref_registry_->GetRegistrationFlags(path));
51 } 50 }
52 51
53 // Watch for syncable preferences registered after this point. 52 // Watch for syncable preferences registered after this point.
54 pref_registry->SetSyncableRegistrationCallback( 53 pref_registry->SetSyncableRegistrationCallback(
55 base::Bind(&PrefServiceSyncable::AddRegisteredSyncablePreference, 54 base::Bind(&PrefServiceSyncable::AddRegisteredSyncablePreference,
56 base::Unretained(this))); 55 base::Unretained(this)));
57 } 56 }
58 57
59 PrefServiceSyncable::~PrefServiceSyncable() { 58 PrefServiceSyncable::~PrefServiceSyncable() {
60 // Remove our callback from the registry, since it may outlive us. 59 // Remove our callback from the registry, since it may outlive us.
61 user_prefs::PrefRegistrySyncable* registry = 60 user_prefs::PrefRegistrySyncable* registry =
62 static_cast<user_prefs::PrefRegistrySyncable*>(pref_registry_.get()); 61 static_cast<user_prefs::PrefRegistrySyncable*>(pref_registry_.get());
63 registry->SetSyncableRegistrationCallback( 62 registry->SetSyncableRegistrationCallback(
64 user_prefs::PrefRegistrySyncable::SyncableRegistrationCallback()); 63 user_prefs::PrefRegistrySyncable::SyncableRegistrationCallback());
65 } 64 }
66 65
67 PrefServiceSyncable* PrefServiceSyncable::CreateIncognitoPrefService( 66 PrefServiceSyncable* PrefServiceSyncable::CreateIncognitoPrefService(
68 PrefStore* incognito_extension_prefs) { 67 PrefStore* incognito_extension_prefs,
68 const base::Callback<void(OverlayUserPrefStore*)>&
69 incognito_pref_created_cb) {
69 pref_service_forked_ = true; 70 pref_service_forked_ = true;
70 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); 71 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl();
71 OverlayUserPrefStore* incognito_pref_store = 72 OverlayUserPrefStore* incognito_pref_store =
72 new OverlayUserPrefStore(user_pref_store_.get()); 73 new OverlayUserPrefStore(user_pref_store_.get());
73 PrefsTabHelper::InitIncognitoUserPrefStore(incognito_pref_store); 74 if (!incognito_pref_created_cb.is_null())
gab 2015/09/11 12:58:32 This wasn't previously optional. Enforce it by con
sdefresne 2015/09/14 13:17:26 This is commented out in the downstream iOS fork (
75 incognito_pref_created_cb.Run(incognito_pref_store);
74 76
75 scoped_refptr<user_prefs::PrefRegistrySyncable> forked_registry = 77 scoped_refptr<user_prefs::PrefRegistrySyncable> forked_registry =
76 static_cast<user_prefs::PrefRegistrySyncable*>( 78 static_cast<user_prefs::PrefRegistrySyncable*>(pref_registry_.get())
77 pref_registry_.get())->ForkForIncognito(); 79 ->ForkForIncognito();
gab 2015/09/11 12:58:32 Weird formatting... preferred old one: same number
sdefresne 2015/09/14 13:17:26 Reverted.
78 PrefServiceSyncable* incognito_service = new PrefServiceSyncable( 80 PrefServiceSyncable* incognito_service = new PrefServiceSyncable(
79 pref_notifier, 81 pref_notifier,
80 pref_value_store_->CloneAndSpecialize(NULL, // managed 82 pref_value_store_->CloneAndSpecialize(NULL, // managed
81 NULL, // supervised_user 83 NULL, // supervised_user
82 incognito_extension_prefs, 84 incognito_extension_prefs,
83 NULL, // command_line_prefs 85 NULL, // command_line_prefs
84 incognito_pref_store, 86 incognito_pref_store,
85 NULL, // recommended 87 NULL, // recommended
86 forked_registry->defaults().get(), 88 forked_registry->defaults().get(),
87 pref_notifier), 89 pref_notifier),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 129 }
128 130
129 void PrefServiceSyncable::UpdateCommandLinePrefStore( 131 void PrefServiceSyncable::UpdateCommandLinePrefStore(
130 PrefStore* cmd_line_store) { 132 PrefStore* cmd_line_store) {
131 // If |pref_service_forked_| is true, then this PrefService and the forked 133 // If |pref_service_forked_| is true, then this PrefService and the forked
132 // copies will be out of sync. 134 // copies will be out of sync.
133 DCHECK(!pref_service_forked_); 135 DCHECK(!pref_service_forked_);
134 PrefService::UpdateCommandLinePrefStore(cmd_line_store); 136 PrefService::UpdateCommandLinePrefStore(cmd_line_store);
135 } 137 }
136 138
137 void PrefServiceSyncable::AddSyncedPrefObserver( 139 void PrefServiceSyncable::AddSyncedPrefObserver(const std::string& name,
138 const std::string& name, 140 SyncedPrefObserver* observer) {
139 SyncedPrefObserver* observer) {
140 pref_sync_associator_.AddSyncedPrefObserver(name, observer); 141 pref_sync_associator_.AddSyncedPrefObserver(name, observer);
141 priority_pref_sync_associator_.AddSyncedPrefObserver(name, observer); 142 priority_pref_sync_associator_.AddSyncedPrefObserver(name, observer);
142 } 143 }
143 144
144 void PrefServiceSyncable::RemoveSyncedPrefObserver( 145 void PrefServiceSyncable::RemoveSyncedPrefObserver(
145 const std::string& name, 146 const std::string& name,
146 SyncedPrefObserver* observer) { 147 SyncedPrefObserver* observer) {
147 pref_sync_associator_.RemoveSyncedPrefObserver(name, observer); 148 pref_sync_associator_.RemoveSyncedPrefObserver(name, observer);
148 priority_pref_sync_associator_.RemoveSyncedPrefObserver(name, observer); 149 priority_pref_sync_associator_.RemoveSyncedPrefObserver(name, observer);
149 } 150 }
150 151
151 void PrefServiceSyncable::AddRegisteredSyncablePreference( 152 void PrefServiceSyncable::AddRegisteredSyncablePreference(
152 const std::string& path, 153 const std::string& path,
153 uint32 flags) { 154 uint32 flags) {
154 DCHECK(FindPreference(path)); 155 DCHECK(FindPreference(path));
155 if (flags & user_prefs::PrefRegistrySyncable::SYNCABLE_PREF) { 156 if (flags & user_prefs::PrefRegistrySyncable::SYNCABLE_PREF) {
156 pref_sync_associator_.RegisterPref(path.c_str()); 157 pref_sync_associator_.RegisterPref(path.c_str());
157 } else if (flags & 158 } else if (flags & user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF) {
158 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF) {
159 priority_pref_sync_associator_.RegisterPref(path.c_str()); 159 priority_pref_sync_associator_.RegisterPref(path.c_str());
160 } 160 }
161 } 161 }
162 162
163 void PrefServiceSyncable::OnIsSyncingChanged() { 163 void PrefServiceSyncable::OnIsSyncingChanged() {
164 FOR_EACH_OBSERVER(PrefServiceSyncableObserver, observer_list_, 164 FOR_EACH_OBSERVER(PrefServiceSyncableObserver, observer_list_,
165 OnIsSyncingChanged()); 165 OnIsSyncingChanged());
166 } 166 }
167 167
168 void PrefServiceSyncable::ProcessPrefChange(const std::string& name) { 168 void PrefServiceSyncable::ProcessPrefChange(const std::string& name) {
169 pref_sync_associator_.ProcessPrefChange(name); 169 pref_sync_associator_.ProcessPrefChange(name);
170 priority_pref_sync_associator_.ProcessPrefChange(name); 170 priority_pref_sync_associator_.ProcessPrefChange(name);
171 } 171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698