diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-12 05:56:05 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-12 05:56:05 +0000 |
commit | a149e538e6f3b866b405d96bdf89dd69e428ae67 (patch) | |
tree | 163467b600f22b143c9b4e1b96b8e58366ee3a64 | |
parent | 84af9ad2925ec51b3eb9c1b6c8738df1fae2025d (diff) | |
download | chromium_src-a149e538e6f3b866b405d96bdf89dd69e428ae67.zip chromium_src-a149e538e6f3b866b405d96bdf89dd69e428ae67.tar.gz chromium_src-a149e538e6f3b866b405d96bdf89dd69e428ae67.tar.bz2 |
rAc: Switch to using getWalletItems for logged in accounts.
Stop relying on toolbar's getaccountinfo. To keep the change minimal, don't actually support multiple accounts yet (stick to /u/0).
BUG=247755
Review URL: https://codereview.chromium.org/67463002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@234423 0039d316-1c4b-4281-b951-d872f2087c98
13 files changed, 132 insertions, 398 deletions
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc index 4446c83..57d940a 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc @@ -845,9 +845,6 @@ IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, MAYBE_PreservedSections) { EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); // Set up some Wallet state. - std::vector<std::string> usernames; - usernames.push_back("user@example.com"); - controller()->OnUserNameFetchSuccess(usernames); controller()->OnDidFetchWalletCookieValue(std::string()); controller()->OnDidGetWalletItems( wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); @@ -911,8 +908,6 @@ IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, MAYBE_PreservedSections) { IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, GeneratedCardLastFourAfterVerifyCvv) { - std::vector<std::string> usernames(1, "user@example.com"); - controller()->OnUserNameFetchSuccess(usernames); controller()->OnDidFetchWalletCookieValue(std::string()); scoped_ptr<wallet::WalletItems> wallet_items = @@ -972,8 +967,6 @@ IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, SimulateSuccessfulSignIn) { InitializeController(); controller()->OnDidFetchWalletCookieValue(std::string()); - controller()->OnUserNameFetchFailure(GoogleServiceAuthError( - GoogleServiceAuthError::USER_NOT_SIGNED_UP)); controller()->OnDidGetWalletItems( wallet::GetTestWalletItemsWithRequiredAction(wallet::GAIA_AUTH)); @@ -1015,8 +1008,6 @@ IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, SimulateSuccessfulSignIn) { controller()->OnDidGetWalletItems( wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); - std::vector<std::string> usernames(1, "user@example.com"); - controller()->OnUserNameFetchSuccess(usernames); // Wallet should now be selected and Chrome shouldn't have crashed (which can // happen if the WebContents is deleted while proccessing a nav entry commit). diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc index 2f8b256..cf3c1a0 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc @@ -660,7 +660,7 @@ void AutofillDialogControllerImpl::Show() { LogDialogLatencyToShow(); } else { // TODO(aruslan): UMA metrics for sign-in. - FetchWalletCookieAndUserName(); + FetchWalletCookie(); } } @@ -945,11 +945,6 @@ 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; } @@ -959,15 +954,7 @@ void AutofillDialogControllerImpl::SignedInStateUpdated() { switch (SignedInState()) { case SIGNED_IN: - // Start fetching the user name if we don't know it yet. - if (!account_chooser_model_.HasAccountsToChoose()) { - DCHECK(!username_fetcher_); - username_fetcher_.reset(new wallet::WalletSigninHelper( - this, profile_->GetRequestContext())); - username_fetcher_->StartUserNameFetch(); - } else { - LogDialogLatencyToShow(); - } + LogDialogLatencyToShow(); break; case REQUIRES_SIGN_IN: @@ -977,16 +964,11 @@ void AutofillDialogControllerImpl::SignedInStateUpdated() { case SIGN_IN_DISABLED: // Switch to the local account and refresh the dialog. signin_helper_.reset(); - username_fetcher_.reset(); OnWalletSigninError(); handling_use_wallet_link_click_ = false; break; case REQUIRES_PASSIVE_SIGN_IN: - // Cancel any pending username fetch and clear any stale username data. - username_fetcher_.reset(); - account_chooser_model_.ClearWalletAccounts(); - // Attempt to passively sign in the user. DCHECK(!signin_helper_); signin_helper_.reset(new wallet::WalletSigninHelper( @@ -2057,7 +2039,7 @@ void AutofillDialogControllerImpl::SignInLinkClicked() { if (SignedInState() == NOT_CHECKED) { handling_use_wallet_link_click_ = true; account_chooser_model_.SelectActiveWalletAccount(); - FetchWalletCookieAndUserName(); + FetchWalletCookie(); view_->UpdateAccountChooser(); } else if (signin_registrar_.IsEmpty()) { // Start sign in. @@ -2236,7 +2218,7 @@ void AutofillDialogControllerImpl::Observe( if (IsSignInContinueUrl(load_details->entry->GetVirtualURL())) { // TODO(estade): will need to update this when we fix <crbug.com/247755>. account_chooser_model_.SelectActiveWalletAccount(); - FetchWalletCookieAndUserName(); + FetchWalletCookie(); // NOTE: |HideSignIn()| may delete the WebContents which doesn't expect to // be deleted while committing a nav entry. Just call |HideSignIn()| later. @@ -2360,28 +2342,8 @@ void AutofillDialogControllerImpl::OnDidGetFullWallet( view_->UpdateOverlay(); } -void AutofillDialogControllerImpl::OnPassiveSigninSuccess( - const std::vector<std::string>& usernames) { - // TODO(estade): for now, we still only support single user login. - std::vector<std::string> username; - if (!usernames.empty()) - username.push_back(usernames[0]); - account_chooser_model_.SetWalletAccounts(username); - signin_helper_->StartWalletCookieValueFetch(); -} - -void AutofillDialogControllerImpl::OnUserNameFetchSuccess( - const std::vector<std::string>& usernames) { - ScopedViewUpdates updates(view_.get()); - - // TODO(estade): for now, we still only support single user login. - std::vector<std::string> username; - if (!usernames.empty()) - username.push_back(usernames[0]); - - account_chooser_model_.SetWalletAccounts(username); - username_fetcher_.reset(); - OnWalletOrSigninUpdate(); +void AutofillDialogControllerImpl::OnPassiveSigninSuccess() { + FetchWalletCookie(); } void AutofillDialogControllerImpl::OnPassiveSigninFailure( @@ -2392,19 +2354,6 @@ void AutofillDialogControllerImpl::OnPassiveSigninFailure( OnWalletSigninError(); } -void AutofillDialogControllerImpl::OnUserNameFetchFailure( - const GoogleServiceAuthError& error) { - // TODO(aruslan): report an error. - LOG(ERROR) << "failed to fetch the user account name: " << error.ToString(); - 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( const std::string& cookie_value) { wallet_cookie_value_ = cookie_value; @@ -2419,6 +2368,13 @@ void AutofillDialogControllerImpl::OnDidGetWalletItems( has_accepted_legal_documents_ = false; wallet_items_ = wallet_items.Pass(); + + // TODO(estade): support multiple users. http://crbug.com/247755 + std::vector<std::string> username; + if (wallet_items_ && !wallet_items_->gaia_accounts().empty()) + username.push_back(wallet_items_->gaia_accounts()[0]); + account_chooser_model_.SetWalletAccounts(username); + ConstructLegalDocumentsText(); OnWalletOrSigninUpdate(); } @@ -2684,7 +2640,6 @@ 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(); @@ -3579,14 +3534,10 @@ void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() { view_->UpdateButtonStrip(); } -void AutofillDialogControllerImpl::FetchWalletCookieAndUserName() { +void AutofillDialogControllerImpl::FetchWalletCookie() { 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 diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h index 0752609..fe65abf 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h @@ -210,14 +210,9 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate, virtual void UpdateAccountChooserView() OVERRIDE; // wallet::WalletSigninHelperDelegate implementation. - virtual void OnPassiveSigninSuccess(const std::vector<std::string>& username) - OVERRIDE; + virtual void OnPassiveSigninSuccess() OVERRIDE; virtual void OnPassiveSigninFailure( const GoogleServiceAuthError& error) OVERRIDE; - virtual void OnUserNameFetchSuccess(const std::vector<std::string>& username) - OVERRIDE; - virtual void OnUserNameFetchFailure( - const GoogleServiceAuthError& error) OVERRIDE; virtual void OnDidFetchWalletCookieValue( const std::string& cookie_value) OVERRIDE; @@ -570,8 +565,8 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate, // Called when the delay for enabling the submit button ends. void OnSubmitButtonDelayEnd(); - // Initiates a fetch of the user's current Wallet cookie and Google username. - void FetchWalletCookieAndUserName(); + // Gets the user's current Wallet cookie (gdToken) from the cookie jar. + void FetchWalletCookie(); // The |profile| for |contents_|. Profile* const profile_; @@ -601,10 +596,6 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate, // sign-in. The helper is set only during fetch/sign-in, and NULL otherwise. scoped_ptr<wallet::WalletSigninHelper> signin_helper_; - // The sign-in helper to fetch the user's human-readable username. The helper - // is set only while fetching the username, and NULL otherwise. - scoped_ptr<wallet::WalletSigninHelper> username_fetcher_; - // A client to talk to the Online Wallet API. wallet::WalletClient wallet_client_; diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc index 108108b..14ab0ce 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc @@ -432,9 +432,6 @@ class AutofillDialogControllerTest : public ChromeRenderViewHostTestHarness { // data for it. void SetUpControllerWithFormData(const FormData& form_data) { ResetControllerWithFormData(form_data); - std::vector<std::string> usernames; - usernames.push_back(kFakeEmail); - controller_->OnUserNameFetchSuccess(usernames); EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems()); controller_->OnDidFetchWalletCookieValue(std::string()); controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); @@ -2692,9 +2689,6 @@ TEST_F(AutofillDialogControllerTest, DontGetWalletTillNecessary) { controller()->SignInLinkClicked(); EXPECT_NE(TestAutofillDialogController::NOT_CHECKED, controller()->SignedInState()); - std::vector<std::string> usernames; - usernames.push_back(kFakeEmail); - controller()->OnUserNameFetchSuccess(usernames); controller()->OnDidFetchWalletCookieValue(std::string()); controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); controller()->OnPassiveSigninFailure(GoogleServiceAuthError( diff --git a/components/autofill/content/browser/wallet/wallet_items.cc b/components/autofill/content/browser/wallet/wallet_items.cc index fbc49ef..a6d7de3 100644 --- a/components/autofill/content/browser/wallet/wallet_items.cc +++ b/components/autofill/content/browser/wallet/wallet_items.cc @@ -417,13 +417,15 @@ WalletItems::WalletItems(const std::vector<RequiredAction>& required_actions, const std::string& default_instrument_id, const std::string& default_address_id, const std::string& obfuscated_gaia_id, - AmexPermission amex_permission) + AmexPermission amex_permission, + const std::vector<std::string>& gaia_accounts) : required_actions_(required_actions), google_transaction_id_(google_transaction_id), default_instrument_id_(default_instrument_id), default_address_id_(default_address_id), obfuscated_gaia_id_(obfuscated_gaia_id), - amex_permission_(amex_permission) {} + amex_permission_(amex_permission), + gaia_accounts_(gaia_accounts) {} WalletItems::~WalletItems() {} @@ -473,12 +475,30 @@ scoped_ptr<WalletItems> AmexPermission amex_permission = amex_disallowed ? AMEX_DISALLOWED : AMEX_ALLOWED; + std::vector<std::string> gaia_accounts; + const base::ListValue* gaia_profiles; + if (dictionary.GetList("gaia_profile", &gaia_profiles)) { + for (size_t i = 0; i < gaia_profiles->GetSize(); ++i) { + const base::DictionaryValue* account_dict; + std::string email; + if (gaia_profiles->GetDictionary(i, &account_dict) && + account_dict->GetString("buyer_email", &email)) { + gaia_accounts.push_back(email); + } else { + DVLOG(1) << "Response from Google Wallet has malformed GAIA profile."; + } + } + } else { + DVLOG(1) << "Response from Google wallet missing GAIA profiles."; + } + scoped_ptr<WalletItems> wallet_items(new WalletItems(required_action, google_transaction_id, default_instrument_id, default_address_id, obfuscated_gaia_id, - amex_permission)); + amex_permission, + gaia_accounts)); const ListValue* legal_docs; if (dictionary.GetList("required_legal_document", &legal_docs)) { diff --git a/components/autofill/content/browser/wallet/wallet_items.h b/components/autofill/content/browser/wallet/wallet_items.h index 257bbad..32f1118 100644 --- a/components/autofill/content/browser/wallet/wallet_items.h +++ b/components/autofill/content/browser/wallet/wallet_items.h @@ -259,6 +259,9 @@ class WalletItems { const std::vector<Address*>& addresses() const { return addresses_.get(); } const std::string& default_address_id() const { return default_address_id_; } const std::string& obfuscated_gaia_id() const { return obfuscated_gaia_id_; } + const std::vector<std::string>& gaia_accounts() const { + return gaia_accounts_; + } const std::vector<LegalDocument*>& legal_documents() const { return legal_documents_.get(); } @@ -267,7 +270,10 @@ class WalletItems { friend class WalletItemsTest; friend scoped_ptr<WalletItems> GetTestWalletItems( const std::vector<RequiredAction>&, - const std::string&, const std::string&, AmexPermission); + const std::string&, + const std::string&, + AmexPermission, + const std::vector<std::string>&); friend scoped_ptr<WalletItems> GetTestWalletItemsWithDefaultIds( RequiredAction action); FRIEND_TEST_ALL_PREFIXES(WalletItemsTest, CreateWalletItems); @@ -279,7 +285,8 @@ class WalletItems { const std::string& default_instrument_id, const std::string& default_address_id, const std::string& obfuscated_gaia_id, - AmexPermission amex_permission); + AmexPermission amex_permission, + const std::vector<std::string>& gaia_accounts); // Actions that must be completed by the user before a FullWallet can be // issued to them by the Online Wallet service. @@ -309,6 +316,11 @@ class WalletItems { // Whether Google Wallet allows American Express card for this merchant. AmexPermission amex_permission_; + // The complete set of logged in GAIA accounts. This just stores email + // addresses. The actual response has more metadata which we currently + // ignore. + std::vector<std::string> gaia_accounts_; + DISALLOW_COPY_AND_ASSIGN(WalletItems); }; diff --git a/components/autofill/content/browser/wallet/wallet_items_unittest.cc b/components/autofill/content/browser/wallet/wallet_items_unittest.cc index a1b32f6..142c74a 100644 --- a/components/autofill/content/browser/wallet/wallet_items_unittest.cc +++ b/components/autofill/content/browser/wallet/wallet_items_unittest.cc @@ -346,7 +346,32 @@ const char kWalletItems[] = " ]," " \"default_address_id\":\"default_address_id\"," " \"obfuscated_gaia_id\":\"obfuscated_gaia_id\"," - " \"amex_disallowed\":true"; + " \"amex_disallowed\":true," + " \"gaia_profile\":" + " [" + " {" + " \"buyer_email\":\"user@chromium.org\"," + " \"gaia_index\":0," + " \"gaia_id\":\"123456789\"," + " \"buyer_name\":\"Joe Usecase\"," + " \"is_active\":true," + " \"avatar_url_27x27\":\"https://lh3.googleusercontent.com/27.jpg\"," + " \"avatar_url_54x54\":\"https://lh3.googleusercontent.com/54.jpg\"," + " \"avatar_url_48x48\":\"https://lh3.googleusercontent.com/48.jpg\"," + " \"avatar_url_96x96\":\"https://lh3.googleusercontent.com/96.jpg\"" + " }," + " {" + " \"buyer_email\":\"user2@chromium.org\"," + " \"gaia_index\":1," + " \"gaia_id\":\"123456789\"," + " \"buyer_name\":\"Jill Usecase\"," + " \"is_active\":false," + " \"avatar_url_27x27\":\"https://lh3.googleusercontent.com/27.jpg\"," + " \"avatar_url_54x54\":\"https://lh3.googleusercontent.com/54.jpg\"," + " \"avatar_url_48x48\":\"https://lh3.googleusercontent.com/48.jpg\"," + " \"avatar_url_96x96\":\"https://lh3.googleusercontent.com/96.jpg\"" + " }" + " ]"; const char kRequiredLegalDocument[] = " ," @@ -488,7 +513,8 @@ TEST_F(WalletItemsTest, CreateWalletItemsWithRequiredActions) { std::string(), std::string(), std::string(), - AMEX_DISALLOWED); + AMEX_DISALLOWED, + std::vector<std::string>()); EXPECT_EQ(expected, *WalletItems::CreateWalletItems(*dict)); ASSERT_FALSE(required_actions.empty()); @@ -498,7 +524,8 @@ TEST_F(WalletItemsTest, CreateWalletItemsWithRequiredActions) { std::string(), std::string(), std::string(), - AMEX_DISALLOWED); + AMEX_DISALLOWED, + std::vector<std::string>()); EXPECT_NE(expected, different_required_actions); } @@ -525,12 +552,16 @@ TEST_F(WalletItemsTest, CreateWalletItemsMissingAmexDisallowed) { TEST_F(WalletItemsTest, CreateWalletItems) { SetUpDictionary(std::string(kWalletItems) + std::string(kCloseJson)); std::vector<RequiredAction> required_actions; + std::vector<std::string> users; + users.push_back("user@chromium.org"); + users.push_back("user2@chromium.org"); WalletItems expected(required_actions, "google_transaction_id", "default_instrument_id", "default_address_id", "obfuscated_gaia_id", - AMEX_DISALLOWED); + AMEX_DISALLOWED, + users); scoped_ptr<Address> billing_address(new Address("US", ASCIIToUTF16("name"), diff --git a/components/autofill/content/browser/wallet/wallet_signin_helper.cc b/components/autofill/content/browser/wallet/wallet_signin_helper.cc index 304426f1..b16a1cd 100644 --- a/components/autofill/content/browser/wallet/wallet_signin_helper.cc +++ b/components/autofill/content/browser/wallet/wallet_signin_helper.cc @@ -30,11 +30,6 @@ namespace wallet { namespace { -// Toolbar::GetAccountInfo API URL (JSON). -const char kGetAccountInfoUrlFormat[] = - "https://clients1.google.com/tbproxy/getaccountinfo?key=%d&rv=2" - "&requestor=chrome"; - const char kWalletCookieName[] = "gdtoken"; // Callback for retrieving Google Wallet cookies. |callback| is passed the @@ -46,7 +41,7 @@ void GetGoogleCookiesCallback( DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); // Cookies for parent domains will also be returned; we only want cookies with - // exact host matches. + // exact host matches. TODO(estade): really? std::string host = wallet::GetPassiveAuthUrl().host(); std::string wallet_cookie; for (size_t i = 0; i < cookies.size(); ++i) { @@ -97,7 +92,6 @@ WalletSigninHelper::WalletSigninHelper( net::URLRequestContextGetter* getter) : delegate_(delegate), getter_(getter), - state_(IDLE), weak_ptr_factory_(this) { DCHECK(delegate_); } @@ -106,11 +100,8 @@ WalletSigninHelper::~WalletSigninHelper() { } void WalletSigninHelper::StartPassiveSignin() { - DCHECK_EQ(IDLE, state_); DCHECK(!url_fetcher_); - state_ = PASSIVE_EXECUTING_SIGNIN; - emails_.clear(); const GURL& url = wallet::GetPassiveAuthUrl(); url_fetcher_.reset(net::URLFetcher::Create( 0, url, net::URLFetcher::GET, this)); @@ -118,15 +109,6 @@ void WalletSigninHelper::StartPassiveSignin() { url_fetcher_->Start(); } -void WalletSigninHelper::StartUserNameFetch() { - DCHECK_EQ(state_, IDLE); - DCHECK(!url_fetcher_); - - state_ = USERNAME_FETCHING_USERINFO; - emails_.clear(); - StartFetchingUserNameFromSession(); -} - void WalletSigninHelper::StartWalletCookieValueFetch() { scoped_refptr<net::URLRequestContextGetter> request_context(getter_); if (!request_context.get()) { @@ -142,29 +124,8 @@ void WalletSigninHelper::StartWalletCookieValueFetch() { content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, task); } -std::string WalletSigninHelper::GetGetAccountInfoUrlForTesting() const { - return base::StringPrintf(kGetAccountInfoUrlFormat, 0); -} - void WalletSigninHelper::OnServiceError(const GoogleServiceAuthError& error) { - const State state_with_error = state_; - state_ = IDLE; - url_fetcher_.reset(); - - switch(state_with_error) { - case IDLE: - NOTREACHED(); - break; - - case PASSIVE_EXECUTING_SIGNIN: /*FALLTHROUGH*/ - case PASSIVE_FETCHING_USERINFO: - delegate_->OnPassiveSigninFailure(error); - break; - - case USERNAME_FETCHING_USERINFO: - delegate_->OnUserNameFetchFailure(error); - break; - } + delegate_->OnPassiveSigninFailure(error); } void WalletSigninHelper::OnOtherError() { @@ -174,141 +135,33 @@ void WalletSigninHelper::OnOtherError() { void WalletSigninHelper::OnURLFetchComplete( const net::URLFetcher* fetcher) { DCHECK_EQ(url_fetcher_.get(), fetcher); + scoped_ptr<net::URLFetcher> url_fetcher(url_fetcher_.release()); + if (!fetcher->GetStatus().is_success() || fetcher->GetResponseCode() < 200 || fetcher->GetResponseCode() >= 300) { - LOG(ERROR) << "URLFetchFailure: state=" << state_ - << " r=" << fetcher->GetResponseCode() - << " s=" << fetcher->GetStatus().status() - << " e=" << fetcher->GetStatus().error(); + DVLOG(1) << "URLFetchFailure:" + << " r=" << fetcher->GetResponseCode() + << " s=" << fetcher->GetStatus().status() + << " e=" << fetcher->GetStatus().error(); OnOtherError(); return; } - switch (state_) { - case USERNAME_FETCHING_USERINFO: /*FALLTHROUGH*/ - case PASSIVE_FETCHING_USERINFO: - ProcessGetAccountInfoResponseAndFinish(); - break; - - case PASSIVE_EXECUTING_SIGNIN: - if (ParseSignInResponse()) { - url_fetcher_.reset(); - state_ = PASSIVE_FETCHING_USERINFO; - StartFetchingUserNameFromSession(); - } - break; - - default: - NOTREACHED() << "unexpected state_=" << state_; - } -} - -void WalletSigninHelper::StartFetchingUserNameFromSession() { - const int random_number = static_cast<int>(base::RandUint64() % INT_MAX); - url_fetcher_.reset( - net::URLFetcher::Create( - 0, - GURL(base::StringPrintf(kGetAccountInfoUrlFormat, random_number)), - net::URLFetcher::GET, - this)); - url_fetcher_->SetRequestContext(getter_); - url_fetcher_->Start(); // This will result in OnURLFetchComplete callback. -} - -void WalletSigninHelper::ProcessGetAccountInfoResponseAndFinish() { - if (!ParseGetAccountInfoResponse(url_fetcher_.get(), &emails_)) { - LOG(ERROR) << "failed to get the user emails"; - OnOtherError(); - return; - } - - const State finishing_state = state_; - state_ = IDLE; - url_fetcher_.reset(); - switch(finishing_state) { - case USERNAME_FETCHING_USERINFO: - delegate_->OnUserNameFetchSuccess(emails_); - break; - - case PASSIVE_FETCHING_USERINFO: - delegate_->OnPassiveSigninSuccess(emails_); - break; - - default: - NOTREACHED() << "unexpected state_=" << finishing_state; - } -} - -bool WalletSigninHelper::ParseSignInResponse() { - if (!url_fetcher_) { - NOTREACHED(); - return false; - } - std::string data; - if (!url_fetcher_->GetResponseAsString(&data)) { + if (!fetcher->GetResponseAsString(&data)) { DVLOG(1) << "failed to GetResponseAsString"; OnOtherError(); - return false; + return; } if (!LowerCaseEqualsASCII(data, "yes")) { OnServiceError( GoogleServiceAuthError(GoogleServiceAuthError::USER_NOT_SIGNED_UP)); - return false; - } - - return true; -} - -bool WalletSigninHelper::ParseGetAccountInfoResponse( - const net::URLFetcher* fetcher, std::vector<std::string>* emails) { - DCHECK(emails); - - std::string data; - if (!fetcher->GetResponseAsString(&data)) { - DVLOG(1) << "failed to GetResponseAsString"; - return false; - } - - scoped_ptr<base::Value> value(base::JSONReader::Read(data)); - if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) { - DVLOG(1) << "failed to parse JSON response"; - return false; - } - - DictionaryValue* dict = static_cast<base::DictionaryValue*>(value.get()); - base::ListValue* user_info; - if (!dict->GetListWithoutPathExpansion("user_info", &user_info)) { - DVLOG(1) << "no user_info in JSON response"; - return false; - } - - if (user_info->empty()) { - DVLOG(1) << "empty list in JSON response"; - return false; - } - - // |user_info| will contain each signed in user in the cookie jar. - for (size_t i = 0; i < user_info->GetSize(); ++i) { - base::DictionaryValue* user_info_detail; - if (!user_info->GetDictionary(i, &user_info_detail)) { - DVLOG(1) << "malformed dictionary in JSON response"; - return false; - } - - std::string email; - if (!user_info_detail->GetStringWithoutPathExpansion("email", &email) || - email.empty()) { - DVLOG(1) << "no email in JSON response"; - return false; - } - - emails->push_back(email); + return; } - return true; + delegate_->OnPassiveSigninSuccess(); } void WalletSigninHelper::ReturnWalletCookieValue( diff --git a/components/autofill/content/browser/wallet/wallet_signin_helper.h b/components/autofill/content/browser/wallet/wallet_signin_helper.h index e8a32f5..ebfcfaa 100644 --- a/components/autofill/content/browser/wallet/wallet_signin_helper.h +++ b/components/autofill/content/browser/wallet/wallet_signin_helper.h @@ -47,29 +47,9 @@ class WalletSigninHelper : public net::URLFetcherDelegate { // on the original thread. void StartPassiveSignin(); - // Initiates a fetch of the user name of a signed-in user. - // Either OnUserNameFetchSuccess or OnUserNameFetchFailure will - // be called on the original thread. - void StartUserNameFetch(); - // Initiates the fetch of the user's Google Wallet cookie. void StartWalletCookieValueFetch(); - protected: - // Sign-in helper states (for tests). - enum State { - IDLE, - PASSIVE_EXECUTING_SIGNIN, - PASSIVE_FETCHING_USERINFO, - USERNAME_FETCHING_USERINFO, - }; - - // (For tests) Current state of the sign-in helper. - State state() const { return state_; } - - // (For tests) URL used to fetch the currently signed-in user info. - std::string GetGetAccountInfoUrlForTesting() const; - private: // Called if a service authentication error occurs. void OnServiceError(const GoogleServiceAuthError& error); @@ -80,24 +60,6 @@ class WalletSigninHelper : public net::URLFetcherDelegate { // URLFetcherDelegate implementation. virtual void OnURLFetchComplete(const net::URLFetcher* fetcher) OVERRIDE; - // Initiates fetching of the currently signed-in user information. - void StartFetchingUserNameFromSession(); - - // Processes the user information received from the server by url_fetcher_ - // and calls the delegate callbacks on success/failure. - void ProcessGetAccountInfoResponseAndFinish(); - - // Attempts to parse a response from the Online Wallet sign-in. - // Returns true if the response is correct and the sign-in has succeeded. - // Otherwise, it calls OnServiceError() and returns false. - bool ParseSignInResponse(); - - // Attempts to parse the GetAccountInfo response from the server. - // Returns true on success; the obtained email addresses are stored into - // |emails|. - bool ParseGetAccountInfoResponse(const net::URLFetcher* fetcher, - std::vector<std::string>* emails); - // Callback for when the Google Wallet cookie has been retrieved. void ReturnWalletCookieValue(const std::string& cookie_value); @@ -110,12 +72,6 @@ class WalletSigninHelper : public net::URLFetcherDelegate { // While passive login/merge session URL fetches are going on: scoped_ptr<net::URLFetcher> url_fetcher_; - // User account names (emails) fetched from OnGetUserInfoSuccess(). - std::vector<std::string> emails_; - - // Current internal state of the helper. - State state_; - base::WeakPtrFactory<WalletSigninHelper> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(WalletSigninHelper); diff --git a/components/autofill/content/browser/wallet/wallet_signin_helper_delegate.h b/components/autofill/content/browser/wallet/wallet_signin_helper_delegate.h index f05e36e..28508a3 100644 --- a/components/autofill/content/browser/wallet/wallet_signin_helper_delegate.h +++ b/components/autofill/content/browser/wallet/wallet_signin_helper_delegate.h @@ -20,22 +20,11 @@ class WalletSigninHelperDelegate { virtual ~WalletSigninHelperDelegate() {} // Called on a successful passive sign-in. - // |usernames| contains the signed-in user account names (emails). - virtual void OnPassiveSigninSuccess(const std::vector<std::string>& usernames) - = 0; + virtual void OnPassiveSigninSuccess() = 0; // Called on a failed passive sign-in; |error| describes the error. virtual void OnPassiveSigninFailure(const GoogleServiceAuthError& error) = 0; - // Called on a successful fetch of the signed-in account name. - // |usernames| contains the signed-in user account names (emails). - virtual void OnUserNameFetchSuccess(const std::vector<std::string>& usernames) - = 0; - - // Called on a failed fetch of the signed-in account name. - // |error| described the error. - virtual void OnUserNameFetchFailure(const GoogleServiceAuthError& error) = 0; - // Called when the Google Wallet cookie value has been retrieved. virtual void OnDidFetchWalletCookieValue(const std::string& cookie_value) = 0; }; diff --git a/components/autofill/content/browser/wallet/wallet_signin_helper_unittest.cc b/components/autofill/content/browser/wallet/wallet_signin_helper_unittest.cc index 2247105..5f7d5a2 100644 --- a/components/autofill/content/browser/wallet/wallet_signin_helper_unittest.cc +++ b/components/autofill/content/browser/wallet/wallet_signin_helper_unittest.cc @@ -34,52 +34,23 @@ namespace wallet { namespace { -const char kGetAccountInfoValidResponseFormat[] = - "{\"user_info\":[" - " {" - " \"email\": \"%s\"" - " }" - "]}"; - class MockWalletSigninHelperDelegate : public WalletSigninHelperDelegate { public: - MOCK_METHOD1(OnPassiveSigninSuccess, - void(const std::vector<std::string>& usernames)); - MOCK_METHOD1(OnUserNameFetchSuccess, - void(const std::vector<std::string>& usernames)); + MOCK_METHOD0(OnPassiveSigninSuccess, void()); MOCK_METHOD1(OnPassiveSigninFailure, void(const GoogleServiceAuthError& error)); - MOCK_METHOD1(OnUserNameFetchFailure, - void(const GoogleServiceAuthError& error)); MOCK_METHOD1(OnDidFetchWalletCookieValue, void(const std::string& cookie_value)); }; -class WalletSigninHelperForTesting : public WalletSigninHelper { - public: - WalletSigninHelperForTesting(WalletSigninHelperDelegate* delegate, - net::URLRequestContextGetter* getter) - : WalletSigninHelper(delegate, getter) { - } - - // Bring in the test-only getters. - using WalletSigninHelper::GetGetAccountInfoUrlForTesting; - using WalletSigninHelper::state; - - // Bring in the State enum. - using WalletSigninHelper::State; - using WalletSigninHelper::IDLE; -}; - } // namespace class WalletSigninHelperTest : public testing::Test { protected: virtual void SetUp() OVERRIDE { - signin_helper_.reset(new WalletSigninHelperForTesting( + signin_helper_.reset(new WalletSigninHelper( &mock_delegate_, browser_context_.GetRequestContext())); - EXPECT_EQ(WalletSigninHelperForTesting::IDLE, state()); } virtual void TearDown() OVERRIDE { @@ -104,23 +75,6 @@ class WalletSigninHelperTest : public testing::Test { fetcher->delegate()->OnURLFetchComplete(fetcher); } - void MockSuccessfulGetAccountInfoResponse(const std::string& username) { - SetUpFetcherResponseAndCompleteRequest( - signin_helper_->GetGetAccountInfoUrlForTesting(), net::HTTP_OK, - net::ResponseCookies(), - base::StringPrintf( - kGetAccountInfoValidResponseFormat, - username.c_str())); - } - - void MockFailedGetAccountInfoResponse404() { - SetUpFetcherResponseAndCompleteRequest( - signin_helper_->GetGetAccountInfoUrlForTesting(), - net::HTTP_NOT_FOUND, - net::ResponseCookies(), - std::string()); - } - void MockSuccessfulPassiveSignInResponse() { SetUpFetcherResponseAndCompleteRequest(wallet::GetPassiveAuthUrl().spec(), net::HTTP_OK, @@ -142,12 +96,8 @@ class WalletSigninHelperTest : public testing::Test { std::string()); } - WalletSigninHelperForTesting::State state() const { - return signin_helper_->state(); - } - content::TestBrowserThreadBundle thread_bundle_; - scoped_ptr<WalletSigninHelperForTesting> signin_helper_; + scoped_ptr<WalletSigninHelper> signin_helper_; MockWalletSigninHelperDelegate mock_delegate_; TestingProfile browser_context_; @@ -156,12 +106,9 @@ class WalletSigninHelperTest : public testing::Test { }; TEST_F(WalletSigninHelperTest, PassiveSigninSuccessful) { - std::vector<std::string> usernames; - usernames.push_back("user@gmail.com"); - EXPECT_CALL(mock_delegate_, OnPassiveSigninSuccess(usernames)); + EXPECT_CALL(mock_delegate_, OnPassiveSigninSuccess()); signin_helper_->StartPassiveSignin(); MockSuccessfulPassiveSignInResponse(); - MockSuccessfulGetAccountInfoResponse("user@gmail.com"); } TEST_F(WalletSigninHelperTest, PassiveSigninFailedSignin404) { @@ -176,27 +123,6 @@ TEST_F(WalletSigninHelperTest, PassiveSigninFailedSigninNo) { MockFailedPassiveSignInResponseNo(); } -TEST_F(WalletSigninHelperTest, PassiveSigninFailedUserInfo) { - EXPECT_CALL(mock_delegate_, OnPassiveSigninFailure(_)); - signin_helper_->StartPassiveSignin(); - MockSuccessfulPassiveSignInResponse(); - MockFailedGetAccountInfoResponse404(); -} - -TEST_F(WalletSigninHelperTest, PassiveUserInfoSuccessful) { - std::vector<std::string> usernames; - usernames.push_back("user@gmail.com"); - EXPECT_CALL(mock_delegate_, OnUserNameFetchSuccess(usernames)); - signin_helper_->StartUserNameFetch(); - MockSuccessfulGetAccountInfoResponse("user@gmail.com"); -} - -TEST_F(WalletSigninHelperTest, PassiveUserInfoFailedUserInfo) { - EXPECT_CALL(mock_delegate_, OnUserNameFetchFailure(_)); - signin_helper_->StartUserNameFetch(); - MockFailedGetAccountInfoResponse404(); -} - TEST_F(WalletSigninHelperTest, GetWalletCookieValueWhenPresent) { EXPECT_CALL(mock_delegate_, OnDidFetchWalletCookieValue("gdToken")); net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL); diff --git a/components/autofill/content/browser/wallet/wallet_test_util.cc b/components/autofill/content/browser/wallet/wallet_test_util.cc index 1360e05..d5e5af0 100644 --- a/components/autofill/content/browser/wallet/wallet_test_util.cc +++ b/components/autofill/content/browser/wallet/wallet_test_util.cc @@ -235,24 +235,30 @@ scoped_ptr<WalletItems> GetTestWalletItems( const std::vector<RequiredAction>& required_actions, const std::string& default_instrument_id, const std::string& default_address_id, - AmexPermission amex_permission) { + AmexPermission amex_permission, + const std::vector<std::string>& users) { return scoped_ptr<WalletItems>( new wallet::WalletItems(required_actions, "google_transaction_id", default_instrument_id, default_address_id, "obfuscated_gaia_id", - amex_permission)); + amex_permission, + users)); } scoped_ptr<WalletItems> GetTestWalletItemsWithRequiredAction( RequiredAction action) { - std::vector<RequiredAction> required_actions; - required_actions.push_back(action); + std::vector<RequiredAction> required_actions(1, action); + std::vector<std::string> users; + if (action != GAIA_AUTH) + users.push_back("user@example.com"); + return GetTestWalletItems(required_actions, "default_instrument_id", "default_address_id", - AMEX_ALLOWED); + AMEX_ALLOWED, + users); } scoped_ptr<WalletItems> GetTestWalletItems(AmexPermission amex_permission) { @@ -261,14 +267,26 @@ scoped_ptr<WalletItems> GetTestWalletItems(AmexPermission amex_permission) { amex_permission); } + +scoped_ptr<WalletItems> GetTestWalletItemsWithUsers( + std::vector<std::string>& users) { + return GetTestWalletItems(std::vector<RequiredAction>(), + "default_instrument_id", + "default_address_id", + AMEX_ALLOWED, + users); +} + scoped_ptr<WalletItems> GetTestWalletItemsWithDefaultIds( const std::string& default_instrument_id, const std::string& default_address_id, AmexPermission amex_permission) { + std::vector<std::string> users(1, "user@example.com"); return GetTestWalletItems(std::vector<RequiredAction>(), default_instrument_id, default_address_id, - amex_permission); + amex_permission, + users); } } // namespace wallet diff --git a/components/autofill/content/browser/wallet/wallet_test_util.h b/components/autofill/content/browser/wallet/wallet_test_util.h index cc1fdf1..e6d33f6 100644 --- a/components/autofill/content/browser/wallet/wallet_test_util.h +++ b/components/autofill/content/browser/wallet/wallet_test_util.h @@ -50,6 +50,8 @@ scoped_ptr<Address> GetTestNonDefaultShippingAddress(); scoped_ptr<WalletItems> GetTestWalletItemsWithRequiredAction( RequiredAction action); scoped_ptr<WalletItems> GetTestWalletItems(AmexPermission amex_permission); +scoped_ptr<WalletItems> GetTestWalletItemsWithUsers( + const std::vector<std::string>& users); scoped_ptr<WalletItems> GetTestWalletItemsWithDefaultIds( const std::string& default_instrument_id, const std::string& default_address_id, |