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

Side by Side Diff: chrome/browser/autofill/personal_data_manager.cc

Issue 2818033: AutoFill: Aggregate profile data. Remove the AutoFill InfoBar. (Closed)
Patch Set: Comment. Created 10 years, 5 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
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/autofill/personal_data_manager.h" 5 #include "chrome/browser/autofill/personal_data_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/autofill/autofill_manager.h" 12 #include "chrome/browser/autofill/autofill_manager.h"
13 #include "chrome/browser/autofill/autofill_field.h" 13 #include "chrome/browser/autofill/autofill_field.h"
14 #include "chrome/browser/autofill/form_structure.h" 14 #include "chrome/browser/autofill/form_structure.h"
15 #include "chrome/browser/autofill/phone_number.h" 15 #include "chrome/browser/autofill/phone_number.h"
16 #include "chrome/browser/chrome_thread.h" 16 #include "chrome/browser/chrome_thread.h"
17 #include "chrome/browser/profile.h" 17 #include "chrome/browser/profile.h"
18 #include "chrome/browser/webdata/web_data_service.h" 18 #include "chrome/browser/webdata/web_data_service.h"
19 #include "chrome/browser/pref_service.h" 19 #include "chrome/browser/pref_service.h"
20 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
21 21
22 namespace { 22 namespace {
23 23
24 // The minimum number of fields that must contain user data and have known types 24 // The minimum number of fields that must contain user data and have known types
25 // before autofill will attempt to import the data into a profile. 25 // before AutoFill will attempt to import the data into a profile.
26 const int kMinImportSize = 5; 26 const int kMinImportSize = 3;
27 27
28 const char kUnlabeled[] = "Unlabeled"; 28 const char kUnlabeled[] = "Unlabeled";
29 29
30 } // namespace 30 } // namespace
31 31
32 PersonalDataManager::~PersonalDataManager() { 32 PersonalDataManager::~PersonalDataManager() {
33 CancelPendingQuery(&pending_profiles_query_); 33 CancelPendingQuery(&pending_profiles_query_);
34 CancelPendingQuery(&pending_creditcards_query_); 34 CancelPendingQuery(&pending_creditcards_query_);
35 } 35 }
36 36
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 } 72 }
73 } 73 }
74 74
75 ///////////////////////////////////////////////////////////////////////////// 75 /////////////////////////////////////////////////////////////////////////////
76 // PersonalDataManager, 76 // PersonalDataManager,
77 // views::ButtonListener implementations 77 // views::ButtonListener implementations
78 void PersonalDataManager::OnAutoFillDialogApply( 78 void PersonalDataManager::OnAutoFillDialogApply(
79 std::vector<AutoFillProfile>* profiles, 79 std::vector<AutoFillProfile>* profiles,
80 std::vector<CreditCard>* credit_cards) { 80 std::vector<CreditCard>* credit_cards) {
81 // |profiles| may be NULL 81 // |profiles| may be NULL.
82 // |credit_cards| may be NULL 82 // |credit_cards| may be NULL.
83 if (profiles) { 83 if (profiles) {
84 CancelPendingQuery(&pending_profiles_query_); 84 CancelPendingQuery(&pending_profiles_query_);
85 SetProfiles(profiles); 85 SetProfiles(profiles);
86 } 86 }
87 if (credit_cards) { 87 if (credit_cards) {
88 CancelPendingQuery(&pending_creditcards_query_); 88 CancelPendingQuery(&pending_creditcards_query_);
89 SetCreditCards(credit_cards); 89 SetCreditCards(credit_cards);
90 } 90 }
91 } 91 }
92 92
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 // importing the data. 198 // importing the data.
199 if (importable_fields + importable_credit_card_fields < kMinImportSize) 199 if (importable_fields + importable_credit_card_fields < kMinImportSize)
200 return false; 200 return false;
201 201
202 if (importable_fields == 0) 202 if (importable_fields == 0)
203 imported_profile_.reset(); 203 imported_profile_.reset();
204 204
205 if (importable_credit_card_fields == 0) 205 if (importable_credit_card_fields == 0)
206 imported_credit_card_.reset(); 206 imported_credit_card_.reset();
207 207
208 {
209 // We're now done with the unique IDs, and SaveImportedProfile() needs the
210 // lock, so release it.
211 AutoUnlock unlock(unique_ids_lock_);
212
213 // We always save imported profiles.
214 SaveImportedProfile();
215 }
216
208 return true; 217 return true;
209 } 218 }
210 219
211 void PersonalDataManager::SaveImportedFormData() {
212 if (profile_->IsOffTheRecord())
213 return;
214
215 if (imported_profile_.get()) {
216 imported_profile_->set_label(ASCIIToUTF16(kUnlabeled));
217
218 std::vector<AutoFillProfile> profiles;
219 profiles.push_back(*imported_profile_);
220 SetProfiles(&profiles);
221 }
222
223 if (imported_credit_card_.get()) {
224 imported_credit_card_->set_label(ASCIIToUTF16(kUnlabeled));
225
226 std::vector<CreditCard> credit_cards;
227 credit_cards.push_back(*imported_credit_card_);
228 SetCreditCards(&credit_cards);
229 }
230 }
231
232 void PersonalDataManager::GetImportedFormData(AutoFillProfile** profile, 220 void PersonalDataManager::GetImportedFormData(AutoFillProfile** profile,
233 CreditCard** credit_card) { 221 CreditCard** credit_card) {
234 DCHECK(profile); 222 DCHECK(profile);
235 DCHECK(credit_card); 223 DCHECK(credit_card);
236 224
237 if (imported_profile_.get()) { 225 if (imported_profile_.get()) {
238 imported_profile_->set_label(ASCIIToUTF16(kUnlabeled)); 226 imported_profile_->set_label(ASCIIToUTF16(kUnlabeled));
239 } 227 }
240 *profile = imported_profile_.get(); 228 *profile = imported_profile_.get();
241 229
242 if (imported_credit_card_.get()) { 230 if (imported_credit_card_.get()) {
243 imported_credit_card_->set_label(ASCIIToUTF16(kUnlabeled)); 231 imported_credit_card_->set_label(ASCIIToUTF16(kUnlabeled));
244 } 232 }
245 *credit_card = imported_credit_card_.get(); 233 *credit_card = imported_credit_card_.get();
246 } 234 }
247 235
248 void PersonalDataManager::SetProfiles(std::vector<AutoFillProfile>* profiles) { 236 void PersonalDataManager::SetProfiles(std::vector<AutoFillProfile>* profiles) {
249 if (profile_->IsOffTheRecord()) 237 if (profile_->IsOffTheRecord())
250 return; 238 return;
251 239
252 SetUniqueProfileLabels(profiles); 240 SetUniqueProfileLabels(profiles);
253 241
254 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 242 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
255 if (!wds) 243 if (!wds)
256 return; 244 return;
257 245
258 AutoLock lock(unique_ids_lock_); 246 AutoLock lock(unique_ids_lock_);
247
259 // Remove the unique IDs of the new set of profiles from the unique ID set. 248 // Remove the unique IDs of the new set of profiles from the unique ID set.
260 for (std::vector<AutoFillProfile>::iterator iter = profiles->begin(); 249 for (std::vector<AutoFillProfile>::iterator iter = profiles->begin();
261 iter != profiles->end(); ++iter) { 250 iter != profiles->end(); ++iter) {
262 if (iter->unique_id() != 0) 251 if (iter->unique_id() != 0)
263 unique_profile_ids_.erase(iter->unique_id()); 252 unique_profile_ids_.erase(iter->unique_id());
264 } 253 }
265 254
266 // Any remaining IDs are not in the new profile list and should be removed 255 // Any remaining IDs are not in the new profile list and should be removed
267 // from the web database. 256 // from the web database.
268 for (std::set<int>::iterator iter = unique_profile_ids_.begin(); 257 for (std::set<int>::iterator iter = unique_profile_ids_.begin();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 if (profile_->IsOffTheRecord()) 302 if (profile_->IsOffTheRecord())
314 return; 303 return;
315 304
316 SetUniqueCreditCardLabels(credit_cards); 305 SetUniqueCreditCardLabels(credit_cards);
317 306
318 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 307 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
319 if (!wds) 308 if (!wds)
320 return; 309 return;
321 310
322 AutoLock lock(unique_ids_lock_); 311 AutoLock lock(unique_ids_lock_);
312
323 // Remove the unique IDs of the new set of credit cards from the unique ID 313 // Remove the unique IDs of the new set of credit cards from the unique ID
324 // set. 314 // set.
325 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); 315 for (std::vector<CreditCard>::iterator iter = credit_cards->begin();
326 iter != credit_cards->end(); ++iter) { 316 iter != credit_cards->end(); ++iter) {
327 if (iter->unique_id() != 0) 317 if (iter->unique_id() != 0)
328 unique_creditcard_ids_.erase(iter->unique_id()); 318 unique_creditcard_ids_.erase(iter->unique_id());
329 } 319 }
330 320
331 // Any remaining IDs are not in the new credit card list and should be removed 321 // Any remaining IDs are not in the new credit card list and should be removed
332 // from the web database. 322 // from the web database.
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 // Start at the second element because the first label should not be 586 // Start at the second element because the first label should not be
597 // renamed. The appended label number starts at 2, because the first label 587 // renamed. The appended label number starts at 2, because the first label
598 // has an implicit index of 1. 588 // has an implicit index of 1.
599 for (size_t i = 1; i < iter->second.size(); ++i) { 589 for (size_t i = 1; i < iter->second.size(); ++i) {
600 string16 newlabel = iter->second[i]->Label() + 590 string16 newlabel = iter->second[i]->Label() +
601 UintToString16(static_cast<unsigned int>(i + 1)); 591 UintToString16(static_cast<unsigned int>(i + 1));
602 iter->second[i]->set_label(newlabel); 592 iter->second[i]->set_label(newlabel);
603 } 593 }
604 } 594 }
605 } 595 }
596
597 void PersonalDataManager::SaveImportedProfile() {
598 if (profile_->IsOffTheRecord())
599 return;
600
601 if (!imported_profile_.get())
602 return;
603
604 // Set to true if |imported_profile_| is merged into the profile list.
605 bool merged = false;
606
607 imported_profile_->set_label(ASCIIToUTF16(kUnlabeled));
608
609 // Don't save a web profile if the data in the profile is a subset of an
610 // auxiliary profile.
611 for (std::vector<AutoFillProfile*>::const_iterator iter =
612 auxiliary_profiles_.begin();
613 iter != auxiliary_profiles_.end(); ++iter) {
614 if (imported_profile_->IsSubsetOf(**iter))
615 return;
616 }
617
618 std::vector<AutoFillProfile> profiles;
619 for (std::vector<AutoFillProfile*>::const_iterator iter =
620 web_profiles_.begin();
621 iter != web_profiles_.end(); ++iter) {
622 if (imported_profile_->IsSubsetOf(**iter)) {
623 // In this case, the existing profile already contains all of the data
624 // in |imported_profile|, so consider the profiles already merged.
625 merged = true;
626 } else if ((*iter)->IntersectionOfTypesHasEqualValues(
627 *imported_profile_)) {
628 // |imported_profile| contains all of the data in this profile, plus
629 // more.
630 merged = true;
631 (*iter)->MergeWith(*imported_profile_);
632 }
633
634 profiles.push_back(**iter);
635 }
636
637 if (!merged)
638 profiles.push_back(*imported_profile_);
639
640 SetProfiles(&profiles);
641 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/personal_data_manager.h ('k') | chrome/browser/autofill/personal_data_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698