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

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

Issue 10908065: Introduce a couple of abstract bases for WebDataService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/autofill/autofill-inl.h" 13 #include "chrome/browser/autofill/autofill-inl.h"
14 #include "chrome/browser/autofill/autofill_field.h" 14 #include "chrome/browser/autofill/autofill_field.h"
15 #include "chrome/browser/autofill/autofill_metrics.h" 15 #include "chrome/browser/autofill/autofill_metrics.h"
16 #include "chrome/browser/autofill/autofill_regexes.h" 16 #include "chrome/browser/autofill/autofill_regexes.h"
17 #include "chrome/browser/autofill/form_structure.h" 17 #include "chrome/browser/autofill/form_structure.h"
18 #include "chrome/browser/autofill/personal_data_manager_observer.h" 18 #include "chrome/browser/autofill/personal_data_manager_observer.h"
19 #include "chrome/browser/autofill/phone_number.h" 19 #include "chrome/browser/autofill/phone_number.h"
20 #include "chrome/browser/autofill/phone_number_i18n.h" 20 #include "chrome/browser/autofill/phone_number_i18n.h"
21 #include "chrome/browser/autofill/select_control_handler.h" 21 #include "chrome/browser/autofill/select_control_handler.h"
22 #include "chrome/browser/api/prefs/pref_service_base.h" 22 #include "chrome/browser/api/prefs/pref_service_base.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/sync/profile_sync_service.h" 24 #include "chrome/browser/sync/profile_sync_service.h"
25 #include "chrome/browser/sync/profile_sync_service_factory.h" 25 #include "chrome/browser/sync/profile_sync_service_factory.h"
26 #include "chrome/browser/webdata/autofill_entry.h"
27 #include "chrome/browser/webdata/web_data_service.h"
28 #include "chrome/browser/webdata/web_data_service_factory.h"
29 #include "chrome/common/chrome_notification_types.h" 26 #include "chrome/common/chrome_notification_types.h"
30 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
31 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/notification_source.h" 29 #include "content/public/browser/notification_source.h"
33 30
34 namespace { 31 namespace {
35 32
36 template<typename T> 33 template<typename T>
37 class FormGroupMatchesByGUIDFunctor { 34 class FormGroupMatchesByGUIDFunctor {
38 public: 35 public:
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 117 }
121 118
122 } // namespace 119 } // namespace
123 120
124 PersonalDataManager::~PersonalDataManager() { 121 PersonalDataManager::~PersonalDataManager() {
125 CancelPendingQuery(&pending_profiles_query_); 122 CancelPendingQuery(&pending_profiles_query_);
126 CancelPendingQuery(&pending_creditcards_query_); 123 CancelPendingQuery(&pending_creditcards_query_);
127 } 124 }
128 125
129 void PersonalDataManager::OnWebDataServiceRequestDone( 126 void PersonalDataManager::OnWebDataServiceRequestDone(
130 WebDataService::Handle h, 127 WebDataServiceBase::Handle h,
131 const WDTypedResult* result) { 128 const WDTypedResult* result) {
132 DCHECK(pending_profiles_query_ || pending_creditcards_query_); 129 DCHECK(pending_profiles_query_ || pending_creditcards_query_);
133 130
134 if (!result) { 131 if (!result) {
135 // Error from the web database. 132 // Error from the web database.
136 if (h == pending_creditcards_query_) 133 if (h == pending_creditcards_query_)
137 pending_creditcards_query_ = 0; 134 pending_creditcards_query_ = 0;
138 else if (h == pending_profiles_query_) 135 else if (h == pending_profiles_query_)
139 pending_profiles_query_ = 0; 136 pending_profiles_query_ = 0;
140 return; 137 return;
(...skipping 24 matching lines...) Expand all
165 OnPersonalDataChanged()); 162 OnPersonalDataChanged());
166 163
167 // As all Autofill data is ready, the Autocomplete data is ready as well. 164 // As all Autofill data is ready, the Autocomplete data is ready as well.
168 // If sync is not set, cull older entries of the autocomplete. Otherwise, 165 // If sync is not set, cull older entries of the autocomplete. Otherwise,
169 // the entries will be culled when sync is connected. 166 // the entries will be culled when sync is connected.
170 ProfileSyncService* sync_service = 167 ProfileSyncService* sync_service =
171 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); 168 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_);
172 if (sync_service && (!sync_service->HasSyncSetupCompleted() || 169 if (sync_service && (!sync_service->HasSyncSetupCompleted() ||
173 !PrefServiceBase::ForProfile(profile_)->GetBoolean( 170 !PrefServiceBase::ForProfile(profile_)->GetBoolean(
174 prefs::kSyncAutofill))) { 171 prefs::kSyncAutofill))) {
175 scoped_refptr<WebDataService> web_data_service = 172 scoped_ref<AutofillWebDataService> service =
176 WebDataServiceFactory::GetForProfile(profile_, 173 AutofillWebDataService::ForContext(profile_);
177 Profile::EXPLICIT_ACCESS); 174 if (service)
178 if (web_data_service) 175 service->RemoveExpiredFormElements();
179 web_data_service->RemoveExpiredFormElements();
180 } 176 }
181 } 177 }
182 } 178 }
183 179
184 void PersonalDataManager::SetObserver(PersonalDataManagerObserver* observer) { 180 void PersonalDataManager::SetObserver(PersonalDataManagerObserver* observer) {
185 // TODO(dhollowa): RemoveObserver is for compatibility with old code, it 181 // TODO(dhollowa): RemoveObserver is for compatibility with old code, it
186 // should be nuked. 182 // should be nuked.
187 observers_.RemoveObserver(observer); 183 observers_.RemoveObserver(observer);
188 observers_.AddObserver(observer); 184 observers_.AddObserver(observer);
189 } 185 }
190 186
191 void PersonalDataManager::RemoveObserver( 187 void PersonalDataManager::RemoveObserver(
192 PersonalDataManagerObserver* observer) { 188 PersonalDataManagerObserver* observer) {
193 observers_.RemoveObserver(observer); 189 observers_.RemoveObserver(observer);
194 } 190 }
195 191
196 // The |PersonalDataManager| is set up as a listener of the sync service in 192 // The |PersonalDataManager| is set up as a listener of the sync service in
197 // |EmptyMigrationTrash| in the case where sync is not yet ready to receive 193 // |EmptyMigrationTrash| in the case where sync is not yet ready to receive
198 // changes. This method, |OnStateChange| acts as a deferred call to 194 // changes. This method, |OnStateChange| acts as a deferred call to
199 // |EmptyMigrationTrash| once the sync service becomes available. 195 // |EmptyMigrationTrash| once the sync service becomes available.
200 void PersonalDataManager::OnStateChanged() { 196 void PersonalDataManager::OnStateChanged() {
201 if (!profile_ || profile_->IsOffTheRecord()) 197 if (!profile_ || profile_->IsOffTheRecord())
202 return; 198 return;
203 199
204 scoped_refptr<WebDataService> web_data_service = 200 scoped_ptr<AutofillWebDataService> autofill_data =
dhollowa 2012/09/07 16:04:01 |service| or |data_service|? And elsewhere.
205 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 201 AutofillWebDataService::ForContext(profile_);
206 if (!web_data_service.get()) { 202 if (!autofill_data.get()) {
207 NOTREACHED(); 203 NOTREACHED();
208 return; 204 return;
209 } 205 }
210 206
211 ProfileSyncService* sync_service = 207 ProfileSyncService* sync_service =
212 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); 208 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_);
213 if (!sync_service) 209 if (!sync_service)
214 return; 210 return;
215 211
216 if (sync_service->ShouldPushChanges()) { 212 if (sync_service->ShouldPushChanges()) {
217 web_data_service->EmptyMigrationTrash(true); 213 autofill_data->EmptyMigrationTrash(true);
218 sync_service->RemoveObserver(this); 214 sync_service->RemoveObserver(this);
219 } 215 }
220 } 216 }
221 217
222 void PersonalDataManager::Shutdown() { 218 void PersonalDataManager::Shutdown() {
223 CancelPendingQuery(&pending_profiles_query_); 219 CancelPendingQuery(&pending_profiles_query_);
224 CancelPendingQuery(&pending_creditcards_query_); 220 CancelPendingQuery(&pending_creditcards_query_);
225 notification_registrar_.RemoveAll(); 221 notification_registrar_.RemoveAll();
226 } 222 }
227 223
228 void PersonalDataManager::Observe(int type, 224 void PersonalDataManager::Observe(int type,
229 const content::NotificationSource& source, 225 const content::NotificationSource& source,
230 const content::NotificationDetails& details) { 226 const content::NotificationDetails& details) {
231 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED); 227 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED);
232 scoped_refptr<WebDataService> web_data_service =
233 content::Source<WebDataService>(source).ptr();
234 228
235 DCHECK(web_data_service.get() && 229 scoped_refptr<WebDataServiceBase> notification_source =
236 web_data_service.get() == WebDataServiceFactory::GetForProfile( 230 content::Source<WebDataServiceBase>(source).ptr();
237 profile_, Profile::EXPLICIT_ACCESS).get()); 231
232 DCHECK(autofill_data_.get() &&
dhollowa 2012/09/07 16:04:01 Compile error with |autofill_data_|?
233 autofill_data_->NotificationSource() == notification_source);
238 Refresh(); 234 Refresh();
239 } 235 }
240 236
241 bool PersonalDataManager::ImportFormData( 237 bool PersonalDataManager::ImportFormData(
242 const FormStructure& form, 238 const FormStructure& form,
243 const CreditCard** imported_credit_card) { 239 const CreditCard** imported_credit_card) {
244 scoped_ptr<AutofillProfile> imported_profile(new AutofillProfile); 240 scoped_ptr<AutofillProfile> imported_profile(new AutofillProfile);
245 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard); 241 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard);
246 242
247 // Parse the form and construct a profile based on the information that is 243 // Parse the form and construct a profile based on the information that is
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 if (profile_->IsOffTheRecord()) 356 if (profile_->IsOffTheRecord())
361 return; 357 return;
362 358
363 if (profile.IsEmpty()) 359 if (profile.IsEmpty())
364 return; 360 return;
365 361
366 // Don't add an existing profile. 362 // Don't add an existing profile.
367 if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) 363 if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid()))
368 return; 364 return;
369 365
370 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( 366 scoped_ptr<AutofillWebDataService> autofill_data =
371 profile_, Profile::EXPLICIT_ACCESS); 367 AutofillWebDataService::ForContext(profile_);
372 if (!wds.get()) 368 if (!autofill_data.get())
373 return; 369 return;
374 370
375 // Don't add a duplicate. 371 // Don't add a duplicate.
376 if (FindByContents(web_profiles_, profile)) 372 if (FindByContents(web_profiles_, profile))
377 return; 373 return;
378 374
379 // Add the new profile to the web database. 375 // Add the new profile to the web database.
380 wds->AddAutofillProfile(profile); 376 autofill_data->AddAutofillProfile(profile);
381 377
382 // Refresh our local cache and send notifications to observers. 378 // Refresh our local cache and send notifications to observers.
383 Refresh(); 379 Refresh();
384 } 380 }
385 381
386 void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) { 382 void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) {
387 if (profile_->IsOffTheRecord()) 383 if (profile_->IsOffTheRecord())
388 return; 384 return;
389 385
390 if (!FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) 386 if (!FindByGUID<AutofillProfile>(web_profiles_, profile.guid()))
391 return; 387 return;
392 388
393 if (profile.IsEmpty()) { 389 if (profile.IsEmpty()) {
394 RemoveProfile(profile.guid()); 390 RemoveProfile(profile.guid());
395 return; 391 return;
396 } 392 }
397 393
398 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( 394 scoped_ptr<AutofillWebDataService> autofill_data =
399 profile_, Profile::EXPLICIT_ACCESS); 395 AutofillWebDataService::ForContext(profile_);
400 if (!wds.get()) 396 if (!autofill_data.get())
401 return; 397 return;
402 398
403 // Make the update. 399 // Make the update.
404 wds->UpdateAutofillProfile(profile); 400 autofill_data->UpdateAutofillProfile(profile);
405 401
406 // Refresh our local cache and send notifications to observers. 402 // Refresh our local cache and send notifications to observers.
407 Refresh(); 403 Refresh();
408 } 404 }
409 405
410 void PersonalDataManager::RemoveProfile(const std::string& guid) { 406 void PersonalDataManager::RemoveProfile(const std::string& guid) {
411 if (profile_->IsOffTheRecord()) 407 if (profile_->IsOffTheRecord())
412 return; 408 return;
413 409
414 if (!FindByGUID<AutofillProfile>(web_profiles_, guid)) 410 if (!FindByGUID<AutofillProfile>(web_profiles_, guid))
415 return; 411 return;
416 412
417 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( 413 scoped_ptr<AutofillWebDataService> autofill_data =
418 profile_, Profile::EXPLICIT_ACCESS); 414 AutofillWebDataService::ForContext(profile_);
419 if (!wds.get()) 415 if (!autofill_data.get())
420 return; 416 return;
421 417
422 // Remove the profile. 418 // Remove the profile.
423 wds->RemoveAutofillProfile(guid); 419 autofill_data->RemoveAutofillProfile(guid);
424 420
425 // Refresh our local cache and send notifications to observers. 421 // Refresh our local cache and send notifications to observers.
426 Refresh(); 422 Refresh();
427 } 423 }
428 424
429 AutofillProfile* PersonalDataManager::GetProfileByGUID( 425 AutofillProfile* PersonalDataManager::GetProfileByGUID(
430 const std::string& guid) { 426 const std::string& guid) {
431 for (std::vector<AutofillProfile*>::iterator iter = web_profiles_.begin(); 427 for (std::vector<AutofillProfile*>::iterator iter = web_profiles_.begin();
432 iter != web_profiles_.end(); ++iter) { 428 iter != web_profiles_.end(); ++iter) {
433 if ((*iter)->guid() == guid) 429 if ((*iter)->guid() == guid)
434 return *iter; 430 return *iter;
435 } 431 }
436 return NULL; 432 return NULL;
437 } 433 }
438 434
439 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) { 435 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) {
440 if (profile_->IsOffTheRecord()) 436 if (profile_->IsOffTheRecord())
441 return; 437 return;
442 438
443 if (credit_card.IsEmpty()) 439 if (credit_card.IsEmpty())
444 return; 440 return;
445 441
446 if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) 442 if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid()))
447 return; 443 return;
448 444
449 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( 445 scoped_ptr<AutofillWebDataService> autofill_data =
450 profile_, Profile::EXPLICIT_ACCESS); 446 AutofillWebDataService::ForContext(profile_);
451 if (!wds.get()) 447 if (!autofill_data.get())
452 return; 448 return;
453 449
454 // Don't add a duplicate. 450 // Don't add a duplicate.
455 if (FindByContents(credit_cards_, credit_card)) 451 if (FindByContents(credit_cards_, credit_card))
456 return; 452 return;
457 453
458 // Add the new credit card to the web database. 454 // Add the new credit card to the web database.
459 wds->AddCreditCard(credit_card); 455 autofill_data->AddCreditCard(credit_card);
460 456
461 // Refresh our local cache and send notifications to observers. 457 // Refresh our local cache and send notifications to observers.
462 Refresh(); 458 Refresh();
463 } 459 }
464 460
465 void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { 461 void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) {
466 if (profile_->IsOffTheRecord()) 462 if (profile_->IsOffTheRecord())
467 return; 463 return;
468 464
469 if (!FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) 465 if (!FindByGUID<CreditCard>(credit_cards_, credit_card.guid()))
470 return; 466 return;
471 467
472 if (credit_card.IsEmpty()) { 468 if (credit_card.IsEmpty()) {
473 RemoveCreditCard(credit_card.guid()); 469 RemoveCreditCard(credit_card.guid());
474 return; 470 return;
475 } 471 }
476 472
477 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( 473 scoped_ptr<AutofillWebDataService> autofill_data =
478 profile_, Profile::EXPLICIT_ACCESS); 474 AutofillWebDataService::ForContext(profile_);
479 if (!wds.get()) 475 if (!autofill_data.get())
480 return; 476 return;
481 477
482 // Make the update. 478 // Make the update.
483 wds->UpdateCreditCard(credit_card); 479 autofill_data->UpdateCreditCard(credit_card);
484 480
485 // Refresh our local cache and send notifications to observers. 481 // Refresh our local cache and send notifications to observers.
486 Refresh(); 482 Refresh();
487 } 483 }
488 484
489 void PersonalDataManager::RemoveCreditCard(const std::string& guid) { 485 void PersonalDataManager::RemoveCreditCard(const std::string& guid) {
490 if (profile_->IsOffTheRecord()) 486 if (profile_->IsOffTheRecord())
491 return; 487 return;
492 488
493 if (!FindByGUID<CreditCard>(credit_cards_, guid)) 489 if (!FindByGUID<CreditCard>(credit_cards_, guid))
494 return; 490 return;
495 491
496 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( 492 scoped_ptr<AutofillWebDataService> autofill_data =
497 profile_, Profile::EXPLICIT_ACCESS); 493 AutofillWebDataService::ForContext(profile_);
498 if (!wds.get()) 494 if (!autofill_data.get())
499 return; 495 return;
500 496
501 // Remove the credit card. 497 // Remove the credit card.
502 wds->RemoveCreditCard(guid); 498 autofill_data->RemoveCreditCard(guid);
503 499
504 // Refresh our local cache and send notifications to observers. 500 // Refresh our local cache and send notifications to observers.
505 Refresh(); 501 Refresh();
506 } 502 }
507 503
508 CreditCard* PersonalDataManager::GetCreditCardByGUID(const std::string& guid) { 504 CreditCard* PersonalDataManager::GetCreditCardByGUID(const std::string& guid) {
509 for (std::vector<CreditCard*>::iterator iter = credit_cards_.begin(); 505 for (std::vector<CreditCard*>::iterator iter = credit_cards_.begin();
510 iter != credit_cards_.end(); ++iter) { 506 iter != credit_cards_.end(); ++iter) {
511 if ((*iter)->guid() == guid) 507 if ((*iter)->guid() == guid)
512 return *iter; 508 return *iter;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 pending_creditcards_query_(0), 572 pending_creditcards_query_(0),
577 metric_logger_(new AutofillMetrics), 573 metric_logger_(new AutofillMetrics),
578 has_logged_profile_count_(false) { 574 has_logged_profile_count_(false) {
579 } 575 }
580 576
581 void PersonalDataManager::Init(Profile* profile) { 577 void PersonalDataManager::Init(Profile* profile) {
582 profile_ = profile; 578 profile_ = profile;
583 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); 579 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled());
584 580
585 // WebDataService may not be available in tests. 581 // WebDataService may not be available in tests.
586 scoped_refptr<WebDataService> web_data_service = 582 scoped_ptr<AutofillWebDataService> autofill_data =
587 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 583 AutofillWebDataService::ForContext(profile_);
588 if (!web_data_service.get()) 584 if (!autofill_data.get())
589 return; 585 return;
590 586
591 LoadProfiles(); 587 LoadProfiles();
592 LoadCreditCards(); 588 LoadCreditCards();
593 589
590 // TODO(joi): How to handle?
594 notification_registrar_.Add( 591 notification_registrar_.Add(
595 this, 592 this,
596 chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED, 593 chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED,
597 content::Source<WebDataService>(web_data_service)); 594 content::Source<WebDataServiceBase>(web_data_service));
598 } 595 }
599 596
600 bool PersonalDataManager::IsAutofillEnabled() const { 597 bool PersonalDataManager::IsAutofillEnabled() const {
601 return PrefServiceBase::ForProfile(profile_)->GetBoolean( 598 return PrefServiceBase::ForProfile(profile_)->GetBoolean(
602 prefs::kAutofillEnabled); 599 prefs::kAutofillEnabled);
603 } 600 }
604 601
605 // static 602 // static
606 bool PersonalDataManager::IsValidLearnableProfile( 603 bool PersonalDataManager::IsValidLearnableProfile(
607 const AutofillProfile& profile) { 604 const AutofillProfile& profile) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 669
673 // Ensure that profile labels are up to date. Currently, sync relies on 670 // Ensure that profile labels are up to date. Currently, sync relies on
674 // labels to identify a profile. 671 // labels to identify a profile.
675 // TODO(dhollowa): We need to deprecate labels and update the way sync 672 // TODO(dhollowa): We need to deprecate labels and update the way sync
676 // identifies profiles. 673 // identifies profiles.
677 std::vector<AutofillProfile*> profile_pointers(profiles->size()); 674 std::vector<AutofillProfile*> profile_pointers(profiles->size());
678 std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(), 675 std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(),
679 address_of<AutofillProfile>); 676 address_of<AutofillProfile>);
680 AutofillProfile::AdjustInferredLabels(&profile_pointers); 677 AutofillProfile::AdjustInferredLabels(&profile_pointers);
681 678
682 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( 679 scoped_ptr<AutofillWebDataService> autofill_data =
683 profile_, Profile::EXPLICIT_ACCESS); 680 AutofillWebDataService::ForContext(profile_);
684 if (!wds.get()) 681 if (!autofill_data.get())
685 return; 682 return;
686 683
687 // Any profiles that are not in the new profile list should be removed from 684 // Any profiles that are not in the new profile list should be removed from
688 // the web database. 685 // the web database.
689 for (std::vector<AutofillProfile*>::const_iterator iter = 686 for (std::vector<AutofillProfile*>::const_iterator iter =
690 web_profiles_.begin(); 687 web_profiles_.begin();
691 iter != web_profiles_.end(); ++iter) { 688 iter != web_profiles_.end(); ++iter) {
692 if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid())) 689 if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid()))
693 wds->RemoveAutofillProfile((*iter)->guid()); 690 autofill_data->RemoveAutofillProfile((*iter)->guid());
694 } 691 }
695 692
696 // Update the web database with the existing profiles. 693 // Update the web database with the existing profiles.
697 for (std::vector<AutofillProfile>::iterator iter = profiles->begin(); 694 for (std::vector<AutofillProfile>::iterator iter = profiles->begin();
698 iter != profiles->end(); ++iter) { 695 iter != profiles->end(); ++iter) {
699 if (FindByGUID<AutofillProfile>(web_profiles_, iter->guid())) 696 if (FindByGUID<AutofillProfile>(web_profiles_, iter->guid()))
700 wds->UpdateAutofillProfile(*iter); 697 autofill_data->UpdateAutofillProfile(*iter);
701 } 698 }
702 699
703 // Add the new profiles to the web database. Don't add a duplicate. 700 // Add the new profiles to the web database. Don't add a duplicate.
704 for (std::vector<AutofillProfile>::iterator iter = profiles->begin(); 701 for (std::vector<AutofillProfile>::iterator iter = profiles->begin();
705 iter != profiles->end(); ++iter) { 702 iter != profiles->end(); ++iter) {
706 if (!FindByGUID<AutofillProfile>(web_profiles_, iter->guid()) && 703 if (!FindByGUID<AutofillProfile>(web_profiles_, iter->guid()) &&
707 !FindByContents(web_profiles_, *iter)) 704 !FindByContents(web_profiles_, *iter))
708 wds->AddAutofillProfile(*iter); 705 autofill_data->AddAutofillProfile(*iter);
709 } 706 }
710 707
711 // Copy in the new profiles. 708 // Copy in the new profiles.
712 web_profiles_.clear(); 709 web_profiles_.clear();
713 for (std::vector<AutofillProfile>::iterator iter = profiles->begin(); 710 for (std::vector<AutofillProfile>::iterator iter = profiles->begin();
714 iter != profiles->end(); ++iter) { 711 iter != profiles->end(); ++iter) {
715 web_profiles_.push_back(new AutofillProfile(*iter)); 712 web_profiles_.push_back(new AutofillProfile(*iter));
716 } 713 }
717 714
718 // Refresh our local cache and send notifications to observers. 715 // Refresh our local cache and send notifications to observers.
719 Refresh(); 716 Refresh();
720 } 717 }
721 718
722 void PersonalDataManager::SetCreditCards( 719 void PersonalDataManager::SetCreditCards(
723 std::vector<CreditCard>* credit_cards) { 720 std::vector<CreditCard>* credit_cards) {
724 if (profile_->IsOffTheRecord()) 721 if (profile_->IsOffTheRecord())
725 return; 722 return;
726 723
727 // Remove empty credit cards from input. 724 // Remove empty credit cards from input.
728 credit_cards->erase( 725 credit_cards->erase(
729 std::remove_if( 726 std::remove_if(
730 credit_cards->begin(), credit_cards->end(), 727 credit_cards->begin(), credit_cards->end(),
731 std::mem_fun_ref(&CreditCard::IsEmpty)), 728 std::mem_fun_ref(&CreditCard::IsEmpty)),
732 credit_cards->end()); 729 credit_cards->end());
733 730
734 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( 731 scoped_ptr<AutofillWebDataService> autofill_data =
735 profile_, Profile::EXPLICIT_ACCESS); 732 AutofillWebDataService::ForContext(profile_);
736 if (!wds.get()) 733 if (!autofill_data.get())
737 return; 734 return;
738 735
739 // Any credit cards that are not in the new credit card list should be 736 // Any credit cards that are not in the new credit card list should be
740 // removed. 737 // removed.
741 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); 738 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin();
742 iter != credit_cards_.end(); ++iter) { 739 iter != credit_cards_.end(); ++iter) {
743 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid())) 740 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid()))
744 wds->RemoveCreditCard((*iter)->guid()); 741 autofill_data->RemoveCreditCard((*iter)->guid());
745 } 742 }
746 743
747 // Update the web database with the existing credit cards. 744 // Update the web database with the existing credit cards.
748 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); 745 for (std::vector<CreditCard>::iterator iter = credit_cards->begin();
749 iter != credit_cards->end(); ++iter) { 746 iter != credit_cards->end(); ++iter) {
750 if (FindByGUID<CreditCard>(credit_cards_, iter->guid())) 747 if (FindByGUID<CreditCard>(credit_cards_, iter->guid()))
751 wds->UpdateCreditCard(*iter); 748 autofill_data->UpdateCreditCard(*iter);
752 } 749 }
753 750
754 // Add the new credit cards to the web database. Don't add a duplicate. 751 // Add the new credit cards to the web database. Don't add a duplicate.
755 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); 752 for (std::vector<CreditCard>::iterator iter = credit_cards->begin();
756 iter != credit_cards->end(); ++iter) { 753 iter != credit_cards->end(); ++iter) {
757 if (!FindByGUID<CreditCard>(credit_cards_, iter->guid()) && 754 if (!FindByGUID<CreditCard>(credit_cards_, iter->guid()) &&
758 !FindByContents(credit_cards_, *iter)) 755 !FindByContents(credit_cards_, *iter))
759 wds->AddCreditCard(*iter); 756 autofill_data->AddCreditCard(*iter);
760 } 757 }
761 758
762 // Copy in the new credit cards. 759 // Copy in the new credit cards.
763 credit_cards_.clear(); 760 credit_cards_.clear();
764 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); 761 for (std::vector<CreditCard>::iterator iter = credit_cards->begin();
765 iter != credit_cards->end(); ++iter) { 762 iter != credit_cards->end(); ++iter) {
766 credit_cards_.push_back(new CreditCard(*iter)); 763 credit_cards_.push_back(new CreditCard(*iter));
767 } 764 }
768 765
769 // Refresh our local cache and send notifications to observers. 766 // Refresh our local cache and send notifications to observers.
770 Refresh(); 767 Refresh();
771 } 768 }
772 769
773 void PersonalDataManager::LoadProfiles() { 770 void PersonalDataManager::LoadProfiles() {
774 scoped_refptr<WebDataService> web_data_service = 771 scoped_ptr<AutofillWebDataService> autofill_data =
775 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 772 AutofillWebDataService::ForContext(profile_);
776 if (!web_data_service.get()) { 773 if (!autofill_data.get()) {
777 NOTREACHED(); 774 NOTREACHED();
778 return; 775 return;
779 } 776 }
780 777
781 CancelPendingQuery(&pending_profiles_query_); 778 CancelPendingQuery(&pending_profiles_query_);
782 779
783 pending_profiles_query_ = web_data_service->GetAutofillProfiles(this); 780 pending_profiles_query_ = autofill_data->GetAutofillProfiles(this);
784 } 781 }
785 782
786 // Win and Linux implementations do nothing. Mac implementation fills in the 783 // Win and Linux implementations do nothing. Mac implementation fills in the
787 // contents of |auxiliary_profiles_|. 784 // contents of |auxiliary_profiles_|.
788 #if !defined(OS_MACOSX) 785 #if !defined(OS_MACOSX)
789 void PersonalDataManager::LoadAuxiliaryProfiles() const { 786 void PersonalDataManager::LoadAuxiliaryProfiles() const {
790 } 787 }
791 #endif 788 #endif
792 789
793 void PersonalDataManager::LoadCreditCards() { 790 void PersonalDataManager::LoadCreditCards() {
794 scoped_refptr<WebDataService> web_data_service = 791 scoped_ptr<AutofillWebDataService> autofill_data =
795 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 792 AutofillWebDataService::ForContext(profile_);
796 if (!web_data_service.get()) { 793 if (!autofill_data.get()) {
797 NOTREACHED(); 794 NOTREACHED();
798 return; 795 return;
799 } 796 }
800 797
801 CancelPendingQuery(&pending_creditcards_query_); 798 CancelPendingQuery(&pending_creditcards_query_);
802 799
803 pending_creditcards_query_ = web_data_service->GetCreditCards(this); 800 pending_creditcards_query_ = autofill_data->GetCreditCards(this);
804 } 801 }
805 802
806 void PersonalDataManager::ReceiveLoadedProfiles(WebDataService::Handle h, 803 void PersonalDataManager::ReceiveLoadedProfiles(WebDataServiceBase::Handle h,
807 const WDTypedResult* result) { 804 const WDTypedResult* result) {
808 DCHECK_EQ(pending_profiles_query_, h); 805 DCHECK_EQ(pending_profiles_query_, h);
809 806
810 pending_profiles_query_ = 0; 807 pending_profiles_query_ = 0;
811 web_profiles_.clear(); 808 web_profiles_.clear();
812 809
813 const WDResult<std::vector<AutofillProfile*> >* r = 810 const WDResult<std::vector<AutofillProfile*> >* r =
814 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); 811 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result);
815 812
816 std::vector<AutofillProfile*> profiles = r->GetValue(); 813 std::vector<AutofillProfile*> profiles = r->GetValue();
817 for (std::vector<AutofillProfile*>::iterator iter = profiles.begin(); 814 for (std::vector<AutofillProfile*>::iterator iter = profiles.begin();
818 iter != profiles.end(); ++iter) { 815 iter != profiles.end(); ++iter) {
819 web_profiles_.push_back(*iter); 816 web_profiles_.push_back(*iter);
820 } 817 }
821 818
822 LogProfileCount(); 819 LogProfileCount();
823 EmptyMigrationTrash(); 820 EmptyMigrationTrash();
824 } 821 }
825 822
826 void PersonalDataManager::ReceiveLoadedCreditCards( 823 void PersonalDataManager::ReceiveLoadedCreditCards(
827 WebDataService::Handle h, const WDTypedResult* result) { 824 WebDataServiceBase::Handle h, const WDTypedResult* result) {
828 DCHECK_EQ(pending_creditcards_query_, h); 825 DCHECK_EQ(pending_creditcards_query_, h);
829 826
830 pending_creditcards_query_ = 0; 827 pending_creditcards_query_ = 0;
831 credit_cards_.clear(); 828 credit_cards_.clear();
832 829
833 const WDResult<std::vector<CreditCard*> >* r = 830 const WDResult<std::vector<CreditCard*> >* r =
834 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); 831 static_cast<const WDResult<std::vector<CreditCard*> >*>(result);
835 832
836 std::vector<CreditCard*> credit_cards = r->GetValue(); 833 std::vector<CreditCard*> credit_cards = r->GetValue();
837 for (std::vector<CreditCard*>::iterator iter = credit_cards.begin(); 834 for (std::vector<CreditCard*>::iterator iter = credit_cards.begin();
838 iter != credit_cards.end(); ++iter) { 835 iter != credit_cards.end(); ++iter) {
839 credit_cards_.push_back(*iter); 836 credit_cards_.push_back(*iter);
840 } 837 }
841 } 838 }
842 839
843 void PersonalDataManager::CancelPendingQuery(WebDataService::Handle* handle) { 840 void PersonalDataManager::CancelPendingQuery(
841 WebDataServiceBase::Handle* handle) {
844 if (*handle) { 842 if (*handle) {
845 scoped_refptr<WebDataService> web_data_service = 843 scoped_ptr<AutofillWebDataService> autofill_data =
846 WebDataServiceFactory::GetForProfile(profile_, 844 AutofillWebDataService::ForContext(profile_);
847 Profile::EXPLICIT_ACCESS); 845 if (!autofill_data.get()) {
848 if (!web_data_service.get()) {
849 NOTREACHED(); 846 NOTREACHED();
850 return; 847 return;
851 } 848 }
852 web_data_service->CancelRequest(*handle); 849 autofill_data->CancelRequest(*handle);
853 } 850 }
854 *handle = 0; 851 *handle = 0;
855 } 852 }
856 853
857 void PersonalDataManager::SaveImportedProfile( 854 void PersonalDataManager::SaveImportedProfile(
858 const AutofillProfile& imported_profile) { 855 const AutofillProfile& imported_profile) {
859 if (profile_->IsOffTheRecord()) { 856 if (profile_->IsOffTheRecord()) {
860 // The |IsOffTheRecord| check should happen earlier in the import process, 857 // The |IsOffTheRecord| check should happen earlier in the import process,
861 // upon form submission. 858 // upon form submission.
862 NOTREACHED(); 859 NOTREACHED();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 if (!merged) 903 if (!merged)
907 creditcards.push_back(imported_credit_card); 904 creditcards.push_back(imported_credit_card);
908 905
909 SetCreditCards(&creditcards); 906 SetCreditCards(&creditcards);
910 } 907 }
911 908
912 void PersonalDataManager::EmptyMigrationTrash() { 909 void PersonalDataManager::EmptyMigrationTrash() {
913 if (!profile_ || profile_->IsOffTheRecord()) 910 if (!profile_ || profile_->IsOffTheRecord())
914 return; 911 return;
915 912
916 scoped_refptr<WebDataService> web_data_service = 913 scoped_ptr<AutofillWebDataService> autofill_data =
917 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 914 AutofillWebDataService::ForContext(profile_);
918 if (!web_data_service.get()) { 915 if (!autofill_data.get()) {
919 NOTREACHED(); 916 NOTREACHED();
920 return; 917 return;
921 } 918 }
922 919
923 ProfileSyncService* sync_service = 920 ProfileSyncService* sync_service =
924 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); 921 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_);
925 if (!sync_service) 922 if (!sync_service)
926 return; 923 return;
927 924
928 if (!sync_service->HasSyncSetupCompleted()) { 925 if (!sync_service->HasSyncSetupCompleted()) {
929 web_data_service->EmptyMigrationTrash(false); 926 autofill_data->EmptyMigrationTrash(false);
930 } else if (sync_service->ShouldPushChanges()) { 927 } else if (sync_service->ShouldPushChanges()) {
931 web_data_service->EmptyMigrationTrash(true); 928 autofill_data->EmptyMigrationTrash(true);
932 } else { 929 } else {
933 // Install ourself as a listener so we can empty the trash once the 930 // Install ourself as a listener so we can empty the trash once the
934 // sync service becomes available. 931 // sync service becomes available.
935 if (!sync_service->HasObserver(this)) 932 if (!sync_service->HasObserver(this))
936 sync_service->AddObserver(this); 933 sync_service->AddObserver(this);
937 } 934 }
938 } 935 }
939 936
940 void PersonalDataManager::LogProfileCount() const { 937 void PersonalDataManager::LogProfileCount() const {
941 if (!has_logged_profile_count_) { 938 if (!has_logged_profile_count_) {
942 metric_logger_->LogStoredProfileCount(web_profiles_.size()); 939 metric_logger_->LogStoredProfileCount(web_profiles_.size());
943 has_logged_profile_count_ = true; 940 has_logged_profile_count_ = true;
944 } 941 }
945 } 942 }
946 943
947 const AutofillMetrics* PersonalDataManager::metric_logger() const { 944 const AutofillMetrics* PersonalDataManager::metric_logger() const {
948 return metric_logger_.get(); 945 return metric_logger_.get();
949 } 946 }
950 947
951 void PersonalDataManager::set_metric_logger( 948 void PersonalDataManager::set_metric_logger(
952 const AutofillMetrics* metric_logger) { 949 const AutofillMetrics* metric_logger) {
953 metric_logger_.reset(metric_logger); 950 metric_logger_.reset(metric_logger);
954 } 951 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698