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

Side by Side Diff: chrome/browser/sync/glue/preference_model_associator.cc

Issue 6375007: [Sync] Refactored ProfileSyncService and remove its backend() function (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add comment Created 9 years, 11 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/sync/glue/preference_model_associator.h" 5 #include "chrome/browser/sync/glue/preference_model_associator.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
110 PrefService* pref_service = sync_service_->profile()->GetPrefs(); 110 PrefService* pref_service = sync_service_->profile()->GetPrefs();
111 111
112 int64 root_id; 112 int64 root_id;
113 if (!GetSyncIdForTaggedNode(kPreferencesTag, &root_id)) { 113 if (!GetSyncIdForTaggedNode(kPreferencesTag, &root_id)) {
114 LOG(ERROR) << "Server did not create the top-level preferences node. We " 114 LOG(ERROR) << "Server did not create the top-level preferences node. We "
115 << "might be running against an out-of-date server."; 115 << "might be running against an out-of-date server.";
116 return false; 116 return false;
117 } 117 }
118 118
119 sync_api::WriteTransaction trans( 119 sync_api::WriteTransaction trans(sync_service_->GetUserShare());
120 sync_service()->backend()->GetUserShareHandle());
121 sync_api::ReadNode root(&trans); 120 sync_api::ReadNode root(&trans);
122 if (!root.InitByIdLookup(root_id)) { 121 if (!root.InitByIdLookup(root_id)) {
123 LOG(ERROR) << "Server did not create the top-level preferences node. We " 122 LOG(ERROR) << "Server did not create the top-level preferences node. We "
124 << "might be running against an out-of-date server."; 123 << "might be running against an out-of-date server.";
125 return false; 124 return false;
126 } 125 }
127 126
128 for (std::set<std::string>::iterator it = synced_preferences_.begin(); 127 for (std::set<std::string>::iterator it = synced_preferences_.begin();
129 it != synced_preferences_.end(); ++it) { 128 it != synced_preferences_.end(); ++it) {
130 const PrefService::Preference* pref = 129 const PrefService::Preference* pref =
(...skipping 11 matching lines...) Expand all
142 141
143 bool PreferenceModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { 142 bool PreferenceModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) {
144 DCHECK(has_nodes); 143 DCHECK(has_nodes);
145 *has_nodes = false; 144 *has_nodes = false;
146 int64 preferences_sync_id; 145 int64 preferences_sync_id;
147 if (!GetSyncIdForTaggedNode(kPreferencesTag, &preferences_sync_id)) { 146 if (!GetSyncIdForTaggedNode(kPreferencesTag, &preferences_sync_id)) {
148 LOG(ERROR) << "Server did not create the top-level preferences node. We " 147 LOG(ERROR) << "Server did not create the top-level preferences node. We "
149 << "might be running against an out-of-date server."; 148 << "might be running against an out-of-date server.";
150 return false; 149 return false;
151 } 150 }
152 sync_api::ReadTransaction trans( 151 sync_api::ReadTransaction trans(sync_service_->GetUserShare());
153 sync_service()->backend()->GetUserShareHandle());
154 152
155 sync_api::ReadNode preferences_node(&trans); 153 sync_api::ReadNode preferences_node(&trans);
156 if (!preferences_node.InitByIdLookup(preferences_sync_id)) { 154 if (!preferences_node.InitByIdLookup(preferences_sync_id)) {
157 LOG(ERROR) << "Server did not create the top-level preferences node. We " 155 LOG(ERROR) << "Server did not create the top-level preferences node. We "
158 << "might be running against an out-of-date server."; 156 << "might be running against an out-of-date server.";
159 return false; 157 return false;
160 } 158 }
161 159
162 // The sync model has user created nodes if the preferences folder has any 160 // The sync model has user created nodes if the preferences folder has any
163 // children. 161 // children.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
198 SyncIdToPreferenceNameMap::iterator iter = id_map_inverse_.find(sync_id); 196 SyncIdToPreferenceNameMap::iterator iter = id_map_inverse_.find(sync_id);
199 if (iter == id_map_inverse_.end()) 197 if (iter == id_map_inverse_.end())
200 return; 198 return;
201 id_map_.erase(iter->second); 199 id_map_.erase(iter->second);
202 id_map_inverse_.erase(iter); 200 id_map_inverse_.erase(iter);
203 } 201 }
204 202
205 bool PreferenceModelAssociator::GetSyncIdForTaggedNode(const std::string& tag, 203 bool PreferenceModelAssociator::GetSyncIdForTaggedNode(const std::string& tag,
206 int64* sync_id) { 204 int64* sync_id) {
207 sync_api::ReadTransaction trans( 205 sync_api::ReadTransaction trans(sync_service_->GetUserShare());
208 sync_service_->backend()->GetUserShareHandle());
209 sync_api::ReadNode sync_node(&trans); 206 sync_api::ReadNode sync_node(&trans);
210 if (!sync_node.InitByTagLookup(tag.c_str())) 207 if (!sync_node.InitByTagLookup(tag.c_str()))
211 return false; 208 return false;
212 *sync_id = sync_node.GetId(); 209 *sync_id = sync_node.GetId();
213 return true; 210 return true;
214 } 211 }
215 212
216 Value* PreferenceModelAssociator::MergePreference( 213 Value* PreferenceModelAssociator::MergePreference(
217 const PrefService::Preference& local_pref, 214 const PrefService::Preference& local_pref,
218 const Value& server_value) { 215 const Value& server_value) {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 // notification to update the UI. 314 // notification to update the UI.
318 if (0 == pref_name.compare(prefs::kShowBookmarkBar)) { 315 if (0 == pref_name.compare(prefs::kShowBookmarkBar)) {
319 NotificationService::current()->Notify( 316 NotificationService::current()->Notify(
320 NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, 317 NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
321 Source<PreferenceModelAssociator>(this), 318 Source<PreferenceModelAssociator>(this),
322 NotificationService::NoDetails()); 319 NotificationService::NoDetails());
323 } 320 }
324 } 321 }
325 322
326 } // namespace browser_sync 323 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/preference_model_associator.h ('k') | chrome/browser/sync/glue/session_model_associator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698