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

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

Issue 3140026: DOMUI: Implement the 'Remove...' button on the AutoFill page. (Closed)
Patch Set: DOMUI fixes. Created 10 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
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"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 22
23 namespace { 23 namespace {
24 24
25 // The minimum number of fields that must contain user data and have known types 25 // The minimum number of fields that must contain user data and have known types
26 // before AutoFill will attempt to import the data into a profile. 26 // before AutoFill will attempt to import the data into a profile.
27 const int kMinImportSize = 3; 27 const int kMinImportSize = 3;
28 28
29 const char kUnlabeled[] = "Unlabeled"; 29 const char kUnlabeled[] = "Unlabeled";
30 30
31 template<typename T>
32 class FormGroupIDMatchesFunctor {
33 public:
34 explicit FormGroupIDMatchesFunctor(int id) : id_(id) {}
35
36 bool operator()(const T& form_group) {
37 return form_group.unique_id() == id_;
38 }
39
40 private:
41 int id_;
42 };
43
44 template<typename T>
45 class DereferenceFunctor {
46 public:
47 template<typename T_Iterator>
48 const T& operator()(const T_Iterator& iterator) {
49 return *iterator;
50 }
51 };
52
31 } // namespace 53 } // namespace
32 54
33 PersonalDataManager::~PersonalDataManager() { 55 PersonalDataManager::~PersonalDataManager() {
34 CancelPendingQuery(&pending_profiles_query_); 56 CancelPendingQuery(&pending_profiles_query_);
35 CancelPendingQuery(&pending_creditcards_query_); 57 CancelPendingQuery(&pending_creditcards_query_);
36 } 58 }
37 59
38 void PersonalDataManager::OnWebDataServiceRequestDone( 60 void PersonalDataManager::OnWebDataServiceRequestDone(
39 WebDataService::Handle h, 61 WebDataService::Handle h,
40 const WDTypedResult* result) { 62 const WDTypedResult* result) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 CancelPendingQuery(&pending_profiles_query_); 98 CancelPendingQuery(&pending_profiles_query_);
77 SetProfiles(profiles); 99 SetProfiles(profiles);
78 } 100 }
79 if (credit_cards) { 101 if (credit_cards) {
80 CancelPendingQuery(&pending_creditcards_query_); 102 CancelPendingQuery(&pending_creditcards_query_);
81 SetCreditCards(credit_cards); 103 SetCreditCards(credit_cards);
82 } 104 }
83 } 105 }
84 106
85 void PersonalDataManager::SetObserver(PersonalDataManager::Observer* observer) { 107 void PersonalDataManager::SetObserver(PersonalDataManager::Observer* observer) {
86 // TODO: RemoveObserver is for compatability with old code, it should be 108 // TODO: RemoveObserver is for compatibility with old code, it should be
87 // nuked. 109 // nuked.
88 observers_.RemoveObserver(observer); 110 observers_.RemoveObserver(observer);
89 observers_.AddObserver(observer); 111 observers_.AddObserver(observer);
90 } 112 }
91 113
92 void PersonalDataManager::RemoveObserver( 114 void PersonalDataManager::RemoveObserver(
93 PersonalDataManager::Observer* observer) { 115 PersonalDataManager::Observer* observer) {
94 observers_.RemoveObserver(observer); 116 observers_.RemoveObserver(observer);
95 } 117 }
96 118
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 379
358 credit_cards_.reset(); 380 credit_cards_.reset();
359 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); 381 for (std::vector<CreditCard>::iterator iter = credit_cards->begin();
360 iter != credit_cards->end(); ++iter) { 382 iter != credit_cards->end(); ++iter) {
361 credit_cards_.push_back(new CreditCard(*iter)); 383 credit_cards_.push_back(new CreditCard(*iter));
362 } 384 }
363 385
364 FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataChanged()); 386 FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataChanged());
365 } 387 }
366 388
389 void PersonalDataManager::RemoveProfile(int unique_id) {
390 // TODO(jhawkins): Refactor SetProfiles so this isn't so hacky.
391 std::vector<AutoFillProfile> profiles(web_profiles_.size());
392 std::transform(web_profiles_.begin(), web_profiles_.end(),
393 profiles.begin(),
394 DereferenceFunctor<AutoFillProfile>());
395
396 // Remove the profile that matches |unique_id|.
397 profiles.erase(
398 std::remove_if(profiles.begin(), profiles.end(),
399 FormGroupIDMatchesFunctor<AutoFillProfile>(unique_id)),
400 profiles.end());
401
402 SetProfiles(&profiles);
403 }
404
405 void PersonalDataManager::RemoveCreditCard(int unique_id) {
406 // TODO(jhawkins): Refactor SetCreditCards so this isn't so hacky.
407 std::vector<CreditCard> credit_cards(credit_cards_.size());
408 std::transform(credit_cards_.begin(), credit_cards_.end(),
409 credit_cards.begin(),
410 DereferenceFunctor<CreditCard>());
411
412 // Remove the credit card that matches |unique_id|.
413 credit_cards.erase(
414 std::remove_if(credit_cards.begin(), credit_cards.end(),
415 FormGroupIDMatchesFunctor<CreditCard>(unique_id)),
416 credit_cards.end());
417
418 SetCreditCards(&credit_cards);
419 }
420
367 void PersonalDataManager::GetPossibleFieldTypes(const string16& text, 421 void PersonalDataManager::GetPossibleFieldTypes(const string16& text,
368 FieldTypeSet* possible_types) { 422 FieldTypeSet* possible_types) {
369 string16 clean_info = StringToLowerASCII(CollapseWhitespace(text, false)); 423 string16 clean_info = StringToLowerASCII(CollapseWhitespace(text, false));
370 if (clean_info.empty()) { 424 if (clean_info.empty()) {
371 possible_types->insert(EMPTY_TYPE); 425 possible_types->insert(EMPTY_TYPE);
372 return; 426 return;
373 } 427 }
374 428
375 for (ScopedVector<AutoFillProfile>::iterator iter = web_profiles_.begin(); 429 for (ScopedVector<AutoFillProfile>::iterator iter = web_profiles_.begin();
376 iter != web_profiles_.end(); ++iter) { 430 iter != web_profiles_.end(); ++iter) {
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 } 738 }
685 739
686 creditcards.push_back(**iter); 740 creditcards.push_back(**iter);
687 } 741 }
688 742
689 if (!merged) 743 if (!merged)
690 creditcards.push_back(*imported_credit_card_); 744 creditcards.push_back(*imported_credit_card_);
691 745
692 SetCreditCards(&creditcards); 746 SetCreditCards(&creditcards);
693 } 747 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/personal_data_manager.h ('k') | chrome/browser/dom_ui/autofill_options_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698