Chromium Code Reviews

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

Issue 2975003: Makes the auto fill dialogs match the mocks. (Closed)
Patch Set: Moves function declarations out of autofill_dialog.h Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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 41 matching lines...)
52 case AUTOFILL_CREDITCARDS_RESULT: 52 case AUTOFILL_CREDITCARDS_RESULT:
53 ReceiveLoadedCreditCards(h, result); 53 ReceiveLoadedCreditCards(h, result);
54 break; 54 break;
55 default: 55 default:
56 NOTREACHED(); 56 NOTREACHED();
57 } 57 }
58 58
59 // If both requests have responded, then all personal data is loaded. 59 // If both requests have responded, then all personal data is loaded.
60 if (pending_profiles_query_ == 0 && pending_creditcards_query_ == 0) { 60 if (pending_profiles_query_ == 0 && pending_creditcards_query_ == 0) {
61 is_data_loaded_ = true; 61 is_data_loaded_ = true;
62 // Copy is needed as observer can unsubscribe itself when notified. 62 FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataLoaded());
63 std::vector<PersonalDataManager::Observer*> temporary_copy;
64 temporary_copy.resize(observers_.size());
65 std::copy(observers_.begin(), observers_.end(), temporary_copy.begin());
66 for (std::vector<PersonalDataManager::Observer*>::iterator
67 iter = temporary_copy.begin();
68 iter != temporary_copy.end();
69 ++iter) {
70 (*iter)->OnPersonalDataLoaded();
71 }
72 } 63 }
73 } 64 }
74 65
75 ///////////////////////////////////////////////////////////////////////////// 66 /////////////////////////////////////////////////////////////////////////////
76 // PersonalDataManager, 67 // PersonalDataManager,
77 // views::ButtonListener implementations 68 // views::ButtonListener implementations
78 void PersonalDataManager::OnAutoFillDialogApply( 69 void PersonalDataManager::OnAutoFillDialogApply(
79 std::vector<AutoFillProfile>* profiles, 70 std::vector<AutoFillProfile>* profiles,
80 std::vector<CreditCard>* credit_cards) { 71 std::vector<CreditCard>* credit_cards) {
81 // |profiles| may be NULL. 72 // |profiles| may be NULL.
82 // |credit_cards| may be NULL. 73 // |credit_cards| may be NULL.
83 if (profiles) { 74 if (profiles) {
84 CancelPendingQuery(&pending_profiles_query_); 75 CancelPendingQuery(&pending_profiles_query_);
85 SetProfiles(profiles); 76 SetProfiles(profiles);
86 } 77 }
87 if (credit_cards) { 78 if (credit_cards) {
88 CancelPendingQuery(&pending_creditcards_query_); 79 CancelPendingQuery(&pending_creditcards_query_);
89 SetCreditCards(credit_cards); 80 SetCreditCards(credit_cards);
90 } 81 }
91 } 82 }
92 83
93 void PersonalDataManager::SetObserver(PersonalDataManager::Observer* observer) { 84 void PersonalDataManager::SetObserver(PersonalDataManager::Observer* observer) {
94 for (std::vector<PersonalDataManager::Observer*>::iterator 85 // TODO: RemoveObserver is for compatability with old code, it should be
95 iter = observers_.begin(); 86 // nuked.
96 iter != observers_.end(); 87 observers_.RemoveObserver(observer);
97 ++iter) { 88 observers_.AddObserver(observer);
98 if (*iter == observer) {
99 // Already have this observer.
100 return;
101 }
102 }
103 observers_.push_back(observer);
104 } 89 }
105 90
106 void PersonalDataManager::RemoveObserver( 91 void PersonalDataManager::RemoveObserver(
107 PersonalDataManager::Observer* observer) { 92 PersonalDataManager::Observer* observer) {
108 for (std::vector<PersonalDataManager::Observer*>::iterator 93 observers_.RemoveObserver(observer);
109 iter = observers_.begin();
110 iter != observers_.end();
111 ++iter) {
112 if (*iter == observer) {
113 observers_.erase(iter);
114 return;
115 }
116 }
117 } 94 }
118 95
119 bool PersonalDataManager::ImportFormData( 96 bool PersonalDataManager::ImportFormData(
120 const std::vector<FormStructure*>& form_structures, 97 const std::vector<FormStructure*>& form_structures,
121 AutoFillManager* autofill_manager) { 98 AutoFillManager* autofill_manager) {
122 AutoLock lock(unique_ids_lock_); 99 AutoLock lock(unique_ids_lock_);
123 // Parse the form and construct a profile based on the information that is 100 // Parse the form and construct a profile based on the information that is
124 // possible to import. 101 // possible to import.
125 int importable_fields = 0; 102 int importable_fields = 0;
126 int importable_credit_card_fields = 0; 103 int importable_credit_card_fields = 0;
(...skipping 164 matching lines...)
291 } 268 }
292 269
293 web_profiles_.reset(); 270 web_profiles_.reset();
294 for (std::vector<AutoFillProfile>::iterator iter = profiles->begin(); 271 for (std::vector<AutoFillProfile>::iterator iter = profiles->begin();
295 iter != profiles->end(); ++iter) { 272 iter != profiles->end(); ++iter) {
296 web_profiles_.push_back(new AutoFillProfile(*iter)); 273 web_profiles_.push_back(new AutoFillProfile(*iter));
297 } 274 }
298 275
299 // Read our writes to ensure consistency with the database. 276 // Read our writes to ensure consistency with the database.
300 Refresh(); 277 Refresh();
278
279 FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataChanged());
301 } 280 }
302 281
303 void PersonalDataManager::SetCreditCards( 282 void PersonalDataManager::SetCreditCards(
304 std::vector<CreditCard>* credit_cards) { 283 std::vector<CreditCard>* credit_cards) {
305 if (profile_->IsOffTheRecord()) 284 if (profile_->IsOffTheRecord())
306 return; 285 return;
307 286
308 SetUniqueCreditCardLabels(credit_cards); 287 SetUniqueCreditCardLabels(credit_cards);
309 288
310 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 289 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
(...skipping 43 matching lines...)
354 iter->set_unique_id(CreateNextUniqueID(&unique_creditcard_ids_)); 333 iter->set_unique_id(CreateNextUniqueID(&unique_creditcard_ids_));
355 wds->AddCreditCard(*iter); 334 wds->AddCreditCard(*iter);
356 } 335 }
357 } 336 }
358 337
359 credit_cards_.reset(); 338 credit_cards_.reset();
360 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); 339 for (std::vector<CreditCard>::iterator iter = credit_cards->begin();
361 iter != credit_cards->end(); ++iter) { 340 iter != credit_cards->end(); ++iter) {
362 credit_cards_.push_back(new CreditCard(*iter)); 341 credit_cards_.push_back(new CreditCard(*iter));
363 } 342 }
343
344 FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataChanged());
364 } 345 }
365 346
366 void PersonalDataManager::GetPossibleFieldTypes(const string16& text, 347 void PersonalDataManager::GetPossibleFieldTypes(const string16& text,
367 FieldTypeSet* possible_types) { 348 FieldTypeSet* possible_types) {
368 string16 clean_info = StringToLowerASCII(CollapseWhitespace(text, false)); 349 string16 clean_info = StringToLowerASCII(CollapseWhitespace(text, false));
369 if (clean_info.empty()) { 350 if (clean_info.empty()) {
370 possible_types->insert(EMPTY_TYPE); 351 possible_types->insert(EMPTY_TYPE);
371 return; 352 return;
372 } 353 }
373 354
(...skipping 271 matching lines...)
645 626
646 if (!merged) 627 if (!merged)
647 profiles.push_back(*imported_profile_); 628 profiles.push_back(*imported_profile_);
648 629
649 SetProfiles(&profiles); 630 SetProfiles(&profiles);
650 } 631 }
651 632
652 void PersonalDataManager::SaveImportedCreditCard() { 633 void PersonalDataManager::SaveImportedCreditCard() {
653 // http://crbug.com/47428 634 // http://crbug.com/47428
654 } 635 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/personal_data_manager.h ('k') | chrome/browser/gtk/keyword_editor_view.h » ('j') | no next file with comments »

Powered by Google App Engine