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/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: Fix gypi file 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_ptr<AutofillWebDataService> service(
176 WebDataServiceFactory::GetForProfile(profile_, 173 AutofillWebDataService::ForContext(profile_));
177 Profile::EXPLICIT_ACCESS); 174 if (service.get())
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(
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 if (DCHECK_IS_ON()) {
236 web_data_service.get() == WebDataServiceFactory::GetForProfile( 230 WebDataServiceBase* notification_source =
237 profile_, Profile::EXPLICIT_ACCESS).get()); 231 content::Source<WebDataServiceBase>(source).ptr();
232
233 scoped_ptr<AutofillWebDataService> autofill_data(
234 AutofillWebDataService::ForContext(profile_));
235
236 DCHECK(autofill_data.get() &&
237 autofill_data->GetNotificationSource() == notification_source);
238 }
239
238 Refresh(); 240 Refresh();
239 } 241 }
240 242
241 bool PersonalDataManager::ImportFormData( 243 bool PersonalDataManager::ImportFormData(
242 const FormStructure& form, 244 const FormStructure& form,
243 const CreditCard** imported_credit_card) { 245 const CreditCard** imported_credit_card) {
244 scoped_ptr<AutofillProfile> imported_profile(new AutofillProfile); 246 scoped_ptr<AutofillProfile> imported_profile(new AutofillProfile);
245 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard); 247 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard);
246 248
247 // Parse the form and construct a profile based on the information that is 249 // 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()) 362 if (profile_->IsOffTheRecord())
361 return; 363 return;
362 364
363 if (profile.IsEmpty()) 365 if (profile.IsEmpty())
364 return; 366 return;
365 367
366 // Don't add an existing profile. 368 // Don't add an existing profile.
367 if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) 369 if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid()))
368 return; 370 return;
369 371
370 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( 372 scoped_ptr<AutofillWebDataService> autofill_data(
371 profile_, Profile::EXPLICIT_ACCESS); 373 AutofillWebDataService::ForContext(profile_));
372 if (!wds.get()) 374 if (!autofill_data.get())
373 return; 375 return;
374 376
375 // Don't add a duplicate. 377 // Don't add a duplicate.
376 if (FindByContents(web_profiles_, profile)) 378 if (FindByContents(web_profiles_, profile))
377 return; 379 return;
378 380
379 // Add the new profile to the web database. 381 // Add the new profile to the web database.
380 wds->AddAutofillProfile(profile); 382 autofill_data->AddAutofillProfile(profile);
381 383
382 // Refresh our local cache and send notifications to observers. 384 // Refresh our local cache and send notifications to observers.
383 Refresh(); 385 Refresh();
384 } 386 }
385 387
386 void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) { 388 void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) {
387 if (profile_->IsOffTheRecord()) 389 if (profile_->IsOffTheRecord())
388 return; 390 return;
389 391
390 if (!FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) 392 if (!FindByGUID<AutofillProfile>(web_profiles_, profile.guid()))
391 return; 393 return;
392 394
393 if (profile.IsEmpty()) { 395 if (profile.IsEmpty()) {
394 RemoveProfile(profile.guid()); 396 RemoveProfile(profile.guid());
395 return; 397 return;
396 } 398 }
397 399
398 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( 400 scoped_ptr<AutofillWebDataService> autofill_data(
399 profile_, Profile::EXPLICIT_ACCESS); 401 AutofillWebDataService::ForContext(profile_));
400 if (!wds.get()) 402 if (!autofill_data.get())
401 return; 403 return;
402 404
403 // Make the update. 405 // Make the update.
404 wds->UpdateAutofillProfile(profile); 406 autofill_data->UpdateAutofillProfile(profile);
405 407
406 // Refresh our local cache and send notifications to observers. 408 // Refresh our local cache and send notifications to observers.
407 Refresh(); 409 Refresh();
408 } 410 }
409 411
410 void PersonalDataManager::RemoveProfile(const std::string& guid) { 412 void PersonalDataManager::RemoveProfile(const std::string& guid) {
411 if (profile_->IsOffTheRecord()) 413 if (profile_->IsOffTheRecord())
412 return; 414 return;
413 415
414 if (!FindByGUID<AutofillProfile>(web_profiles_, guid)) 416 if (!FindByGUID<AutofillProfile>(web_profiles_, guid))
415 return; 417 return;
416 418
417 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( 419 scoped_ptr<AutofillWebDataService> autofill_data(
418 profile_, Profile::EXPLICIT_ACCESS); 420 AutofillWebDataService::ForContext(profile_));
419 if (!wds.get()) 421 if (!autofill_data.get())
420 return; 422 return;
421 423
422 // Remove the profile. 424 // Remove the profile.
423 wds->RemoveAutofillProfile(guid); 425 autofill_data->RemoveAutofillProfile(guid);
424 426
425 // Refresh our local cache and send notifications to observers. 427 // Refresh our local cache and send notifications to observers.
426 Refresh(); 428 Refresh();
427 } 429 }
428 430
429 AutofillProfile* PersonalDataManager::GetProfileByGUID( 431 AutofillProfile* PersonalDataManager::GetProfileByGUID(
430 const std::string& guid) { 432 const std::string& guid) {
431 for (std::vector<AutofillProfile*>::iterator iter = web_profiles_.begin(); 433 for (std::vector<AutofillProfile*>::iterator iter = web_profiles_.begin();
432 iter != web_profiles_.end(); ++iter) { 434 iter != web_profiles_.end(); ++iter) {
433 if ((*iter)->guid() == guid) 435 if ((*iter)->guid() == guid)
434 return *iter; 436 return *iter;
435 } 437 }
436 return NULL; 438 return NULL;
437 } 439 }
438 440
439 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) { 441 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) {
440 if (profile_->IsOffTheRecord()) 442 if (profile_->IsOffTheRecord())
441 return; 443 return;
442 444
443 if (credit_card.IsEmpty()) 445 if (credit_card.IsEmpty())
444 return; 446 return;
445 447
446 if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) 448 if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid()))
447 return; 449 return;
448 450
449 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( 451 scoped_ptr<AutofillWebDataService> autofill_data(
450 profile_, Profile::EXPLICIT_ACCESS); 452 AutofillWebDataService::ForContext(profile_));
451 if (!wds.get()) 453 if (!autofill_data.get())
452 return; 454 return;
453 455
454 // Don't add a duplicate. 456 // Don't add a duplicate.
455 if (FindByContents(credit_cards_, credit_card)) 457 if (FindByContents(credit_cards_, credit_card))
456 return; 458 return;
457 459
458 // Add the new credit card to the web database. 460 // Add the new credit card to the web database.
459 wds->AddCreditCard(credit_card); 461 autofill_data->AddCreditCard(credit_card);
460 462
461 // Refresh our local cache and send notifications to observers. 463 // Refresh our local cache and send notifications to observers.
462 Refresh(); 464 Refresh();
463 } 465 }
464 466
465 void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { 467 void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) {
466 if (profile_->IsOffTheRecord()) 468 if (profile_->IsOffTheRecord())
467 return; 469 return;
468 470
469 if (!FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) 471 if (!FindByGUID<CreditCard>(credit_cards_, credit_card.guid()))
470 return; 472 return;
471 473
472 if (credit_card.IsEmpty()) { 474 if (credit_card.IsEmpty()) {
473 RemoveCreditCard(credit_card.guid()); 475 RemoveCreditCard(credit_card.guid());
474 return; 476 return;
475 } 477 }
476 478
477 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( 479 scoped_ptr<AutofillWebDataService> autofill_data(
478 profile_, Profile::EXPLICIT_ACCESS); 480 AutofillWebDataService::ForContext(profile_));
479 if (!wds.get()) 481 if (!autofill_data.get())
480 return; 482 return;
481 483
482 // Make the update. 484 // Make the update.
483 wds->UpdateCreditCard(credit_card); 485 autofill_data->UpdateCreditCard(credit_card);
484 486
485 // Refresh our local cache and send notifications to observers. 487 // Refresh our local cache and send notifications to observers.
486 Refresh(); 488 Refresh();
487 } 489 }
488 490
489 void PersonalDataManager::RemoveCreditCard(const std::string& guid) { 491 void PersonalDataManager::RemoveCreditCard(const std::string& guid) {
490 if (profile_->IsOffTheRecord()) 492 if (profile_->IsOffTheRecord())
491 return; 493 return;
492 494
493 if (!FindByGUID<CreditCard>(credit_cards_, guid)) 495 if (!FindByGUID<CreditCard>(credit_cards_, guid))
494 return; 496 return;
495 497
496 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( 498 scoped_ptr<AutofillWebDataService> autofill_data(
497 profile_, Profile::EXPLICIT_ACCESS); 499 AutofillWebDataService::ForContext(profile_));
498 if (!wds.get()) 500 if (!autofill_data.get())
499 return; 501 return;
500 502
501 // Remove the credit card. 503 // Remove the credit card.
502 wds->RemoveCreditCard(guid); 504 autofill_data->RemoveCreditCard(guid);
503 505
504 // Refresh our local cache and send notifications to observers. 506 // Refresh our local cache and send notifications to observers.
505 Refresh(); 507 Refresh();
506 } 508 }
507 509
508 CreditCard* PersonalDataManager::GetCreditCardByGUID(const std::string& guid) { 510 CreditCard* PersonalDataManager::GetCreditCardByGUID(const std::string& guid) {
509 for (std::vector<CreditCard*>::iterator iter = credit_cards_.begin(); 511 for (std::vector<CreditCard*>::iterator iter = credit_cards_.begin();
510 iter != credit_cards_.end(); ++iter) { 512 iter != credit_cards_.end(); ++iter) {
511 if ((*iter)->guid() == guid) 513 if ((*iter)->guid() == guid)
512 return *iter; 514 return *iter;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 pending_creditcards_query_(0), 578 pending_creditcards_query_(0),
577 metric_logger_(new AutofillMetrics), 579 metric_logger_(new AutofillMetrics),
578 has_logged_profile_count_(false) { 580 has_logged_profile_count_(false) {
579 } 581 }
580 582
581 void PersonalDataManager::Init(Profile* profile) { 583 void PersonalDataManager::Init(Profile* profile) {
582 profile_ = profile; 584 profile_ = profile;
583 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); 585 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled());
584 586
585 // WebDataService may not be available in tests. 587 // WebDataService may not be available in tests.
586 scoped_refptr<WebDataService> web_data_service = 588 scoped_ptr<AutofillWebDataService> autofill_data(
587 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 589 AutofillWebDataService::ForContext(profile_));
588 if (!web_data_service.get()) 590 if (!autofill_data.get())
589 return; 591 return;
590 592
591 LoadProfiles(); 593 LoadProfiles();
592 LoadCreditCards(); 594 LoadCreditCards();
593 595
594 notification_registrar_.Add( 596 notification_registrar_.Add(
595 this, 597 this,
596 chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED, 598 chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED,
597 content::Source<WebDataService>(web_data_service)); 599 content::Source<WebDataServiceBase>(
600 autofill_data->GetNotificationSource()));
598 } 601 }
599 602
600 bool PersonalDataManager::IsAutofillEnabled() const { 603 bool PersonalDataManager::IsAutofillEnabled() const {
601 return PrefServiceBase::ForProfile(profile_)->GetBoolean( 604 return PrefServiceBase::ForProfile(profile_)->GetBoolean(
602 prefs::kAutofillEnabled); 605 prefs::kAutofillEnabled);
603 } 606 }
604 607
605 // static 608 // static
606 bool PersonalDataManager::IsValidLearnableProfile( 609 bool PersonalDataManager::IsValidLearnableProfile(
607 const AutofillProfile& profile) { 610 const AutofillProfile& profile) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 675
673 // Ensure that profile labels are up to date. Currently, sync relies on 676 // Ensure that profile labels are up to date. Currently, sync relies on
674 // labels to identify a profile. 677 // labels to identify a profile.
675 // TODO(dhollowa): We need to deprecate labels and update the way sync 678 // TODO(dhollowa): We need to deprecate labels and update the way sync
676 // identifies profiles. 679 // identifies profiles.
677 std::vector<AutofillProfile*> profile_pointers(profiles->size()); 680 std::vector<AutofillProfile*> profile_pointers(profiles->size());
678 std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(), 681 std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(),
679 address_of<AutofillProfile>); 682 address_of<AutofillProfile>);
680 AutofillProfile::AdjustInferredLabels(&profile_pointers); 683 AutofillProfile::AdjustInferredLabels(&profile_pointers);
681 684
682 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( 685 scoped_ptr<AutofillWebDataService> autofill_data(
683 profile_, Profile::EXPLICIT_ACCESS); 686 AutofillWebDataService::ForContext(profile_));
684 if (!wds.get()) 687 if (!autofill_data.get())
685 return; 688 return;
686 689
687 // Any profiles that are not in the new profile list should be removed from 690 // Any profiles that are not in the new profile list should be removed from
688 // the web database. 691 // the web database.
689 for (std::vector<AutofillProfile*>::const_iterator iter = 692 for (std::vector<AutofillProfile*>::const_iterator iter =
690 web_profiles_.begin(); 693 web_profiles_.begin();
691 iter != web_profiles_.end(); ++iter) { 694 iter != web_profiles_.end(); ++iter) {
692 if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid())) 695 if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid()))
693 wds->RemoveAutofillProfile((*iter)->guid()); 696 autofill_data->RemoveAutofillProfile((*iter)->guid());
694 } 697 }
695 698
696 // Update the web database with the existing profiles. 699 // Update the web database with the existing profiles.
697 for (std::vector<AutofillProfile>::iterator iter = profiles->begin(); 700 for (std::vector<AutofillProfile>::iterator iter = profiles->begin();
698 iter != profiles->end(); ++iter) { 701 iter != profiles->end(); ++iter) {
699 if (FindByGUID<AutofillProfile>(web_profiles_, iter->guid())) 702 if (FindByGUID<AutofillProfile>(web_profiles_, iter->guid()))
700 wds->UpdateAutofillProfile(*iter); 703 autofill_data->UpdateAutofillProfile(*iter);
701 } 704 }
702 705
703 // Add the new profiles to the web database. Don't add a duplicate. 706 // Add the new profiles to the web database. Don't add a duplicate.
704 for (std::vector<AutofillProfile>::iterator iter = profiles->begin(); 707 for (std::vector<AutofillProfile>::iterator iter = profiles->begin();
705 iter != profiles->end(); ++iter) { 708 iter != profiles->end(); ++iter) {
706 if (!FindByGUID<AutofillProfile>(web_profiles_, iter->guid()) && 709 if (!FindByGUID<AutofillProfile>(web_profiles_, iter->guid()) &&
707 !FindByContents(web_profiles_, *iter)) 710 !FindByContents(web_profiles_, *iter))
708 wds->AddAutofillProfile(*iter); 711 autofill_data->AddAutofillProfile(*iter);
709 } 712 }
710 713
711 // Copy in the new profiles. 714 // Copy in the new profiles.
712 web_profiles_.clear(); 715 web_profiles_.clear();
713 for (std::vector<AutofillProfile>::iterator iter = profiles->begin(); 716 for (std::vector<AutofillProfile>::iterator iter = profiles->begin();
714 iter != profiles->end(); ++iter) { 717 iter != profiles->end(); ++iter) {
715 web_profiles_.push_back(new AutofillProfile(*iter)); 718 web_profiles_.push_back(new AutofillProfile(*iter));
716 } 719 }
717 720
718 // Refresh our local cache and send notifications to observers. 721 // Refresh our local cache and send notifications to observers.
719 Refresh(); 722 Refresh();
720 } 723 }
721 724
722 void PersonalDataManager::SetCreditCards( 725 void PersonalDataManager::SetCreditCards(
723 std::vector<CreditCard>* credit_cards) { 726 std::vector<CreditCard>* credit_cards) {
724 if (profile_->IsOffTheRecord()) 727 if (profile_->IsOffTheRecord())
725 return; 728 return;
726 729
727 // Remove empty credit cards from input. 730 // Remove empty credit cards from input.
728 credit_cards->erase( 731 credit_cards->erase(
729 std::remove_if( 732 std::remove_if(
730 credit_cards->begin(), credit_cards->end(), 733 credit_cards->begin(), credit_cards->end(),
731 std::mem_fun_ref(&CreditCard::IsEmpty)), 734 std::mem_fun_ref(&CreditCard::IsEmpty)),
732 credit_cards->end()); 735 credit_cards->end());
733 736
734 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( 737 scoped_ptr<AutofillWebDataService> autofill_data(
735 profile_, Profile::EXPLICIT_ACCESS); 738 AutofillWebDataService::ForContext(profile_));
736 if (!wds.get()) 739 if (!autofill_data.get())
737 return; 740 return;
738 741
739 // Any credit cards that are not in the new credit card list should be 742 // Any credit cards that are not in the new credit card list should be
740 // removed. 743 // removed.
741 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); 744 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin();
742 iter != credit_cards_.end(); ++iter) { 745 iter != credit_cards_.end(); ++iter) {
743 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid())) 746 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid()))
744 wds->RemoveCreditCard((*iter)->guid()); 747 autofill_data->RemoveCreditCard((*iter)->guid());
745 } 748 }
746 749
747 // Update the web database with the existing credit cards. 750 // Update the web database with the existing credit cards.
748 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); 751 for (std::vector<CreditCard>::iterator iter = credit_cards->begin();
749 iter != credit_cards->end(); ++iter) { 752 iter != credit_cards->end(); ++iter) {
750 if (FindByGUID<CreditCard>(credit_cards_, iter->guid())) 753 if (FindByGUID<CreditCard>(credit_cards_, iter->guid()))
751 wds->UpdateCreditCard(*iter); 754 autofill_data->UpdateCreditCard(*iter);
752 } 755 }
753 756
754 // Add the new credit cards to the web database. Don't add a duplicate. 757 // Add the new credit cards to the web database. Don't add a duplicate.
755 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); 758 for (std::vector<CreditCard>::iterator iter = credit_cards->begin();
756 iter != credit_cards->end(); ++iter) { 759 iter != credit_cards->end(); ++iter) {
757 if (!FindByGUID<CreditCard>(credit_cards_, iter->guid()) && 760 if (!FindByGUID<CreditCard>(credit_cards_, iter->guid()) &&
758 !FindByContents(credit_cards_, *iter)) 761 !FindByContents(credit_cards_, *iter))
759 wds->AddCreditCard(*iter); 762 autofill_data->AddCreditCard(*iter);
760 } 763 }
761 764
762 // Copy in the new credit cards. 765 // Copy in the new credit cards.
763 credit_cards_.clear(); 766 credit_cards_.clear();
764 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); 767 for (std::vector<CreditCard>::iterator iter = credit_cards->begin();
765 iter != credit_cards->end(); ++iter) { 768 iter != credit_cards->end(); ++iter) {
766 credit_cards_.push_back(new CreditCard(*iter)); 769 credit_cards_.push_back(new CreditCard(*iter));
767 } 770 }
768 771
769 // Refresh our local cache and send notifications to observers. 772 // Refresh our local cache and send notifications to observers.
770 Refresh(); 773 Refresh();
771 } 774 }
772 775
773 void PersonalDataManager::LoadProfiles() { 776 void PersonalDataManager::LoadProfiles() {
774 scoped_refptr<WebDataService> web_data_service = 777 scoped_ptr<AutofillWebDataService> autofill_data(
775 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 778 AutofillWebDataService::ForContext(profile_));
776 if (!web_data_service.get()) { 779 if (!autofill_data.get()) {
777 NOTREACHED(); 780 NOTREACHED();
778 return; 781 return;
779 } 782 }
780 783
781 CancelPendingQuery(&pending_profiles_query_); 784 CancelPendingQuery(&pending_profiles_query_);
782 785
783 pending_profiles_query_ = web_data_service->GetAutofillProfiles(this); 786 pending_profiles_query_ = autofill_data->GetAutofillProfiles(this);
784 } 787 }
785 788
786 // Win and Linux implementations do nothing. Mac implementation fills in the 789 // Win and Linux implementations do nothing. Mac implementation fills in the
787 // contents of |auxiliary_profiles_|. 790 // contents of |auxiliary_profiles_|.
788 #if !defined(OS_MACOSX) 791 #if !defined(OS_MACOSX)
789 void PersonalDataManager::LoadAuxiliaryProfiles() const { 792 void PersonalDataManager::LoadAuxiliaryProfiles() const {
790 } 793 }
791 #endif 794 #endif
792 795
793 void PersonalDataManager::LoadCreditCards() { 796 void PersonalDataManager::LoadCreditCards() {
794 scoped_refptr<WebDataService> web_data_service = 797 scoped_ptr<AutofillWebDataService> autofill_data(
795 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 798 AutofillWebDataService::ForContext(profile_));
796 if (!web_data_service.get()) { 799 if (!autofill_data.get()) {
797 NOTREACHED(); 800 NOTREACHED();
798 return; 801 return;
799 } 802 }
800 803
801 CancelPendingQuery(&pending_creditcards_query_); 804 CancelPendingQuery(&pending_creditcards_query_);
802 805
803 pending_creditcards_query_ = web_data_service->GetCreditCards(this); 806 pending_creditcards_query_ = autofill_data->GetCreditCards(this);
804 } 807 }
805 808
806 void PersonalDataManager::ReceiveLoadedProfiles(WebDataService::Handle h, 809 void PersonalDataManager::ReceiveLoadedProfiles(WebDataServiceBase::Handle h,
807 const WDTypedResult* result) { 810 const WDTypedResult* result) {
808 DCHECK_EQ(pending_profiles_query_, h); 811 DCHECK_EQ(pending_profiles_query_, h);
809 812
810 pending_profiles_query_ = 0; 813 pending_profiles_query_ = 0;
811 web_profiles_.clear(); 814 web_profiles_.clear();
812 815
813 const WDResult<std::vector<AutofillProfile*> >* r = 816 const WDResult<std::vector<AutofillProfile*> >* r =
814 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); 817 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result);
815 818
816 std::vector<AutofillProfile*> profiles = r->GetValue(); 819 std::vector<AutofillProfile*> profiles = r->GetValue();
817 for (std::vector<AutofillProfile*>::iterator iter = profiles.begin(); 820 for (std::vector<AutofillProfile*>::iterator iter = profiles.begin();
818 iter != profiles.end(); ++iter) { 821 iter != profiles.end(); ++iter) {
819 web_profiles_.push_back(*iter); 822 web_profiles_.push_back(*iter);
820 } 823 }
821 824
822 LogProfileCount(); 825 LogProfileCount();
823 EmptyMigrationTrash(); 826 EmptyMigrationTrash();
824 } 827 }
825 828
826 void PersonalDataManager::ReceiveLoadedCreditCards( 829 void PersonalDataManager::ReceiveLoadedCreditCards(
827 WebDataService::Handle h, const WDTypedResult* result) { 830 WebDataServiceBase::Handle h, const WDTypedResult* result) {
828 DCHECK_EQ(pending_creditcards_query_, h); 831 DCHECK_EQ(pending_creditcards_query_, h);
829 832
830 pending_creditcards_query_ = 0; 833 pending_creditcards_query_ = 0;
831 credit_cards_.clear(); 834 credit_cards_.clear();
832 835
833 const WDResult<std::vector<CreditCard*> >* r = 836 const WDResult<std::vector<CreditCard*> >* r =
834 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); 837 static_cast<const WDResult<std::vector<CreditCard*> >*>(result);
835 838
836 std::vector<CreditCard*> credit_cards = r->GetValue(); 839 std::vector<CreditCard*> credit_cards = r->GetValue();
837 for (std::vector<CreditCard*>::iterator iter = credit_cards.begin(); 840 for (std::vector<CreditCard*>::iterator iter = credit_cards.begin();
838 iter != credit_cards.end(); ++iter) { 841 iter != credit_cards.end(); ++iter) {
839 credit_cards_.push_back(*iter); 842 credit_cards_.push_back(*iter);
840 } 843 }
841 } 844 }
842 845
843 void PersonalDataManager::CancelPendingQuery(WebDataService::Handle* handle) { 846 void PersonalDataManager::CancelPendingQuery(
847 WebDataServiceBase::Handle* handle) {
844 if (*handle) { 848 if (*handle) {
845 scoped_refptr<WebDataService> web_data_service = 849 scoped_ptr<AutofillWebDataService> autofill_data(
846 WebDataServiceFactory::GetForProfile(profile_, 850 AutofillWebDataService::ForContext(profile_));
847 Profile::EXPLICIT_ACCESS); 851 if (!autofill_data.get()) {
848 if (!web_data_service.get()) {
849 NOTREACHED(); 852 NOTREACHED();
850 return; 853 return;
851 } 854 }
852 web_data_service->CancelRequest(*handle); 855 autofill_data->CancelRequest(*handle);
853 } 856 }
854 *handle = 0; 857 *handle = 0;
855 } 858 }
856 859
857 void PersonalDataManager::SaveImportedProfile( 860 void PersonalDataManager::SaveImportedProfile(
858 const AutofillProfile& imported_profile) { 861 const AutofillProfile& imported_profile) {
859 if (profile_->IsOffTheRecord()) { 862 if (profile_->IsOffTheRecord()) {
860 // The |IsOffTheRecord| check should happen earlier in the import process, 863 // The |IsOffTheRecord| check should happen earlier in the import process,
861 // upon form submission. 864 // upon form submission.
862 NOTREACHED(); 865 NOTREACHED();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 if (!merged) 909 if (!merged)
907 creditcards.push_back(imported_credit_card); 910 creditcards.push_back(imported_credit_card);
908 911
909 SetCreditCards(&creditcards); 912 SetCreditCards(&creditcards);
910 } 913 }
911 914
912 void PersonalDataManager::EmptyMigrationTrash() { 915 void PersonalDataManager::EmptyMigrationTrash() {
913 if (!profile_ || profile_->IsOffTheRecord()) 916 if (!profile_ || profile_->IsOffTheRecord())
914 return; 917 return;
915 918
916 scoped_refptr<WebDataService> web_data_service = 919 scoped_ptr<AutofillWebDataService> autofill_data(
917 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 920 AutofillWebDataService::ForContext(profile_));
918 if (!web_data_service.get()) { 921 if (!autofill_data.get()) {
919 NOTREACHED(); 922 NOTREACHED();
920 return; 923 return;
921 } 924 }
922 925
923 ProfileSyncService* sync_service = 926 ProfileSyncService* sync_service =
924 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); 927 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_);
925 if (!sync_service) 928 if (!sync_service)
926 return; 929 return;
927 930
928 if (!sync_service->HasSyncSetupCompleted()) { 931 if (!sync_service->HasSyncSetupCompleted()) {
929 web_data_service->EmptyMigrationTrash(false); 932 autofill_data->EmptyMigrationTrash(false);
930 } else if (sync_service->ShouldPushChanges()) { 933 } else if (sync_service->ShouldPushChanges()) {
931 web_data_service->EmptyMigrationTrash(true); 934 autofill_data->EmptyMigrationTrash(true);
932 } else { 935 } else {
933 // Install ourself as a listener so we can empty the trash once the 936 // Install ourself as a listener so we can empty the trash once the
934 // sync service becomes available. 937 // sync service becomes available.
935 if (!sync_service->HasObserver(this)) 938 if (!sync_service->HasObserver(this))
936 sync_service->AddObserver(this); 939 sync_service->AddObserver(this);
937 } 940 }
938 } 941 }
939 942
940 void PersonalDataManager::LogProfileCount() const { 943 void PersonalDataManager::LogProfileCount() const {
941 if (!has_logged_profile_count_) { 944 if (!has_logged_profile_count_) {
942 metric_logger_->LogStoredProfileCount(web_profiles_.size()); 945 metric_logger_->LogStoredProfileCount(web_profiles_.size());
943 has_logged_profile_count_ = true; 946 has_logged_profile_count_ = true;
944 } 947 }
945 } 948 }
946 949
947 const AutofillMetrics* PersonalDataManager::metric_logger() const { 950 const AutofillMetrics* PersonalDataManager::metric_logger() const {
948 return metric_logger_.get(); 951 return metric_logger_.get();
949 } 952 }
950 953
951 void PersonalDataManager::set_metric_logger( 954 void PersonalDataManager::set_metric_logger(
952 const AutofillMetrics* metric_logger) { 955 const AutofillMetrics* metric_logger) {
953 metric_logger_.reset(metric_logger); 956 metric_logger_.reset(metric_logger);
954 } 957 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698