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

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

Issue 14622003: components: Move PrefRegistrySyncable into user_prefs namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 7 years, 7 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 | 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_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/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/prefs/default_pref_store.h" 9 #include "base/prefs/default_pref_store.h"
10 #include "base/prefs/overlay_user_pref_store.h" 10 #include "base/prefs/overlay_user_pref_store.h"
(...skipping 16 matching lines...) Expand all
27 // static 27 // static
28 PrefServiceSyncable* PrefServiceSyncable::IncognitoFromProfile( 28 PrefServiceSyncable* PrefServiceSyncable::IncognitoFromProfile(
29 Profile* profile) { 29 Profile* profile) {
30 return static_cast<PrefServiceSyncable*>(profile->GetOffTheRecordPrefs()); 30 return static_cast<PrefServiceSyncable*>(profile->GetOffTheRecordPrefs());
31 } 31 }
32 32
33 PrefServiceSyncable::PrefServiceSyncable( 33 PrefServiceSyncable::PrefServiceSyncable(
34 PrefNotifierImpl* pref_notifier, 34 PrefNotifierImpl* pref_notifier,
35 PrefValueStore* pref_value_store, 35 PrefValueStore* pref_value_store,
36 PersistentPrefStore* user_prefs, 36 PersistentPrefStore* user_prefs,
37 PrefRegistrySyncable* pref_registry, 37 user_prefs::PrefRegistrySyncable* pref_registry,
38 base::Callback<void(PersistentPrefStore::PrefReadError)> 38 base::Callback<void(PersistentPrefStore::PrefReadError)>
39 read_error_callback, 39 read_error_callback,
40 bool async) 40 bool async)
41 : PrefService(pref_notifier, 41 : PrefService(pref_notifier,
42 pref_value_store, 42 pref_value_store,
43 user_prefs, 43 user_prefs,
44 pref_registry, 44 pref_registry,
45 read_error_callback, 45 read_error_callback,
46 async), 46 async),
47 pref_sync_associator_(syncer::PREFERENCES), 47 pref_sync_associator_(syncer::PREFERENCES),
48 priority_pref_sync_associator_(syncer::PRIORITY_PREFERENCES) { 48 priority_pref_sync_associator_(syncer::PRIORITY_PREFERENCES) {
49 pref_sync_associator_.SetPrefService(this); 49 pref_sync_associator_.SetPrefService(this);
50 priority_pref_sync_associator_.SetPrefService(this); 50 priority_pref_sync_associator_.SetPrefService(this);
51 51
52 // Let PrefModelAssociators know about changes to preference values. 52 // Let PrefModelAssociators know about changes to preference values.
53 pref_value_store->set_callback( 53 pref_value_store->set_callback(
54 base::Bind(&PrefServiceSyncable::ProcessPrefChange, 54 base::Bind(&PrefServiceSyncable::ProcessPrefChange,
55 base::Unretained(this))); 55 base::Unretained(this)));
56 56
57 // Add already-registered syncable preferences to PrefModelAssociator. 57 // Add already-registered syncable preferences to PrefModelAssociator.
58 const PrefRegistrySyncable::PrefToStatus& syncable_preferences = 58 const user_prefs::PrefRegistrySyncable::PrefToStatus& syncable_preferences =
59 pref_registry->syncable_preferences(); 59 pref_registry->syncable_preferences();
60 for (PrefRegistrySyncable::PrefToStatus::const_iterator it = 60 for (user_prefs::PrefRegistrySyncable::PrefToStatus::const_iterator it =
61 syncable_preferences.begin(); 61 syncable_preferences.begin();
62 it != syncable_preferences.end(); 62 it != syncable_preferences.end();
63 ++it) { 63 ++it) {
64 AddRegisteredSyncablePreference(it->first.c_str(), it->second); 64 AddRegisteredSyncablePreference(it->first.c_str(), it->second);
65 } 65 }
66 66
67 // Watch for syncable preferences registered after this point. 67 // Watch for syncable preferences registered after this point.
68 pref_registry->SetSyncableRegistrationCallback( 68 pref_registry->SetSyncableRegistrationCallback(
69 base::Bind(&PrefServiceSyncable::AddRegisteredSyncablePreference, 69 base::Bind(&PrefServiceSyncable::AddRegisteredSyncablePreference,
70 base::Unretained(this))); 70 base::Unretained(this)));
71 } 71 }
72 72
73 PrefServiceSyncable::~PrefServiceSyncable() { 73 PrefServiceSyncable::~PrefServiceSyncable() {
74 // Remove our callback from the registry, since it may outlive us. 74 // Remove our callback from the registry, since it may outlive us.
75 PrefRegistrySyncable* registry = 75 user_prefs::PrefRegistrySyncable* registry =
76 static_cast<PrefRegistrySyncable*>(pref_registry_.get()); 76 static_cast<user_prefs::PrefRegistrySyncable*>(pref_registry_.get());
77 registry->SetSyncableRegistrationCallback( 77 registry->SetSyncableRegistrationCallback(
78 PrefRegistrySyncable::SyncableRegistrationCallback()); 78 user_prefs::PrefRegistrySyncable::SyncableRegistrationCallback());
79 } 79 }
80 80
81 PrefServiceSyncable* PrefServiceSyncable::CreateIncognitoPrefService( 81 PrefServiceSyncable* PrefServiceSyncable::CreateIncognitoPrefService(
82 PrefStore* incognito_extension_prefs) { 82 PrefStore* incognito_extension_prefs) {
83 pref_service_forked_ = true; 83 pref_service_forked_ = true;
84 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); 84 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl();
85 OverlayUserPrefStore* incognito_pref_store = 85 OverlayUserPrefStore* incognito_pref_store =
86 new OverlayUserPrefStore(user_pref_store_.get()); 86 new OverlayUserPrefStore(user_pref_store_.get());
87 PrefsTabHelper::InitIncognitoUserPrefStore(incognito_pref_store); 87 PrefsTabHelper::InitIncognitoUserPrefStore(incognito_pref_store);
88 88
89 scoped_refptr<PrefRegistrySyncable> forked_registry = 89 scoped_refptr<user_prefs::PrefRegistrySyncable> forked_registry =
90 static_cast<PrefRegistrySyncable*>( 90 static_cast<user_prefs::PrefRegistrySyncable*>(
91 pref_registry_.get())->ForkForIncognito(); 91 pref_registry_.get())->ForkForIncognito();
92 PrefServiceSyncable* incognito_service = new PrefServiceSyncable( 92 PrefServiceSyncable* incognito_service = new PrefServiceSyncable(
93 pref_notifier, 93 pref_notifier,
94 pref_value_store_->CloneAndSpecialize( 94 pref_value_store_->CloneAndSpecialize(
95 NULL, // managed 95 NULL, // managed
96 incognito_extension_prefs, 96 incognito_extension_prefs,
97 NULL, // command_line_prefs 97 NULL, // command_line_prefs
98 incognito_pref_store, 98 incognito_pref_store,
99 NULL, // recommended 99 NULL, // recommended
100 forked_registry->defaults(), 100 forked_registry->defaults(),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 void PrefServiceSyncable::UpdateCommandLinePrefStore( 139 void PrefServiceSyncable::UpdateCommandLinePrefStore(
140 PrefStore* cmd_line_store) { 140 PrefStore* cmd_line_store) {
141 // If |pref_service_forked_| is true, then this PrefService and the forked 141 // If |pref_service_forked_| is true, then this PrefService and the forked
142 // copies will be out of sync. 142 // copies will be out of sync.
143 DCHECK(!pref_service_forked_); 143 DCHECK(!pref_service_forked_);
144 PrefService::UpdateCommandLinePrefStore(cmd_line_store); 144 PrefService::UpdateCommandLinePrefStore(cmd_line_store);
145 } 145 }
146 146
147 void PrefServiceSyncable::AddRegisteredSyncablePreference( 147 void PrefServiceSyncable::AddRegisteredSyncablePreference(
148 const char* path, 148 const char* path,
149 const PrefRegistrySyncable::PrefSyncStatus sync_status) { 149 const user_prefs::PrefRegistrySyncable::PrefSyncStatus sync_status) {
150 DCHECK(FindPreference(path)); 150 DCHECK(FindPreference(path));
151 if (sync_status == PrefRegistrySyncable::SYNCABLE_PREF) { 151 if (sync_status == user_prefs::PrefRegistrySyncable::SYNCABLE_PREF) {
152 pref_sync_associator_.RegisterPref(path); 152 pref_sync_associator_.RegisterPref(path);
153 } else if (sync_status == PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF) { 153 } else if (sync_status ==
154 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF) {
154 priority_pref_sync_associator_.RegisterPref(path); 155 priority_pref_sync_associator_.RegisterPref(path);
155 } else { 156 } else {
156 NOTREACHED() << "invalid sync_status: " << sync_status; 157 NOTREACHED() << "invalid sync_status: " << sync_status;
157 } 158 }
158 } 159 }
159 160
160 void PrefServiceSyncable::OnIsSyncingChanged() { 161 void PrefServiceSyncable::OnIsSyncingChanged() {
161 FOR_EACH_OBSERVER(PrefServiceSyncableObserver, observer_list_, 162 FOR_EACH_OBSERVER(PrefServiceSyncableObserver, observer_list_,
162 OnIsSyncingChanged()); 163 OnIsSyncingChanged());
163 } 164 }
164 165
165 void PrefServiceSyncable::ProcessPrefChange(const std::string& name) { 166 void PrefServiceSyncable::ProcessPrefChange(const std::string& name) {
166 pref_sync_associator_.ProcessPrefChange(name); 167 pref_sync_associator_.ProcessPrefChange(name);
167 priority_pref_sync_associator_.ProcessPrefChange(name); 168 priority_pref_sync_associator_.ProcessPrefChange(name);
168 } 169 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/pref_service_syncable.h ('k') | chrome/browser/prefs/pref_service_syncable_builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698