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

Unified Diff: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc

Issue 23653052: [rAc] Fetch username concurrently with fetching Wallet items. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests to not assume the account chooser menu model always exists. Created 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
index 3be137c8279e9facf499a1e2064305d83ad18aea..78e9004a6b779e97e489a4cda39f00a4da7ac2be 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
@@ -704,9 +704,7 @@ void AutofillDialogControllerImpl::Show() {
// Try to see if the user is already signed-in. If signed-in, fetch the user's
// Wallet data. Otherwise, see if the user could be signed in passively.
// TODO(aruslan): UMA metrics for sign-in.
- signin_helper_.reset(new wallet::WalletSigninHelper(
- this, profile_->GetRequestContext()));
- signin_helper_->StartWalletCookieValueFetch();
+ FetchWalletCookieAndUserName();
if (!account_chooser_model_.WalletIsSelected())
LogDialogLatencyToShow();
@@ -987,6 +985,11 @@ AutofillDialogControllerImpl::DialogSignedInState
if (wallet_items_->HasRequiredAction(wallet::PASSIVE_GAIA_AUTH))
return REQUIRES_PASSIVE_SIGN_IN;
+ // Since the username can be pre-fetched as a performance optimization, Wallet
+ // required actions take precedence over a pending username fetch.
+ if (username_fetcher_)
+ return REQUIRES_RESPONSE;
+
return SIGNED_IN;
}
@@ -995,9 +998,10 @@ void AutofillDialogControllerImpl::SignedInStateUpdated() {
case SIGNED_IN:
// Start fetching the user name if we don't know it yet.
if (account_chooser_model_.active_wallet_account_name().empty()) {
- signin_helper_.reset(new wallet::WalletSigninHelper(
+ DCHECK(!username_fetcher_);
+ username_fetcher_.reset(new wallet::WalletSigninHelper(
this, profile_->GetRequestContext()));
- signin_helper_->StartUserNameFetch();
+ username_fetcher_->StartUserNameFetch();
} else {
LogDialogLatencyToShow();
}
@@ -1006,13 +1010,18 @@ void AutofillDialogControllerImpl::SignedInStateUpdated() {
case REQUIRES_SIGN_IN:
case SIGN_IN_DISABLED:
// Switch to the local account and refresh the dialog.
+ signin_helper_.reset();
+ username_fetcher_.reset();
OnWalletSigninError();
break;
case REQUIRES_PASSIVE_SIGN_IN:
+ // Cancel any pending username fetch and clear any stale username data.
+ username_fetcher_.reset();
+ account_chooser_model_.ClearActiveWalletAccountName();
+
// Attempt to passively sign in the user.
DCHECK(!signin_helper_);
- account_chooser_model_.ClearActiveWalletAccountName();
signin_helper_.reset(new wallet::WalletSigninHelper(
this,
profile_->GetRequestContext()));
@@ -1305,7 +1314,8 @@ ui::MenuModel* AutofillDialogControllerImpl::MenuModelForAccountChooser() {
// If there were unrecoverable Wallet errors, or if there are choices other
// than "Pay without the wallet", show the full menu.
if (wallet_error_notification_ ||
- account_chooser_model_.HasAccountsToChoose()) {
+ (SignedInState() == SIGNED_IN &&
+ account_chooser_model_.HasAccountsToChoose())) {
return &account_chooser_model_;
}
@@ -2099,9 +2109,7 @@ void AutofillDialogControllerImpl::Observe(
content::Details<content::LoadCommittedDetails>(details).ptr();
if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) {
account_chooser_model_.SelectActiveWalletAccount();
- signin_helper_.reset(new wallet::WalletSigninHelper(
- this, profile_->GetRequestContext()));
- signin_helper_->StartWalletCookieValueFetch();
+ FetchWalletCookieAndUserName();
HideSignIn();
}
}
@@ -2226,7 +2234,7 @@ void AutofillDialogControllerImpl::OnUserNameFetchSuccess(
const std::string& username) {
ScopedViewUpdates updates(view_.get());
const string16 username16 = UTF8ToUTF16(username);
- signin_helper_.reset();
+ username_fetcher_.reset();
account_chooser_model_.SetActiveWalletAccountName(username16);
OnWalletOrSigninUpdate();
}
@@ -2235,6 +2243,7 @@ void AutofillDialogControllerImpl::OnPassiveSigninFailure(
const GoogleServiceAuthError& error) {
// TODO(aruslan): report an error.
LOG(ERROR) << "failed to passively sign in: " << error.ToString();
+ signin_helper_.reset();
OnWalletSigninError();
}
@@ -2242,7 +2251,13 @@ void AutofillDialogControllerImpl::OnUserNameFetchFailure(
const GoogleServiceAuthError& error) {
// TODO(aruslan): report an error.
LOG(ERROR) << "failed to fetch the user account name: " << error.ToString();
- OnWalletSigninError();
+ username_fetcher_.reset();
+ // Only treat the failed fetch as an error if the user is known to already be
+ // signed in. Attempting to fetch the username prior to loading the
+ // |wallet_items_| is purely a performance optimization that shouldn't be
+ // treated as an error if it fails.
+ if (wallet_items_)
+ OnWalletSigninError();
}
void AutofillDialogControllerImpl::OnDidFetchWalletCookieValue(
@@ -2369,6 +2384,11 @@ void AutofillDialogControllerImpl::SubmitButtonDelayEndForTesting() {
submit_button_delay_timer_.Stop();
}
+void AutofillDialogControllerImpl::
+ ClearLastWalletItemsFetchTimestampForTesting() {
+ last_wallet_items_fetch_timestamp_ = base::TimeTicks();
+}
+
AutofillDialogControllerImpl::AutofillDialogControllerImpl(
content::WebContents* contents,
const FormData& form_structure,
@@ -2478,7 +2498,6 @@ bool AutofillDialogControllerImpl::IsManuallyEditingSection(
}
void AutofillDialogControllerImpl::OnWalletSigninError() {
- signin_helper_.reset();
account_chooser_model_.SetHadWalletSigninError();
GetWalletClient()->CancelRequests();
LogDialogLatencyToShow();
@@ -2487,6 +2506,7 @@ void AutofillDialogControllerImpl::OnWalletSigninError() {
void AutofillDialogControllerImpl::DisableWallet(
wallet::WalletClient::ErrorType error_type) {
signin_helper_.reset();
+ username_fetcher_.reset();
wallet_items_.reset();
wallet_errors_.clear();
GetWalletClient()->CancelRequests();
@@ -2672,6 +2692,9 @@ void AutofillDialogControllerImpl::SuggestionsUpdated() {
for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
DialogSection section = static_cast<DialogSection>(i);
+ if (!SectionIsActive(section))
+ continue;
+
ShowEditUiIfBadSuggestion(section);
UpdateSection(section);
}
@@ -3414,4 +3437,14 @@ void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() {
view_->UpdateButtonStrip();
}
+void AutofillDialogControllerImpl::FetchWalletCookieAndUserName() {
+ net::URLRequestContextGetter* request_context = profile_->GetRequestContext();
+ signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context));
+ signin_helper_->StartWalletCookieValueFetch();
+
+ username_fetcher_.reset(
+ new wallet::WalletSigninHelper(this, request_context));
+ username_fetcher_->StartUserNameFetch();
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698