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

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc

Issue 13331007: Multi-account AccountChooser for interactive autocomplete. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Indent fix. Created 7 years, 8 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/ui/autofill/autofill_dialog_controller_impl.h" 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 return REQUIRES_PASSIVE_SIGN_IN; 462 return REQUIRES_PASSIVE_SIGN_IN;
463 463
464 return SIGNED_IN; 464 return SIGNED_IN;
465 } 465 }
466 466
467 bool AutofillDialogControllerImpl::ShouldShowSpinner() const { 467 bool AutofillDialogControllerImpl::ShouldShowSpinner() const {
468 return IsPayingWithWallet() && SignedInState() == REQUIRES_RESPONSE; 468 return IsPayingWithWallet() && SignedInState() == REQUIRES_RESPONSE;
469 } 469 }
470 470
471 string16 AutofillDialogControllerImpl::AccountChooserText() const { 471 string16 AutofillDialogControllerImpl::AccountChooserText() const {
472 // TODO(aruslan): this should be l10n "Not using Google Wallet".
472 if (!IsPayingWithWallet()) 473 if (!IsPayingWithWallet())
473 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET); 474 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET);
474 475
475 // TODO(dbeam): real strings and l10n.
476 if (SignedInState() == SIGNED_IN) 476 if (SignedInState() == SIGNED_IN)
477 return ASCIIToUTF16(current_username_); 477 return ASCIIToUTF16(account_chooser_model_.GetCurrentlySignedInAccount());
478 478
479 // In this case, the account chooser should be showing the signin link. 479 // In this case, the account chooser should be showing the signin link.
480 return string16(); 480 return string16();
481 } 481 }
482 482
483 string16 AutofillDialogControllerImpl::SignInLinkText() const { 483 string16 AutofillDialogControllerImpl::SignInLinkText() const {
484 // TODO(estade): real strings and l10n. 484 // TODO(estade): real strings and l10n.
485 return ASCIIToUTF16("Sign in to use Google Wallet"); 485 return ASCIIToUTF16("Sign in to use Google Wallet");
486 } 486 }
487 487
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 std::vector<wallet::WalletClient::RiskCapability>()); 535 std::vector<wallet::WalletClient::RiskCapability>());
536 } 536 }
537 537
538 void AutofillDialogControllerImpl::OnWalletOrSigninUpdate() { 538 void AutofillDialogControllerImpl::OnWalletOrSigninUpdate() {
539 if (wallet_items_.get()) { 539 if (wallet_items_.get()) {
540 DCHECK(IsPayingWithWallet()); 540 DCHECK(IsPayingWithWallet());
541 DCHECK(!signin_helper_.get()); 541 DCHECK(!signin_helper_.get());
542 switch (SignedInState()) { 542 switch (SignedInState()) {
543 case SIGNED_IN: 543 case SIGNED_IN:
544 // Start fetching the user name if we don't know it yet. 544 // Start fetching the user name if we don't know it yet.
545 if (current_username_.empty()) { 545 if (account_chooser_model_.GetCurrentlySignedInAccount().empty()) {
546 signin_helper_.reset(new wallet::WalletSigninHelper( 546 signin_helper_.reset(new wallet::WalletSigninHelper(
547 this, 547 this,
548 profile_->GetRequestContext())); 548 profile_->GetRequestContext()));
549 signin_helper_->StartUserNameFetch(); 549 signin_helper_->StartUserNameFetch();
550 } 550 }
551 break; 551 break;
552 552
553 case REQUIRES_SIGN_IN: 553 case REQUIRES_SIGN_IN:
554 // TODO(aruslan): automatic sign-in? 554 // Switch to the local account and refresh the dialog.
555 OnWalletSigninError();
555 break; 556 break;
556 557
557 case REQUIRES_PASSIVE_SIGN_IN: 558 case REQUIRES_PASSIVE_SIGN_IN:
558 // Attempt to passively sign in the user. 559 // Attempt to passively sign in the user.
559 current_username_.clear(); 560 account_chooser_model_.ResetCurrentlySignedInAccount();
560 signin_helper_.reset(new wallet::WalletSigninHelper( 561 signin_helper_.reset(new wallet::WalletSigninHelper(
561 this, 562 this,
562 profile_->GetRequestContext())); 563 profile_->GetRequestContext()));
563 signin_helper_->StartPassiveSignin(); 564 signin_helper_->StartPassiveSignin();
564 break; 565 break;
565 566
566 case REQUIRES_RESPONSE: 567 case REQUIRES_RESPONSE:
567 NOTREACHED(); 568 NOTREACHED();
568 } 569 }
569 } 570 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 return NULL; 655 return NULL;
655 } 656 }
656 } 657 }
657 658
658 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection( 659 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection(
659 DialogSection section) { 660 DialogSection section) {
660 return SuggestionsMenuModelForSection(section); 661 return SuggestionsMenuModelForSection(section);
661 } 662 }
662 663
663 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForAccountChooser() { 664 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForAccountChooser() {
664 // When paying with wallet, but not signed in, there is no menu, just a 665 // If the only choice is "Pay without the wallet", there is no menu, just
665 // sign in link. 666 // a sign in link.
666 if (IsPayingWithWallet() && SignedInState() != SIGNED_IN) 667 if (!account_chooser_model_.HasAccountsToChoose())
667 return NULL; 668 return NULL;
668 669
669 return &account_chooser_model_; 670 return &account_chooser_model_;
670 } 671 }
671 672
672 gfx::Image AutofillDialogControllerImpl::AccountChooserImage() { 673 gfx::Image AutofillDialogControllerImpl::AccountChooserImage() {
673 if (!MenuModelForAccountChooser()) { 674 if (!MenuModelForAccountChooser()) {
674 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( 675 return ui::ResourceBundle::GetSharedInstance().GetImageNamed(
675 IDR_WALLET_ICON); 676 IDR_WALLET_ICON);
676 } 677 }
677 678
678 gfx::Image icon; 679 gfx::Image icon;
679 account_chooser_model_.GetIconAt(account_chooser_model_.checked_item(), 680 account_chooser_model_.GetIconAt(
680 &icon); 681 account_chooser_model_.GetIndexOfCommandId(
682 account_chooser_model_.checked_item()),
683 &icon);
681 return icon; 684 return icon;
682 } 685 }
683 686
684 string16 AutofillDialogControllerImpl::LabelForSection(DialogSection section) 687 string16 AutofillDialogControllerImpl::LabelForSection(DialogSection section)
685 const { 688 const {
686 switch (section) { 689 switch (section) {
687 case SECTION_EMAIL: 690 case SECTION_EMAIL:
688 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_EMAIL); 691 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_EMAIL);
689 case SECTION_CC: 692 case SECTION_CC:
690 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_CC); 693 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_CC);
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 DialogNotification::WALLET_ERROR, 1099 DialogNotification::WALLET_ERROR,
1097 l10n_util::GetStringFUTF16( 1100 l10n_util::GetStringFUTF16(
1098 IDS_AUTOFILL_DIALOG_COMPLETE_WITHOUT_WALLET, 1101 IDS_AUTOFILL_DIALOG_COMPLETE_WITHOUT_WALLET,
1099 ASCIIToUTF16("Oops, [Wallet-Error].")))); 1102 ASCIIToUTF16("Oops, [Wallet-Error]."))));
1100 } 1103 }
1101 1104
1102 return notifications; 1105 return notifications;
1103 } 1106 }
1104 1107
1105 void AutofillDialogControllerImpl::StartSignInFlow() { 1108 void AutofillDialogControllerImpl::StartSignInFlow() {
1109 DCHECK(!IsPayingWithWallet());
1106 DCHECK(registrar_.IsEmpty()); 1110 DCHECK(registrar_.IsEmpty());
1107 1111
1108 content::Source<content::NavigationController> source(view_->ShowSignIn()); 1112 content::Source<content::NavigationController> source(view_->ShowSignIn());
1109 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source); 1113 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source);
1110 } 1114 }
1111 1115
1112 void AutofillDialogControllerImpl::EndSignInFlow() { 1116 void AutofillDialogControllerImpl::EndSignInFlow() {
1113 DCHECK(!registrar_.IsEmpty()); 1117 DCHECK(!registrar_.IsEmpty());
1114 registrar_.RemoveAll(); 1118 registrar_.RemoveAll();
1115 view_->HideSignIn(); 1119 view_->HideSignIn();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 1240
1237 void AutofillDialogControllerImpl::Observe( 1241 void AutofillDialogControllerImpl::Observe(
1238 int type, 1242 int type,
1239 const content::NotificationSource& source, 1243 const content::NotificationSource& source,
1240 const content::NotificationDetails& details) { 1244 const content::NotificationDetails& details) {
1241 DCHECK_EQ(type, content::NOTIFICATION_NAV_ENTRY_COMMITTED); 1245 DCHECK_EQ(type, content::NOTIFICATION_NAV_ENTRY_COMMITTED);
1242 content::LoadCommittedDetails* load_details = 1246 content::LoadCommittedDetails* load_details =
1243 content::Details<content::LoadCommittedDetails>(details).ptr(); 1247 content::Details<content::LoadCommittedDetails>(details).ptr();
1244 if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) { 1248 if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) {
1245 EndSignInFlow(); 1249 EndSignInFlow();
1246 if (IsPayingWithWallet()) 1250 // The sign-in flow means that the user implicitly switched the account
1247 StartFetchingWalletItems(); 1251 // to the Wallet. This will trigger AccountChoiceChanged.
1252 DCHECK(!IsPayingWithWallet());
1253 account_chooser_model_.ForceSelectWalletAccount();
1248 } 1254 }
1249 } 1255 }
1250 1256
1251 //////////////////////////////////////////////////////////////////////////////// 1257 ////////////////////////////////////////////////////////////////////////////////
1252 // SuggestionsMenuModelDelegate implementation. 1258 // SuggestionsMenuModelDelegate implementation.
1253 1259
1254 void AutofillDialogControllerImpl::SuggestionItemSelected( 1260 void AutofillDialogControllerImpl::SuggestionItemSelected(
1255 const SuggestionsMenuModel& model) { 1261 const SuggestionsMenuModel& model) {
1256 const DialogSection section = SectionForSuggestionsMenuModel(model); 1262 const DialogSection section = SectionForSuggestionsMenuModel(model);
1257 EditCancelledForSection(section); 1263 EditCancelledForSection(section);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 1299
1294 if (full_wallet_->HasRequiredAction(wallet::VERIFY_CVV)) 1300 if (full_wallet_->HasRequiredAction(wallet::VERIFY_CVV))
1295 DisableWallet(); 1301 DisableWallet();
1296 else 1302 else
1297 FinishSubmit(); 1303 FinishSubmit();
1298 } 1304 }
1299 1305
1300 void AutofillDialogControllerImpl::OnPassiveSigninSuccess( 1306 void AutofillDialogControllerImpl::OnPassiveSigninSuccess(
1301 const std::string& username) { 1307 const std::string& username) {
1302 DCHECK(IsPayingWithWallet()); 1308 DCHECK(IsPayingWithWallet());
1303 current_username_ = username; 1309 account_chooser_model_.SetCurrentlySignedInAccount(username);
1304 signin_helper_.reset(); 1310 signin_helper_.reset();
1305 wallet_items_.reset(); 1311 wallet_items_.reset();
1306 StartFetchingWalletItems(); 1312 StartFetchingWalletItems();
1307 } 1313 }
1308 1314
1309 void AutofillDialogControllerImpl::OnUserNameFetchSuccess( 1315 void AutofillDialogControllerImpl::OnUserNameFetchSuccess(
1310 const std::string& username) { 1316 const std::string& username) {
1311 DCHECK(IsPayingWithWallet()); 1317 DCHECK(IsPayingWithWallet());
1312 current_username_ = username; 1318 account_chooser_model_.SetCurrentlySignedInAccount(username);
1313 signin_helper_.reset(); 1319 signin_helper_.reset();
1314 OnWalletOrSigninUpdate(); 1320 OnWalletOrSigninUpdate();
1315 } 1321 }
1316 1322
1317 void AutofillDialogControllerImpl::OnAutomaticSigninSuccess( 1323 void AutofillDialogControllerImpl::OnAutomaticSigninSuccess(
1318 const std::string& username) { 1324 const std::string& username) {
1319 // TODO(aruslan): automatic sign-in. 1325 // TODO(aruslan): automatic sign-in.
1320 NOTIMPLEMENTED(); 1326 NOTIMPLEMENTED();
1321 } 1327 }
1322 1328
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 void AutofillDialogControllerImpl::OnPersonalDataChanged() { 1414 void AutofillDialogControllerImpl::OnPersonalDataChanged() {
1409 HidePopup(); 1415 HidePopup();
1410 GenerateSuggestionsModels(); 1416 GenerateSuggestionsModels();
1411 view_->ModelChanged(); 1417 view_->ModelChanged();
1412 } 1418 }
1413 1419
1414 void AutofillDialogControllerImpl::AccountChoiceChanged() { 1420 void AutofillDialogControllerImpl::AccountChoiceChanged() {
1415 if (!view_) 1421 if (!view_)
1416 return; 1422 return;
1417 1423
1418 // Whenever the user changes the current account, the Wallet data should be 1424 // The Wallet data should be cleared when the user switches accounts.
1419 // cleared. If the user has chosen a Wallet account, an attempt to fetch
1420 // the Wallet data is made to see if the user is still signed in.
1421 // This will trigger a passive sign-in if required.
1422 // TODO(aruslan): integrate an automatic sign-in.
1423 wallet_items_.reset(); 1425 wallet_items_.reset();
1424 if (IsPayingWithWallet()) 1426 if (IsPayingWithWallet()) {
1425 StartFetchingWalletItems(); 1427 if (account_chooser_model_.IsCurrentlySignedInAccountSelected()) {
1428 // If the user has chosen a content-area Wallet account, an attempt to
1429 // fetch the Wallet data is made to see if the user is still signed in.
1430 // This will trigger a passive sign-in if required.
1431 StartFetchingWalletItems();
1432 } else {
1433 // TODO(aruslan): integrate an automatic sign-in.
1434 OnWalletSigninError();
1435 }
1436 }
1426 1437
1427 GenerateSuggestionsModels(); 1438 GenerateSuggestionsModels();
1428 view_->ModelChanged(); 1439 view_->ModelChanged();
1429 view_->UpdateAccountChooser(); 1440 view_->UpdateAccountChooser();
1430 view_->UpdateNotificationArea(); 1441 view_->UpdateNotificationArea();
1431 } 1442 }
1432 1443
1433 //////////////////////////////////////////////////////////////////////////////// 1444 ////////////////////////////////////////////////////////////////////////////////
1434 1445
1435 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput( 1446 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1468 wallet::WalletClient* AutofillDialogControllerImpl::GetWalletClient() { 1479 wallet::WalletClient* AutofillDialogControllerImpl::GetWalletClient() {
1469 return &wallet_client_; 1480 return &wallet_client_;
1470 } 1481 }
1471 1482
1472 bool AutofillDialogControllerImpl::IsPayingWithWallet() const { 1483 bool AutofillDialogControllerImpl::IsPayingWithWallet() const {
1473 return account_chooser_model_.WalletIsSelected(); 1484 return account_chooser_model_.WalletIsSelected();
1474 } 1485 }
1475 1486
1476 void AutofillDialogControllerImpl::DisableWallet() { 1487 void AutofillDialogControllerImpl::DisableWallet() {
1477 signin_helper_.reset(); 1488 signin_helper_.reset();
1478 current_username_.clear();
1479 account_chooser_model_.SetHadWalletError(); 1489 account_chooser_model_.SetHadWalletError();
1480 GetWalletClient()->CancelPendingRequests(); 1490 GetWalletClient()->CancelPendingRequests();
1481 } 1491 }
1482 1492
1483 void AutofillDialogControllerImpl::OnWalletSigninError() { 1493 void AutofillDialogControllerImpl::OnWalletSigninError() {
1484 signin_helper_.reset(); 1494 signin_helper_.reset();
1485 current_username_.clear();
1486 account_chooser_model_.SetHadWalletSigninError(); 1495 account_chooser_model_.SetHadWalletSigninError();
1487 GetWalletClient()->CancelPendingRequests(); 1496 GetWalletClient()->CancelPendingRequests();
1488 } 1497 }
1489 1498
1490 bool AutofillDialogControllerImpl::IsFirstRun() const { 1499 bool AutofillDialogControllerImpl::IsFirstRun() const {
1491 PrefService* prefs = profile_->GetPrefs(); 1500 PrefService* prefs = profile_->GetPrefs();
1492 return !prefs->HasPrefPath(prefs::kAutofillDialogPayWithoutWallet); 1501 return !prefs->HasPrefPath(prefs::kAutofillDialogPayWithoutWallet);
1493 } 1502 }
1494 1503
1495 void AutofillDialogControllerImpl::GenerateSuggestionsModels() { 1504 void AutofillDialogControllerImpl::GenerateSuggestionsModels() {
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
1927 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; 1936 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL;
1928 } 1937 }
1929 1938
1930 // Has Wallet items. 1939 // Has Wallet items.
1931 return has_autofill_profiles ? 1940 return has_autofill_profiles ?
1932 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : 1941 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL :
1933 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; 1942 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL;
1934 } 1943 }
1935 1944
1936 } // namespace autofill 1945 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698