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

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

Issue 6673079: Reduce boxing and unboxing of AutofillFieldType (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years, 9 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/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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 std::vector<std::string>* profiles_to_delete) { 55 std::vector<std::string>* profiles_to_delete) {
56 56
57 if (VLOG_IS_ON(2)) { 57 if (VLOG_IS_ON(2)) {
58 VLOG(2) << "[AUTOFILL MIGRATION]" 58 VLOG(2) << "[AUTOFILL MIGRATION]"
59 << "Printing profiles from web db"; 59 << "Printing profiles from web db";
60 60
61 for (std::vector<AutofillProfile*>::const_iterator ix = 61 for (std::vector<AutofillProfile*>::const_iterator ix =
62 all_profiles_from_db.begin(); ix != all_profiles_from_db.end(); ++ix) { 62 all_profiles_from_db.begin(); ix != all_profiles_from_db.end(); ++ix) {
63 AutofillProfile* p = *ix; 63 AutofillProfile* p = *ix;
64 VLOG(2) << "[AUTOFILL MIGRATION] " 64 VLOG(2) << "[AUTOFILL MIGRATION] "
65 << p->GetFieldText(AutofillType(NAME_FIRST)) 65 << p->GetFieldText(NAME_FIRST)
66 << p->GetFieldText(AutofillType(NAME_LAST)) 66 << p->GetFieldText(NAME_LAST)
67 << p->guid(); 67 << p->guid();
68 } 68 }
69 } 69 }
70 70
71 VLOG(1) << "[AUTOFILL MIGRATION]" 71 VLOG(1) << "[AUTOFILL MIGRATION]"
72 << "Looking for the above data in sync db.."; 72 << "Looking for the above data in sync db..";
73 73
74 // Alias the all_profiles_from_db so we fit in 80 characters 74 // Alias the all_profiles_from_db so we fit in 80 characters
75 const std::vector<AutofillProfile*>& profiles(all_profiles_from_db); 75 const std::vector<AutofillProfile*>& profiles(all_profiles_from_db);
76 for (std::vector<AutofillProfile*>::const_iterator ix = profiles.begin(); 76 for (std::vector<AutofillProfile*>::const_iterator ix = profiles.begin();
77 ix != profiles.end(); 77 ix != profiles.end();
78 ++ix) { 78 ++ix) {
79 std::string guid((*ix)->guid()); 79 std::string guid((*ix)->guid());
80 if (guid::IsValidGUID(guid) == false) { 80 if (guid::IsValidGUID(guid) == false) {
81 DCHECK(false) << "Guid in the web db is invalid " << guid; 81 DCHECK(false) << "Guid in the web db is invalid " << guid;
82 continue; 82 continue;
83 } 83 }
84 84
85 ReadNode node(write_trans); 85 ReadNode node(write_trans);
86 if (node.InitByClientTagLookup(syncable::AUTOFILL_PROFILE, guid) && 86 if (node.InitByClientTagLookup(syncable::AUTOFILL_PROFILE, guid) &&
87 // The following check is to ensure the given sync node is not already 87 // The following check is to ensure the given sync node is not already
88 // associated with another profile. That could happen if the user has 88 // associated with another profile. That could happen if the user has
89 // the same profile duplicated. 89 // the same profile duplicated.
90 current_profiles->find(guid) == current_profiles->end()) { 90 current_profiles->find(guid) == current_profiles->end()) {
91 VLOG(2) << "[AUTOFILL MIGRATION]" 91 VLOG(2) << "[AUTOFILL MIGRATION]"
92 << " Found in sync db: " 92 << " Found in sync db: "
93 << (*ix)->GetFieldText(AutofillType(NAME_FIRST)) 93 << (*ix)->GetFieldText(NAME_FIRST)
94 << (*ix)->GetFieldText(AutofillType(NAME_LAST)) 94 << (*ix)->GetFieldText(NAME_LAST)
95 << (*ix)->guid() 95 << (*ix)->guid()
96 << " so associating with node id " << node.GetId(); 96 << " so associating with node id " << node.GetId();
97 const sync_pb::AutofillProfileSpecifics& autofill( 97 const sync_pb::AutofillProfileSpecifics& autofill(
98 node.GetAutofillProfileSpecifics()); 98 node.GetAutofillProfileSpecifics());
99 if (OverwriteProfileWithServerData(*ix, autofill)) { 99 if (OverwriteProfileWithServerData(*ix, autofill)) {
100 updated_profiles->push_back(*ix); 100 updated_profiles->push_back(*ix);
101 } 101 }
102 Associate(&guid, node.GetId()); 102 Associate(&guid, node.GetId());
103 current_profiles->insert(guid); 103 current_profiles->insert(guid);
104 } else { 104 } else {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 id_map_.clear(); 203 id_map_.clear();
204 id_map_inverse_.clear(); 204 id_map_inverse_.clear();
205 return true; 205 return true;
206 } 206 }
207 207
208 // Helper to compare the local value and cloud value of a field, merge into 208 // Helper to compare the local value and cloud value of a field, merge into
209 // the local value if they differ, and return whether the merge happened. 209 // the local value if they differ, and return whether the merge happened.
210 bool AutofillProfileModelAssociator::MergeField(FormGroup* f, 210 bool AutofillProfileModelAssociator::MergeField(FormGroup* f,
211 AutofillFieldType t, 211 AutofillFieldType t,
212 const std::string& specifics_field) { 212 const std::string& specifics_field) {
213 if (UTF16ToUTF8(f->GetFieldText(AutofillType(t))) == specifics_field) 213 if (UTF16ToUTF8(f->GetFieldText(t)) == specifics_field)
214 return false; 214 return false;
215 f->SetInfo(AutofillType(t), UTF8ToUTF16(specifics_field)); 215 f->SetInfo(t, UTF8ToUTF16(specifics_field));
216 return true; 216 return true;
217 } 217 }
218 bool AutofillProfileModelAssociator::SyncModelHasUserCreatedNodes( 218 bool AutofillProfileModelAssociator::SyncModelHasUserCreatedNodes(
219 bool *has_nodes) { 219 bool *has_nodes) {
220 CHECK_NE(has_nodes, reinterpret_cast<bool*>(NULL)); 220 CHECK_NE(has_nodes, reinterpret_cast<bool*>(NULL));
221 sync_api::ReadTransaction trans(sync_service_->GetUserShare()); 221 sync_api::ReadTransaction trans(sync_service_->GetUserShare());
222 222
223 sync_api::ReadNode node(&trans); 223 sync_api::ReadNode node(&trans);
224 224
225 if (!node.InitByTagLookup(kAutofillProfileTag)) { 225 if (!node.InitByTagLookup(kAutofillProfileTag)) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 return false; 316 return false;
317 } 317 }
318 AutofillProfile* p = new AutofillProfile(autofill_specifics.guid()); 318 AutofillProfile* p = new AutofillProfile(autofill_specifics.guid());
319 OverwriteProfileWithServerData(p, autofill_specifics); 319 OverwriteProfileWithServerData(p, autofill_specifics);
320 new_profiles->push_back(p); 320 new_profiles->push_back(p);
321 std::string guid = autofill_specifics.guid(); 321 std::string guid = autofill_specifics.guid();
322 Associate(&guid, sync_node_id); 322 Associate(&guid, sync_node_id);
323 current_profiles->insert(autofill_specifics.guid()); 323 current_profiles->insert(autofill_specifics.guid());
324 VLOG(2) << "[AUTOFILL MIGRATION]" 324 VLOG(2) << "[AUTOFILL MIGRATION]"
325 << "Found in sync db but with a different guid: " 325 << "Found in sync db but with a different guid: "
326 << UTF16ToUTF8(profile.GetFieldText(AutofillType(NAME_FIRST))) 326 << UTF16ToUTF8(profile.GetFieldText(NAME_FIRST))
327 << UTF16ToUTF8(profile.GetFieldText(AutofillType(NAME_LAST))) 327 << UTF16ToUTF8(profile.GetFieldText(NAME_LAST))
328 << "New guid " << autofill_specifics.guid() << " sync node id " 328 << "New guid " << autofill_specifics.guid() << " sync node id "
329 << sync_node_id << " so associating. Profile to be deleted " 329 << sync_node_id << " so associating. Profile to be deleted "
330 << profile.guid(); 330 << profile.guid();
331 } else { 331 } else {
332 sync_api::WriteNode node(trans); 332 sync_api::WriteNode node(trans);
333 333
334 // The profile.guid() is expected to be a valid guid. The caller is expected 334 // The profile.guid() is expected to be a valid guid. The caller is expected
335 // to pass in a valid profile object with a valid guid. Having to check in 335 // to pass in a valid profile object with a valid guid. Having to check in
336 // 2 places(the caller and here) is not optimal. 336 // 2 places(the caller and here) is not optimal.
337 if (!node.InitUniqueByCreation( 337 if (!node.InitUniqueByCreation(
338 syncable::AUTOFILL_PROFILE, autofill_root, profile.guid())) { 338 syncable::AUTOFILL_PROFILE, autofill_root, profile.guid())) {
339 LOG(ERROR) << "Failed to create autofill sync node."; 339 LOG(ERROR) << "Failed to create autofill sync node.";
340 return false; 340 return false;
341 } 341 }
342 node.SetTitle(UTF8ToWide(profile.guid())); 342 node.SetTitle(UTF8ToWide(profile.guid()));
343 VLOG(2) << "[AUTOFILL MIGRATION]" 343 VLOG(2) << "[AUTOFILL MIGRATION]"
344 << "NOT Found in sync db " 344 << "NOT Found in sync db "
345 << UTF16ToUTF8(profile.GetFieldText(AutofillType(NAME_FIRST))) 345 << UTF16ToUTF8(profile.GetFieldText(NAME_FIRST))
346 << UTF16ToUTF8(profile.GetFieldText(AutofillType(NAME_LAST))) 346 << UTF16ToUTF8(profile.GetFieldText(NAME_LAST))
347 << profile.guid() 347 << profile.guid()
348 << " so creating a new sync node. Sync node id " 348 << " so creating a new sync node. Sync node id "
349 << node.GetId(); 349 << node.GetId();
350 AutofillProfileChangeProcessor::WriteAutofillProfile(profile, &node); 350 AutofillProfileChangeProcessor::WriteAutofillProfile(profile, &node);
351 current_profiles->insert(profile.guid()); 351 current_profiles->insert(profile.guid());
352 std::string guid = profile.guid(); 352 std::string guid = profile.guid();
353 Associate(&guid, node.GetId()); 353 Associate(&guid, node.GetId());
354 number_of_profiles_created_++; 354 number_of_profiles_created_++;
355 } 355 }
356 return true; 356 return true;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 497
498 AutofillProfileModelAssociator::DataBundle::DataBundle() {} 498 AutofillProfileModelAssociator::DataBundle::DataBundle() {}
499 499
500 AutofillProfileModelAssociator::DataBundle::~DataBundle() { 500 AutofillProfileModelAssociator::DataBundle::~DataBundle() {
501 STLDeleteElements(&new_profiles); 501 STLDeleteElements(&new_profiles);
502 } 502 }
503 503
504 504
505 } // namespace browser_sync 505 } // namespace browser_sync
506 506
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698