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

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: Fix grammar error and rename incognito_extensions_prefs to incognito_extensions_prefs_store 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_pref_store,
68 const std::vector<const char*>& overlay_pref_names) {
69 pref_service_forked_ = true; 69 pref_service_forked_ = true;
70 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); 70 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl();
71 OverlayUserPrefStore* incognito_pref_store = 71 OverlayUserPrefStore* incognito_pref_store =
72 new OverlayUserPrefStore(user_pref_store_.get()); 72 new OverlayUserPrefStore(user_pref_store_.get());
73 PrefsTabHelper::InitIncognitoUserPrefStore(incognito_pref_store); 73 for (const char* overlay_pref_name : overlay_pref_names)
74 incognito_pref_store->RegisterOverlayPref(overlay_pref_name);
74 75
75 scoped_refptr<user_prefs::PrefRegistrySyncable> forked_registry = 76 scoped_refptr<user_prefs::PrefRegistrySyncable> forked_registry =
76 static_cast<user_prefs::PrefRegistrySyncable*>( 77 static_cast<user_prefs::PrefRegistrySyncable*>(
77 pref_registry_.get())->ForkForIncognito(); 78 pref_registry_.get())->ForkForIncognito();
78 PrefServiceSyncable* incognito_service = new PrefServiceSyncable( 79 PrefServiceSyncable* incognito_service = new PrefServiceSyncable(
79 pref_notifier, 80 pref_notifier,
80 pref_value_store_->CloneAndSpecialize(NULL, // managed 81 pref_value_store_->CloneAndSpecialize(NULL, // managed
81 NULL, // supervised_user 82 NULL, // supervised_user
82 incognito_extension_prefs, 83 incognito_extension_pref_store,
83 NULL, // command_line_prefs 84 NULL, // command_line_prefs
84 incognito_pref_store, 85 incognito_pref_store,
85 NULL, // recommended 86 NULL, // recommended
86 forked_registry->defaults().get(), 87 forked_registry->defaults().get(),
87 pref_notifier), 88 pref_notifier),
88 incognito_pref_store, 89 incognito_pref_store,
89 forked_registry.get(), 90 forked_registry.get(),
90 read_error_callback_, 91 read_error_callback_,
91 false); 92 false);
92 return incognito_service; 93 return incognito_service;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 128 }
128 129
129 void PrefServiceSyncable::UpdateCommandLinePrefStore( 130 void PrefServiceSyncable::UpdateCommandLinePrefStore(
130 PrefStore* cmd_line_store) { 131 PrefStore* cmd_line_store) {
131 // If |pref_service_forked_| is true, then this PrefService and the forked 132 // If |pref_service_forked_| is true, then this PrefService and the forked
132 // copies will be out of sync. 133 // copies will be out of sync.
133 DCHECK(!pref_service_forked_); 134 DCHECK(!pref_service_forked_);
134 PrefService::UpdateCommandLinePrefStore(cmd_line_store); 135 PrefService::UpdateCommandLinePrefStore(cmd_line_store);
135 } 136 }
136 137
137 void PrefServiceSyncable::AddSyncedPrefObserver( 138 void PrefServiceSyncable::AddSyncedPrefObserver(const std::string& name,
138 const std::string& name, 139 SyncedPrefObserver* observer) {
139 SyncedPrefObserver* observer) {
140 pref_sync_associator_.AddSyncedPrefObserver(name, observer); 140 pref_sync_associator_.AddSyncedPrefObserver(name, observer);
141 priority_pref_sync_associator_.AddSyncedPrefObserver(name, observer); 141 priority_pref_sync_associator_.AddSyncedPrefObserver(name, observer);
142 } 142 }
143 143
144 void PrefServiceSyncable::RemoveSyncedPrefObserver( 144 void PrefServiceSyncable::RemoveSyncedPrefObserver(
145 const std::string& name, 145 const std::string& name,
146 SyncedPrefObserver* observer) { 146 SyncedPrefObserver* observer) {
147 pref_sync_associator_.RemoveSyncedPrefObserver(name, observer); 147 pref_sync_associator_.RemoveSyncedPrefObserver(name, observer);
148 priority_pref_sync_associator_.RemoveSyncedPrefObserver(name, observer); 148 priority_pref_sync_associator_.RemoveSyncedPrefObserver(name, observer);
149 } 149 }
150 150
151 void PrefServiceSyncable::AddRegisteredSyncablePreference( 151 void PrefServiceSyncable::AddRegisteredSyncablePreference(
152 const std::string& path, 152 const std::string& path,
153 uint32 flags) { 153 uint32 flags) {
154 DCHECK(FindPreference(path)); 154 DCHECK(FindPreference(path));
155 if (flags & user_prefs::PrefRegistrySyncable::SYNCABLE_PREF) { 155 if (flags & user_prefs::PrefRegistrySyncable::SYNCABLE_PREF) {
156 pref_sync_associator_.RegisterPref(path.c_str()); 156 pref_sync_associator_.RegisterPref(path.c_str());
157 } else if (flags & 157 } 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()); 158 priority_pref_sync_associator_.RegisterPref(path.c_str());
160 } 159 }
161 } 160 }
162 161
163 void PrefServiceSyncable::OnIsSyncingChanged() { 162 void PrefServiceSyncable::OnIsSyncingChanged() {
164 FOR_EACH_OBSERVER(PrefServiceSyncableObserver, observer_list_, 163 FOR_EACH_OBSERVER(PrefServiceSyncableObserver, observer_list_,
165 OnIsSyncingChanged()); 164 OnIsSyncingChanged());
166 } 165 }
167 166
168 void PrefServiceSyncable::ProcessPrefChange(const std::string& name) { 167 void PrefServiceSyncable::ProcessPrefChange(const std::string& name) {
169 pref_sync_associator_.ProcessPrefChange(name); 168 pref_sync_associator_.ProcessPrefChange(name);
170 priority_pref_sync_associator_.ProcessPrefChange(name); 169 priority_pref_sync_associator_.ProcessPrefChange(name);
171 } 170 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/pref_service_syncable.h ('k') | chrome/browser/prefs/pref_service_syncable_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698