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

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

Issue 7497014: Revert 94128 - [Sync] Refactor sync datatype error handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/tracked.h" 7 #include "base/tracked.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/sync/api/sync_error.h"
10 #include "chrome/browser/sync/glue/autofill_profile_change_processor.h" 9 #include "chrome/browser/sync/glue/autofill_profile_change_processor.h"
11 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h" 10 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h"
12 #include "chrome/browser/sync/profile_sync_service.h" 11 #include "chrome/browser/sync/profile_sync_service.h"
13 #include "chrome/browser/webdata/web_database.h" 12 #include "chrome/browser/webdata/web_database.h"
14 #include "chrome/common/guid.h" 13 #include "chrome/common/guid.h"
15 14
16 using sync_api::ReadNode; 15 using sync_api::ReadNode;
17 namespace browser_sync { 16 namespace browser_sync {
18 17
19 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles"; 18 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles";
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 std::vector<AutofillProfile*>* profiles) { 129 std::vector<AutofillProfile*>* profiles) {
131 if (IsAbortPending()) 130 if (IsAbortPending())
132 return false; 131 return false;
133 132
134 if (!web_database_->GetAutofillTable()->GetAutofillProfiles(profiles)) 133 if (!web_database_->GetAutofillTable()->GetAutofillProfiles(profiles))
135 return false; 134 return false;
136 135
137 return true; 136 return true;
138 } 137 }
139 138
140 bool AutofillProfileModelAssociator::AssociateModels(SyncError* error) { 139 bool AutofillProfileModelAssociator::AssociateModels() {
141 VLOG(1) << "Associating Autofill Models"; 140 VLOG(1) << "Associating Autofill Models";
142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
143 { 142 {
144 base::AutoLock lock(abort_association_pending_lock_); 143 base::AutoLock lock(abort_association_pending_lock_);
145 abort_association_pending_ = false; 144 abort_association_pending_ = false;
146 } 145 }
147 146
148 ScopedVector<AutofillProfile> profiles; 147 ScopedVector<AutofillProfile> profiles;
149 148
150 if (!LoadAutofillData(&profiles.get())) { 149 if (!LoadAutofillData(&profiles.get())) {
151 error->Reset(FROM_HERE, 150 LOG(ERROR) << "Could not get the autofill data from WebDatabase.";
152 "Could not get the autofill data from WebDatabase.",
153 model_type());
154 return false; 151 return false;
155 } 152 }
156 153
157 VLOG(1) << "[AUTOFILL MIGRATION]" 154 VLOG(1) << "[AUTOFILL MIGRATION]"
158 << " Now associating to the new autofill profile model associator" 155 << " Now associating to the new autofill profile model associator"
159 << " root node"; 156 << " root node";
160 DataBundle bundle; 157 DataBundle bundle;
161 { 158 {
162 // The write transaction lock is held inside this block. 159 // The write transaction lock is held inside this block.
163 // We do all the web db operations outside this block. 160 // We do all the web db operations outside this block.
164 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 161 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare());
165 162
166 sync_api::ReadNode autofill_root(&trans); 163 sync_api::ReadNode autofill_root(&trans);
167 if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) { 164 if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) {
168 error->Reset(FROM_HERE, 165 LOG(ERROR) << "Server did not create the top-level autofill node. We "
169 "Server did not create the top-level autofill node. We " 166 << "might be running against an out-of-date server.";
170 "might be running against an out-of-date server.",
171 model_type());
172 return false; 167 return false;
173 } 168 }
174 169
175 if (!TraverseAndAssociateChromeAutofillProfiles(&trans, autofill_root, 170 if (!TraverseAndAssociateChromeAutofillProfiles(&trans, autofill_root,
176 profiles.get(), &bundle.current_profiles, 171 profiles.get(), &bundle.current_profiles,
177 &bundle.updated_profiles, 172 &bundle.updated_profiles,
178 &bundle.new_profiles, 173 &bundle.new_profiles,
179 &bundle.profiles_to_delete) || 174 &bundle.profiles_to_delete) ||
180 !TraverseAndAssociateAllSyncNodes(&trans, autofill_root, &bundle)) { 175 !TraverseAndAssociateAllSyncNodes(&trans, autofill_root, &bundle)) {
181 error->Reset(FROM_HERE,
182 "Failed to associate all sync nodes.",
183 model_type());
184 return false; 176 return false;
185 } 177 }
186 } 178 }
187 179
188 if (!SaveChangesToWebData(bundle)) { 180 if (!SaveChangesToWebData(bundle)) {
189 error->Reset(FROM_HERE, "Failed to update webdata.", model_type()); 181 LOG(ERROR) << "Failed to update autofill entries.";
190 return false; 182 return false;
191 } 183 }
192 184
193 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 185 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
194 new DoOptimisticRefreshForAutofill(personal_data_)); 186 new DoOptimisticRefreshForAutofill(personal_data_));
195 return true; 187 return true;
196 } 188 }
197 189
198 bool AutofillProfileModelAssociator::DisassociateModels(SyncError* error) { 190 bool AutofillProfileModelAssociator::DisassociateModels() {
199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
200 id_map_.clear(); 192 id_map_.clear();
201 id_map_inverse_.clear(); 193 id_map_inverse_.clear();
202 return true; 194 return true;
203 } 195 }
204 196
205 // Helper to compare the local value and cloud value of a field, merge into 197 // Helper to compare the local value and cloud value of a field, merge into
206 // the local value if they differ, and return whether the merge happened. 198 // the local value if they differ, and return whether the merge happened.
207 bool AutofillProfileModelAssociator::MergeField(FormGroup* f, 199 bool AutofillProfileModelAssociator::MergeField(FormGroup* f,
208 AutofillFieldType t, 200 AutofillFieldType t,
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 bool AutofillProfileModelAssociator::CryptoReadyIfNecessary() { 496 bool AutofillProfileModelAssociator::CryptoReadyIfNecessary() {
505 // We only access the cryptographer while holding a transaction. 497 // We only access the cryptographer while holding a transaction.
506 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 498 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
507 syncable::ModelTypeSet encrypted_types; 499 syncable::ModelTypeSet encrypted_types;
508 encrypted_types = sync_api::GetEncryptedTypes(&trans); 500 encrypted_types = sync_api::GetEncryptedTypes(&trans);
509 return encrypted_types.count(syncable::AUTOFILL_PROFILE) == 0 || 501 return encrypted_types.count(syncable::AUTOFILL_PROFILE) == 0 ||
510 sync_service_->IsCryptographerReady(&trans); 502 sync_service_->IsCryptographerReady(&trans);
511 } 503 }
512 504
513 } // namespace browser_sync 505 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698