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

Side by Side Diff: chrome/browser/sync/glue/autofill_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_model_associator.h" 5 #include "chrome/browser/sync/glue/autofill_model_associator.h"
6 6
7 #include <functional> 7 #include <functional>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/task.h" 11 #include "base/task.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "base/tracked.h" 13 #include "base/tracked.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/autofill/autofill_profile.h" 15 #include "chrome/browser/autofill/autofill_profile.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/sync/api/sync_error.h"
18 #include "chrome/browser/sync/engine/syncapi.h" 17 #include "chrome/browser/sync/engine/syncapi.h"
19 #include "chrome/browser/sync/glue/autofill_change_processor.h" 18 #include "chrome/browser/sync/glue/autofill_change_processor.h"
20 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h" 19 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h"
21 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h" 20 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h"
22 #include "chrome/browser/sync/profile_sync_service.h" 21 #include "chrome/browser/sync/profile_sync_service.h"
23 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" 22 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h"
24 #include "chrome/browser/webdata/web_database.h" 23 #include "chrome/browser/webdata/web_database.h"
25 #include "chrome/common/guid.h" 24 #include "chrome/common/guid.h"
26 #include "content/browser/browser_thread.h" 25 #include "content/browser/browser_thread.h"
27 #include "net/base/escape.h" 26 #include "net/base/escape.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 return false; 129 return false;
131 130
132 if (IsAbortPending()) 131 if (IsAbortPending())
133 return false; 132 return false;
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 AutofillModelAssociator::AssociateModels(SyncError* error) { 139 bool AutofillModelAssociator::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 // TODO(zork): Attempt to load the model association from storage. 147 // TODO(zork): Attempt to load the model association from storage.
149 std::vector<AutofillEntry> entries; 148 std::vector<AutofillEntry> entries;
150 ScopedVector<AutofillProfile> profiles; 149 ScopedVector<AutofillProfile> profiles;
151 150
152 if (!LoadAutofillData(&entries, &profiles.get())) { 151 if (!LoadAutofillData(&entries, &profiles.get())) {
153 error->Reset(FROM_HERE, 152 LOG(ERROR) << "Could not get the autofill data from WebDatabase.";
154 "Could not get the autofill data from WebDatabase.",
155 model_type());
156 return false; 153 return false;
157 } 154 }
158 155
159 DataBundle bundle; 156 DataBundle bundle;
160 { 157 {
161 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 158 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare());
162 159
163 sync_api::ReadNode autofill_root(&trans); 160 sync_api::ReadNode autofill_root(&trans);
164 if (!autofill_root.InitByTagLookup(kAutofillTag)) { 161 if (!autofill_root.InitByTagLookup(kAutofillTag)) {
165 error->Reset(FROM_HERE, 162 LOG(ERROR) << "Server did not create the top-level autofill node. We "
166 "Server did not create the top-level autofill node. We " 163 << "might be running against an out-of-date server.";
167 "might be running against an out-of-date server.",
168 model_type());
169 return false; 164 return false;
170 } 165 }
171 166
172 if (!TraverseAndAssociateChromeAutofillEntries(&trans, autofill_root, 167 if (!TraverseAndAssociateChromeAutofillEntries(&trans, autofill_root,
173 entries, &bundle.current_entries, &bundle.new_entries)) { 168 entries, &bundle.current_entries, &bundle.new_entries)) {
174 error->Reset(FROM_HERE, "Failed to associate entries.", model_type());
175 return false; 169 return false;
176 } 170 }
177 171
178 if (!TraverseAndAssociateAllSyncNodes( 172 if (!TraverseAndAssociateAllSyncNodes(
179 &trans, 173 &trans,
180 autofill_root, 174 autofill_root,
181 &bundle, 175 &bundle,
182 profiles.get())) { 176 profiles.get())) {
183 error->Reset(FROM_HERE, "Failed to associate sync nodes.", model_type());
184 return false; 177 return false;
185 } 178 }
186 } 179 }
187 180
188 // Since we're on the DB thread, we don't have to worry about updating 181 // Since we're on the DB thread, we don't have to worry about updating
189 // the autofill database after closing the write transaction, since 182 // the autofill database after closing the write transaction, since
190 // this is the only thread that writes to the database. We also don't have 183 // this is the only thread that writes to the database. We also don't have
191 // to worry about the sync model getting out of sync, because changes are 184 // to worry about the sync model getting out of sync, because changes are
192 // propagated to the ChangeProcessor on this thread. 185 // propagated to the ChangeProcessor on this thread.
193 if (!SaveChangesToWebData(bundle)) { 186 if (!SaveChangesToWebData(bundle)) {
194 error->Reset(FROM_HERE, "Failed to update webdata.", model_type()); 187 LOG(ERROR) << "Failed to update autofill entries.";
195 return false; 188 return false;
196 } 189 }
197 190
198 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 191 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
199 new DoOptimisticRefreshForAutofill(personal_data_)); 192 new DoOptimisticRefreshForAutofill(personal_data_));
200 return true; 193 return true;
201 } 194 }
202 195
203 bool AutofillModelAssociator::SaveChangesToWebData(const DataBundle& bundle) { 196 bool AutofillModelAssociator::SaveChangesToWebData(const DataBundle& bundle) {
204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 DCHECK(false) << "Guid generated is invalid " << guid; 338 DCHECK(false) << "Guid generated is invalid " << guid;
346 return; 339 return;
347 } 340 }
348 Associate(&guid, node.GetId()); 341 Associate(&guid, node.GetId());
349 AutofillProfile* p = new AutofillProfile(guid); 342 AutofillProfile* p = new AutofillProfile(guid);
350 FillProfileWithServerData(p, profile); 343 FillProfileWithServerData(p, profile);
351 bundle->new_profiles.push_back(p); 344 bundle->new_profiles.push_back(p);
352 } 345 }
353 } 346 }
354 347
355 bool AutofillModelAssociator::DisassociateModels(SyncError* error) { 348 bool AutofillModelAssociator::DisassociateModels() {
356 id_map_.clear(); 349 id_map_.clear();
357 id_map_inverse_.clear(); 350 id_map_inverse_.clear();
358 return true; 351 return true;
359 } 352 }
360 353
361 bool AutofillModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { 354 bool AutofillModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) {
362 DCHECK(has_nodes); 355 DCHECK(has_nodes);
363 *has_nodes = false; 356 *has_nodes = false;
364 int64 autofill_sync_id; 357 int64 autofill_sync_id;
365 if (!GetSyncIdForTaggedNode(kAutofillTag, &autofill_sync_id)) { 358 if (!GetSyncIdForTaggedNode(kAutofillTag, &autofill_sync_id)) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 bool AutofillModelAssociator::CryptoReadyIfNecessary() { 506 bool AutofillModelAssociator::CryptoReadyIfNecessary() {
514 // We only access the cryptographer while holding a transaction. 507 // We only access the cryptographer while holding a transaction.
515 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 508 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
516 syncable::ModelTypeSet encrypted_types; 509 syncable::ModelTypeSet encrypted_types;
517 encrypted_types = sync_api::GetEncryptedTypes(&trans); 510 encrypted_types = sync_api::GetEncryptedTypes(&trans);
518 return encrypted_types.count(syncable::AUTOFILL) == 0 || 511 return encrypted_types.count(syncable::AUTOFILL) == 0 ||
519 sync_service_->IsCryptographerReady(&trans); 512 sync_service_->IsCryptographerReady(&trans);
520 } 513 }
521 514
522 } // namespace browser_sync 515 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/autofill_model_associator.h ('k') | chrome/browser/sync/glue/autofill_profile_model_associator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698