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

Side by Side Diff: chrome/browser/sync/glue/autofill_profile_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/autofill_profile_model_associator.h" 5 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/sync/glue/autofill_profile_change_processor.h" 8 #include "chrome/browser/sync/glue/autofill_profile_change_processor.h"
9 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h" 9 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h"
10 #include "chrome/browser/sync/profile_sync_service.h" 10 #include "chrome/browser/sync/profile_sync_service.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 current_profiles, 98 current_profiles,
99 profiles_to_delete); 99 profiles_to_delete);
100 } 100 }
101 } 101 }
102 return true; 102 return true;
103 } 103 }
104 104
105 bool AutofillProfileModelAssociator::GetSyncIdForTaggedNode( 105 bool AutofillProfileModelAssociator::GetSyncIdForTaggedNode(
106 const std::string& tag, 106 const std::string& tag,
107 int64* sync_id) { 107 int64* sync_id) {
108 sync_api::ReadTransaction trans( 108 sync_api::ReadTransaction trans(sync_service_->GetUserShare());
109 sync_service_->backend()->GetUserShareHandle());
110 sync_api::ReadNode sync_node(&trans); 109 sync_api::ReadNode sync_node(&trans);
111 if (!sync_node.InitByTagLookup(tag.c_str())) 110 if (!sync_node.InitByTagLookup(tag.c_str()))
112 return false; 111 return false;
113 *sync_id = sync_node.GetId(); 112 *sync_id = sync_node.GetId();
114 return true; 113 return true;
115 } 114 }
116 115
117 bool AutofillProfileModelAssociator::LoadAutofillData( 116 bool AutofillProfileModelAssociator::LoadAutofillData(
118 std::vector<AutoFillProfile*>* profiles) { 117 std::vector<AutoFillProfile*>* profiles) {
119 if (IsAbortPending()) 118 if (IsAbortPending())
(...skipping 20 matching lines...) Expand all
140 return false; 139 return false;
141 } 140 }
142 141
143 VLOG(1) << "[AUTOFILL MIGRATION]" 142 VLOG(1) << "[AUTOFILL MIGRATION]"
144 << " Now associating to the new autofill profile model associator" 143 << " Now associating to the new autofill profile model associator"
145 << " root node"; 144 << " root node";
146 DataBundle bundle; 145 DataBundle bundle;
147 { 146 {
148 // The write transaction lock is held inside this block. 147 // The write transaction lock is held inside this block.
149 // We do all the web db operations outside this block. 148 // We do all the web db operations outside this block.
150 sync_api::WriteTransaction trans( 149 sync_api::WriteTransaction trans(sync_service_->GetUserShare());
151 sync_service_->backend()->GetUserShareHandle());
152 150
153 sync_api::ReadNode autofill_root(&trans); 151 sync_api::ReadNode autofill_root(&trans);
154 if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) { 152 if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) {
155 LOG(ERROR) << "Server did not create the top-level autofill node. We " 153 LOG(ERROR) << "Server did not create the top-level autofill node. We "
156 << "might be running against an out-of-date server."; 154 << "might be running against an out-of-date server.";
157 return false; 155 return false;
158 } 156 }
159 157
160 if (!TraverseAndAssociateChromeAutoFillProfiles(&trans, autofill_root, 158 if (!TraverseAndAssociateChromeAutoFillProfiles(&trans, autofill_root,
161 profiles.get(), &bundle.current_profiles, 159 profiles.get(), &bundle.current_profiles,
162 &bundle.updated_profiles, 160 &bundle.updated_profiles,
163 &bundle.new_profiles, 161 &bundle.new_profiles,
164 &bundle.profiles_to_delete) || 162 &bundle.profiles_to_delete) ||
165 !TraverseAndAssociateAllSyncNodes(&trans, autofill_root, &bundle)) { 163 !TraverseAndAssociateAllSyncNodes(&trans, autofill_root, &bundle)) {
166 return false; 164 return false;
167 } 165 }
168 } 166 }
169 167
170 if (!SaveChangesToWebData(bundle)) { 168 if (!SaveChangesToWebData(bundle)) {
171 LOG(ERROR) << "Failed to update autofill entries."; 169 LOG(ERROR) << "Failed to update autofill entries.";
172 return false; 170 return false;
173 } 171 }
174 172
175 if (sync_service_->backend()->GetAutofillMigrationState() != 173 if (sync_service_->GetAutofillMigrationState() !=
176 syncable::MIGRATED) { 174 syncable::MIGRATED) {
177 syncable::AutofillMigrationDebugInfo debug_info; 175 syncable::AutofillMigrationDebugInfo debug_info;
178 debug_info.autofill_profile_added_during_migration = 176 debug_info.autofill_profile_added_during_migration =
179 number_of_profiles_created_; 177 number_of_profiles_created_;
180 sync_service_->backend()->SetAutofillMigrationDebugInfo( 178 sync_service_->SetAutofillMigrationDebugInfo(
181 syncable::AutofillMigrationDebugInfo::PROFILES_ADDED, 179 syncable::AutofillMigrationDebugInfo::PROFILES_ADDED,
182 debug_info); 180 debug_info);
183 sync_service()->backend()->SetAutofillMigrationState( 181 sync_service_->SetAutofillMigrationState(
184 syncable::MIGRATED); 182 syncable::MIGRATED);
185 } 183 }
186 184
187 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 185 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
188 new DoOptimisticRefreshForAutofill(personal_data_)); 186 new DoOptimisticRefreshForAutofill(personal_data_));
189 return true; 187 return true;
190 } 188 }
191 189
192 bool AutofillProfileModelAssociator::DisassociateModels() { 190 bool AutofillProfileModelAssociator::DisassociateModels() {
193 id_map_.clear(); 191 id_map_.clear();
194 id_map_inverse_.clear(); 192 id_map_inverse_.clear();
195 return true; 193 return true;
196 } 194 }
197 195
198 // Helper to compare the local value and cloud value of a field, merge into 196 // Helper to compare the local value and cloud value of a field, merge into
199 // the local value if they differ, and return whether the merge happened. 197 // the local value if they differ, and return whether the merge happened.
200 bool AutofillProfileModelAssociator::MergeField(FormGroup* f, 198 bool AutofillProfileModelAssociator::MergeField(FormGroup* f,
201 AutoFillFieldType t, 199 AutoFillFieldType t,
202 const std::string& specifics_field) { 200 const std::string& specifics_field) {
203 if (UTF16ToUTF8(f->GetFieldText(AutoFillType(t))) == specifics_field) 201 if (UTF16ToUTF8(f->GetFieldText(AutoFillType(t))) == specifics_field)
204 return false; 202 return false;
205 f->SetInfo(AutoFillType(t), UTF8ToUTF16(specifics_field)); 203 f->SetInfo(AutoFillType(t), UTF8ToUTF16(specifics_field));
206 return true; 204 return true;
207 } 205 }
208 bool AutofillProfileModelAssociator::SyncModelHasUserCreatedNodes( 206 bool AutofillProfileModelAssociator::SyncModelHasUserCreatedNodes(
209 bool *has_nodes) { 207 bool *has_nodes) {
210 CHECK_NE(has_nodes, reinterpret_cast<bool*>(NULL)); 208 CHECK_NE(has_nodes, reinterpret_cast<bool*>(NULL));
211 sync_api::ReadTransaction trans( 209 sync_api::ReadTransaction trans(sync_service_->GetUserShare());
212 sync_service_->backend()->GetUserShareHandle());
213 210
214 sync_api::ReadNode node(&trans); 211 sync_api::ReadNode node(&trans);
215 212
216 if (!node.InitByTagLookup(kAutofillProfileTag)) { 213 if (!node.InitByTagLookup(kAutofillProfileTag)) {
217 LOG(ERROR) << "Sever did not create a top level node" 214 LOG(ERROR) << "Sever did not create a top level node"
218 << "Out of data server or autofill type not enabled"; 215 << "Out of data server or autofill type not enabled";
219 return false; 216 return false;
220 } 217 }
221 218
222 *has_nodes = sync_api::kInvalidId != node.GetFirstChildId(); 219 *has_nodes = sync_api::kInvalidId != node.GetFirstChildId();
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 return iter == id_map_inverse_.end() ? NULL : &(iter->second); 465 return iter == id_map_inverse_.end() ? NULL : &(iter->second);
469 } 466 }
470 467
471 bool AutofillProfileModelAssociator::IsAbortPending() { 468 bool AutofillProfileModelAssociator::IsAbortPending() {
472 base::AutoLock lock(abort_association_pending_lock_); 469 base::AutoLock lock(abort_association_pending_lock_);
473 return abort_association_pending_; 470 return abort_association_pending_;
474 } 471 }
475 472
476 } // namespace browser_sync 473 } // namespace browser_sync
477 474
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/autofill_profile_model_associator.h ('k') | chrome/browser/sync/glue/bookmark_model_associator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698