Chromium Code Reviews| 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 f6c082877abb7020e4ba0dbdc664a5097d735eb5..c367b29080d6a97da5cf54ae218181e4b963cf8d 100644 |
| --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
| +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
| @@ -113,7 +113,7 @@ const char kAutofillDialogOrigin[] = "Chrome Autofill dialog"; |
| const color_utils::HSL kGrayImageShift = {-1, 0, 0.8}; |
| // Limit Wallet items refresh rate to at most once per minute. |
| -const int kWalletItemsRefreshRateSeconds = 60; |
| +const int64 kWalletItemsRefreshRateSeconds = 60; |
| // The number of milliseconds to delay enabling the submit button after showing |
| // the dialog. This delay prevents users from accidentally clicking the submit |
| @@ -701,9 +701,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(); |
| @@ -717,7 +715,7 @@ void AutofillDialogControllerImpl::Hide() { |
| void AutofillDialogControllerImpl::TabActivated() { |
| // If the user switched away from this tab and then switched back, reload the |
| // Wallet items, in case they've changed. |
| - int seconds_elapsed_since_last_refresh = |
| + int64 seconds_elapsed_since_last_refresh = |
| (base::TimeTicks::Now() - last_wallet_items_fetch_timestamp_).InSeconds(); |
| if (IsPayingWithWallet() && wallet_items_ && |
| seconds_elapsed_since_last_refresh >= kWalletItemsRefreshRateSeconds) { |
| @@ -975,7 +973,7 @@ AutofillDialogControllerImpl::DialogSignedInState |
| if (wallet_error_notification_) |
| return SIGN_IN_DISABLED; |
| - if (signin_helper_ || !wallet_items_) |
| + if (signin_helper_ || username_fetcher_ || !wallet_items_) |
| return REQUIRES_RESPONSE; |
| if (wallet_items_->HasRequiredAction(wallet::GAIA_AUTH)) |
| @@ -992,9 +990,9 @@ 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( |
| + username_fetcher_.reset(new wallet::WalletSigninHelper( |
|
Evan Stade
2013/09/23 18:13:44
DCHECK(!username_fetcher_)
Ilya Sherman
2013/09/24 00:50:59
Done.
|
| this, profile_->GetRequestContext())); |
| - signin_helper_->StartUserNameFetch(); |
| + username_fetcher_->StartUserNameFetch(); |
| } else { |
| LogDialogLatencyToShow(); |
| } |
| @@ -1007,9 +1005,12 @@ void AutofillDialogControllerImpl::SignedInStateUpdated() { |
| break; |
| case REQUIRES_PASSIVE_SIGN_IN: |
| + // Cancel any pending username fetch and clear any stale username data. |
| + username_fetcher_.reset(); |
|
Evan Stade
2013/09/23 18:13:44
I don't think username_fetcher_ can be non-null he
Ilya Sherman
2013/09/24 00:50:59
Oops, that was a bug in SignedInState(). It ought
|
| + 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())); |
| @@ -2096,9 +2097,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(); |
| } |
| } |
| @@ -2223,7 +2222,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(); |
| } |
| @@ -2232,6 +2231,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(); |
| } |
| @@ -2239,7 +2239,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( |
| @@ -2366,6 +2372,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, |
| @@ -2475,7 +2486,6 @@ bool AutofillDialogControllerImpl::IsManuallyEditingSection( |
| } |
| void AutofillDialogControllerImpl::OnWalletSigninError() { |
| - signin_helper_.reset(); |
| account_chooser_model_.SetHadWalletSigninError(); |
| GetWalletClient()->CancelRequests(); |
| LogDialogLatencyToShow(); |
| @@ -2484,6 +2494,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(); |
| @@ -3410,4 +3421,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 |