diff options
author | droger <droger@chromium.org> | 2015-07-15 02:51:06 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-15 09:51:42 +0000 |
commit | d448b63c12863b61e38a8891636f6a081d5179b4 (patch) | |
tree | 0e387d7e92a8d474ee055cedebf044ecb6dba430 /components | |
parent | e051d2ac59a12318e50812ddeaef08b16ac6ebef (diff) | |
download | chromium_src-d448b63c12863b61e38a8891636f6a081d5179b4.zip chromium_src-d448b63c12863b61e38a8891636f6a081d5179b4.tar.gz chromium_src-d448b63c12863b61e38a8891636f6a081d5179b4.tar.bz2 |
Move ProfileOAuth2TokenServiceIOSProvider to the signin component.
This CL moves the file from //ios/public/provider/components/signin/browser
to //components/signin/browser/core where it belongs.
BUG=358544
Review URL: https://codereview.chromium.org/1218073006
Cr-Commit-Position: refs/heads/master@{#338834}
Diffstat (limited to 'components')
13 files changed, 301 insertions, 119 deletions
diff --git a/components/components_tests.gyp b/components/components_tests.gyp index 02c39b3..e0e1e53 100644 --- a/components/components_tests.gyp +++ b/components/components_tests.gyp @@ -999,6 +999,7 @@ 'components.gyp:open_from_clipboard', 'components.gyp:sessions_ios', 'components.gyp:signin_ios_browser', + 'components.gyp:signin_ios_browser_test_support', 'components.gyp:translate_ios_browser', 'components.gyp:webp_transcode', ], diff --git a/components/signin.gypi b/components/signin.gypi index 15cb1d8..ea821e4 100644 --- a/components/signin.gypi +++ b/components/signin.gypi @@ -116,14 +116,13 @@ ], 'conditions': [ ['OS == "ios"', { + # GN version: //components/signin/core/browser:ios 'targets': [ { - # GN version: //components/signin/core/browser:ios 'target_name': 'signin_ios_browser', 'type': 'static_library', 'dependencies': [ 'signin_core_browser', - '../ios/provider/ios_components.gyp:ios_components', ], 'include_dirs': [ '..', @@ -136,8 +135,26 @@ 'signin/ios/browser/oauth2_token_service_observer_bridge.mm', 'signin/ios/browser/profile_oauth2_token_service_ios_delegate.h', 'signin/ios/browser/profile_oauth2_token_service_ios_delegate.mm', + 'signin/ios/browser/profile_oauth2_token_service_ios_provider.h', ], }, + { + 'target_name': 'signin_ios_browser_test_support', + 'type': 'static_library', + 'dependencies': [ + '../base/base.gyp:base', + 'signin_ios_browser', + ], + 'include_dirs': [ + '..', + ], + 'sources': [ + # Note: file list duplicated in GN build. + 'signin/ios/browser/fake_profile_oauth2_token_service_ios_provider.h', + 'signin/ios/browser/fake_profile_oauth2_token_service_ios_provider.mm', + ], + }, + ], }], ], diff --git a/components/signin/core/browser/signin_client.h b/components/signin/core/browser/signin_client.h index 13bdf84..dd8224b 100644 --- a/components/signin/core/browser/signin_client.h +++ b/components/signin/core/browser/signin_client.h @@ -27,14 +27,6 @@ namespace net { class URLRequestContextGetter; } -#if defined(OS_IOS) -namespace ios { -// TODO(msarda): http://crbug.com/358544 Remove this iOS specific code from the -// core SigninClient. -class ProfileOAuth2TokenServiceIOSProvider; -} -#endif - // An interface that needs to be supplied to the Signin component by its // embedder. class SigninClient : public KeyedService { @@ -125,12 +117,6 @@ class SigninClient : public KeyedService { virtual bool UpdateAccountInfo( AccountTrackerService::AccountInfo* out_account_info) = 0; -#if defined(OS_IOS) - // TODO(msarda): http://crbug.com/358544 Remove this iOS specific code from - // the core SigninClient. - virtual ios::ProfileOAuth2TokenServiceIOSProvider* GetIOSProvider() = 0; -#endif - // Execute |callback| if and when there is a network connection. virtual void DelayNetworkCall(const base::Closure& callback) = 0; diff --git a/components/signin/core/browser/test_signin_client.cc b/components/signin/core/browser/test_signin_client.cc index 45c0fde..096fe06 100644 --- a/components/signin/core/browser/test_signin_client.cc +++ b/components/signin/core/browser/test_signin_client.cc @@ -11,10 +11,6 @@ #include "components/webdata/common/web_database_service.h" #include "testing/gtest/include/gtest/gtest.h" -#if defined(OS_IOS) -#include "ios/public/test/fake_profile_oauth2_token_service_ios_provider.h" -#endif - TestSigninClient::TestSigninClient() : request_context_(new net::TestURLRequestContextGetter( base::ThreadTaskRunnerHandle::Get())), @@ -97,20 +93,6 @@ bool TestSigninClient::UpdateAccountInfo( return false; } -#if defined(OS_IOS) -ios::ProfileOAuth2TokenServiceIOSProvider* TestSigninClient::GetIOSProvider() { - return GetIOSProviderAsFake(); -} - -ios::FakeProfileOAuth2TokenServiceIOSProvider* -TestSigninClient::GetIOSProviderAsFake() { - if (!iosProvider_) { - iosProvider_.reset(new ios::FakeProfileOAuth2TokenServiceIOSProvider()); - } - return iosProvider_.get(); -} -#endif - bool TestSigninClient::IsFirstRun() const { return false; } diff --git a/components/signin/core/browser/test_signin_client.h b/components/signin/core/browser/test_signin_client.h index 8c35970..3a7895c 100644 --- a/components/signin/core/browser/test_signin_client.h +++ b/components/signin/core/browser/test_signin_client.h @@ -13,10 +13,6 @@ #include "components/signin/core/browser/signin_client.h" #include "net/url_request/url_request_test_util.h" -#if defined(OS_IOS) -#include "ios/public/test/fake_profile_oauth2_token_service_ios_provider.h" -#endif - class PrefService; // An implementation of SigninClient for use in unittests. Instantiates test @@ -67,10 +63,6 @@ class TestSigninClient : public SigninClient { // in the default constructor. void SetURLRequestContext(net::URLRequestContextGetter* request_context); -#if defined(OS_IOS) - ios::ProfileOAuth2TokenServiceIOSProvider* GetIOSProvider() override; -#endif - // Returns true. bool ShouldMergeSigninCredentialsIntoCookieJar() override; @@ -84,10 +76,6 @@ class TestSigninClient : public SigninClient { bool UpdateAccountInfo( AccountTrackerService::AccountInfo* out_account_info) override; -#if defined(OS_IOS) - ios::FakeProfileOAuth2TokenServiceIOSProvider* GetIOSProviderAsFake(); -#endif - void set_are_signin_cookies_allowed(bool value) { are_signin_cookies_allowed_ = value; } @@ -119,10 +107,6 @@ class TestSigninClient : public SigninClient { // Pointer to be filled by PostSignedIn. std::string signed_in_password_; -#if defined(OS_IOS) - scoped_ptr<ios::FakeProfileOAuth2TokenServiceIOSProvider> iosProvider_; -#endif - DISALLOW_COPY_AND_ASSIGN(TestSigninClient); }; diff --git a/components/signin/ios/DEPS b/components/signin/ios/DEPS deleted file mode 100644 index a2fbbc5..0000000 --- a/components/signin/ios/DEPS +++ /dev/null @@ -1,4 +0,0 @@ -include_rules = [ - "+ios/public/provider/components/signin", - "+ios/public/test", -] diff --git a/components/signin/ios/browser/BUILD.gn b/components/signin/ios/browser/BUILD.gn index 531d11c..70b03f5 100644 --- a/components/signin/ios/browser/BUILD.gn +++ b/components/signin/ios/browser/BUILD.gn @@ -10,10 +10,23 @@ static_library("browser") { "oauth2_token_service_observer_bridge.mm", "profile_oauth2_token_service_ios_delegate.h", "profile_oauth2_token_service_ios_delegate.mm", + "profile_oauth2_token_service_ios_provider.h", ] deps = [ "//signin/core/browser", - #'../ios/provider/ios_components.gyp:ios_components', TODO(GYP) + ] +} + +static_library("test_support") { + testonly = true + sources = [ + "fake_profile_oauth2_token_service_ios_provider.h", + "fake_profile_oauth2_token_service_ios_provider.mm", + ] + + deps = [ + "//base", + ":browser", ] } diff --git a/components/signin/ios/browser/fake_profile_oauth2_token_service_ios_provider.h b/components/signin/ios/browser/fake_profile_oauth2_token_service_ios_provider.h new file mode 100644 index 0000000..6df9ecd --- /dev/null +++ b/components/signin/ios/browser/fake_profile_oauth2_token_service_ios_provider.h @@ -0,0 +1,51 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef IOS_TEST_MOCK_PROFILE_OAUTH2_TOKEN_SERVICE_PROVIDER_IOS_H_ +#define IOS_TEST_MOCK_PROFILE_OAUTH2_TOKEN_SERVICE_PROVIDER_IOS_H_ + +#include <string> +#include <utility> +#include <vector> + +#include "base/memory/scoped_ptr.h" +#include "components/signin/ios/browser/profile_oauth2_token_service_ios_provider.h" + +// Mock class of ProfileOAuth2TokenServiceIOSProvider for testing. +class FakeProfileOAuth2TokenServiceIOSProvider + : public ProfileOAuth2TokenServiceIOSProvider { + public: + FakeProfileOAuth2TokenServiceIOSProvider(); + ~FakeProfileOAuth2TokenServiceIOSProvider() override; + + // ProfileOAuth2TokenServiceIOSProvider + void GetAccessToken(const std::string& account_id, + const std::string& client_id, + const std::string& client_secret, + const std::set<std::string>& scopes, + const AccessTokenCallback& callback) override; + std::vector<std::string> GetAllAccountIds() override; + AuthenticationErrorCategory GetAuthenticationErrorCategory( + NSError* error) const override; + AccountInfo GetAccountInfo(const std::string& account_id) const override; + + // Methods to configure this fake provider. + void AddAccount(const std::string& account_id); + void SetAccounts(const std::vector<std::string>& accounts); + void ClearAccounts(); + + // Issues access token responses. + void IssueAccessTokenForAllRequests(); + void IssueAccessTokenErrorForAllRequests(); + + private: + typedef std::pair<std::string, AccessTokenCallback> AccessTokenRequest; + + std::vector<std::string> accounts_; + std::vector<AccessTokenRequest> requests_; + + DISALLOW_COPY_AND_ASSIGN(FakeProfileOAuth2TokenServiceIOSProvider); +}; + +#endif // IOS_TEST_PROVIDER_CHROME_BROWSER_SIGNIN_MOCK_PROFILE_OAUTH2_TOKEN_SERVICE_PROVIDER_IOS_H_ diff --git a/components/signin/ios/browser/fake_profile_oauth2_token_service_ios_provider.mm b/components/signin/ios/browser/fake_profile_oauth2_token_service_ios_provider.mm new file mode 100644 index 0000000..345aab1 --- /dev/null +++ b/components/signin/ios/browser/fake_profile_oauth2_token_service_ios_provider.mm @@ -0,0 +1,84 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/signin/ios/browser/fake_profile_oauth2_token_service_ios_provider.h" + +#include <Foundation/Foundation.h> + +#include "base/logging.h" +#include "base/strings/sys_string_conversions.h" + +FakeProfileOAuth2TokenServiceIOSProvider:: + FakeProfileOAuth2TokenServiceIOSProvider() { +} + +FakeProfileOAuth2TokenServiceIOSProvider:: + ~FakeProfileOAuth2TokenServiceIOSProvider() { +} + +void FakeProfileOAuth2TokenServiceIOSProvider::GetAccessToken( + const std::string& account_id, + const std::string& client_id, + const std::string& client_secret, + const std::set<std::string>& scopes, + const AccessTokenCallback& callback) { + requests_.push_back(AccessTokenRequest(account_id, callback)); +} + +std::vector<std::string> +FakeProfileOAuth2TokenServiceIOSProvider::GetAllAccountIds() { + return accounts_; +} + +void FakeProfileOAuth2TokenServiceIOSProvider::AddAccount( + const std::string& account_id) { + accounts_.push_back(account_id); +} + +void FakeProfileOAuth2TokenServiceIOSProvider::SetAccounts( + const std::vector<std::string>& accounts) { + accounts_ = accounts; +} + +void FakeProfileOAuth2TokenServiceIOSProvider::ClearAccounts() { + accounts_.clear(); +} + +void FakeProfileOAuth2TokenServiceIOSProvider:: + IssueAccessTokenForAllRequests() { + for (auto i = requests_.begin(); i != requests_.end(); ++i) { + std::string account_id = i->first; + AccessTokenCallback callback = i->second; + NSString* access_token = [NSString + stringWithFormat:@"fake_access_token [account=%s]", account_id.c_str()]; + NSDate* one_hour_from_now = [NSDate dateWithTimeIntervalSinceNow:3600]; + callback.Run(access_token, one_hour_from_now, nil); + } + requests_.clear(); +} + +void FakeProfileOAuth2TokenServiceIOSProvider:: + IssueAccessTokenErrorForAllRequests() { + for (auto i = requests_.begin(); i != requests_.end(); ++i) { + std::string account_id = i->first; + AccessTokenCallback callback = i->second; + NSError* error = [[[NSError alloc] initWithDomain:@"fake_access_token_error" + code:-1 + userInfo:nil] autorelease]; + callback.Run(nil, nil, error); + } + requests_.clear(); +} + +AuthenticationErrorCategory +FakeProfileOAuth2TokenServiceIOSProvider::GetAuthenticationErrorCategory( + NSError* error) const { + DCHECK(error); + return kAuthenticationErrorCategoryAuthorizationErrors; +} + +AccountInfo FakeProfileOAuth2TokenServiceIOSProvider::GetAccountInfo( + const std::string& account_id) const { + return AccountInfo(); +} diff --git a/components/signin/ios/browser/profile_oauth2_token_service_ios_delegate.h b/components/signin/ios/browser/profile_oauth2_token_service_ios_delegate.h index b03af70..730117a 100644 --- a/components/signin/ios/browser/profile_oauth2_token_service_ios_delegate.h +++ b/components/signin/ios/browser/profile_oauth2_token_service_ios_delegate.h @@ -11,14 +11,13 @@ #include "components/signin/core/browser/signin_error_controller.h" #include "google_apis/gaia/oauth2_token_service_delegate.h" -namespace ios { class ProfileOAuth2TokenServiceIOSProvider; -} class ProfileOAuth2TokenServiceIOSDelegate : public OAuth2TokenServiceDelegate { public: ProfileOAuth2TokenServiceIOSDelegate( SigninClient* client, + ProfileOAuth2TokenServiceIOSProvider* provider, SigninErrorController* signin_error_controller); ~ProfileOAuth2TokenServiceIOSDelegate() override; @@ -111,9 +110,6 @@ class ProfileOAuth2TokenServiceIOSDelegate : public OAuth2TokenServiceDelegate { // to information about the account. typedef std::map<std::string, linked_ptr<AccountInfo>> AccountInfoMap; - // Returns the iOS provider; - ios::ProfileOAuth2TokenServiceIOSProvider* GetProvider(); - // Returns the account ids that should be ignored by this token service. std::set<std::string> GetExcludedSecondaryAccounts(); @@ -136,6 +132,7 @@ class ProfileOAuth2TokenServiceIOSDelegate : public OAuth2TokenServiceDelegate { // The client with which this instance was initialied, or NULL. SigninClient* client_; + ProfileOAuth2TokenServiceIOSProvider* provider_; // The error controller with which this instance was initialized, or NULL. SigninErrorController* signin_error_controller_; diff --git a/components/signin/ios/browser/profile_oauth2_token_service_ios_delegate.mm b/components/signin/ios/browser/profile_oauth2_token_service_ios_delegate.mm index a177f8e..6e91264 100644 --- a/components/signin/ios/browser/profile_oauth2_token_service_ios_delegate.mm +++ b/components/signin/ios/browser/profile_oauth2_token_service_ios_delegate.mm @@ -19,8 +19,8 @@ #include "base/values.h" #include "components/signin/core/browser/signin_client.h" #include "components/signin/core/common/signin_pref_names.h" +#include "components/signin/ios/browser/profile_oauth2_token_service_ios_provider.h" #include "google_apis/gaia/oauth2_access_token_fetcher.h" -#include "ios/public/provider/components/signin/browser/profile_oauth2_token_service_ios_provider.h" #include "net/url_request/url_request_status.h" namespace { @@ -28,35 +28,35 @@ namespace { // Match the way Chromium handles authentication errors in // google_apis/gaia/oauth2_access_token_fetcher.cc: GoogleServiceAuthError GetGoogleServiceAuthErrorFromNSError( - ios::ProfileOAuth2TokenServiceIOSProvider* provider, + ProfileOAuth2TokenServiceIOSProvider* provider, NSError* error) { if (!error) return GoogleServiceAuthError::AuthErrorNone(); - ios::AuthenticationErrorCategory errorCategory = + AuthenticationErrorCategory errorCategory = provider->GetAuthenticationErrorCategory(error); switch (errorCategory) { - case ios::kAuthenticationErrorCategoryUnknownErrors: + case kAuthenticationErrorCategoryUnknownErrors: // Treat all unknown error as unexpected service response errors. // This may be too general and may require a finer grain filtering. return GoogleServiceAuthError( GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE); - case ios::kAuthenticationErrorCategoryAuthorizationErrors: + case kAuthenticationErrorCategoryAuthorizationErrors: return GoogleServiceAuthError( GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); - case ios::kAuthenticationErrorCategoryAuthorizationForbiddenErrors: + case kAuthenticationErrorCategoryAuthorizationForbiddenErrors: // HTTP_FORBIDDEN (403) is treated as temporary error, because it may be // '403 Rate Limit Exceeded.' (for more details, see // google_apis/gaia/oauth2_access_token_fetcher.cc). return GoogleServiceAuthError( GoogleServiceAuthError::SERVICE_UNAVAILABLE); - case ios::kAuthenticationErrorCategoryNetworkServerErrors: + case kAuthenticationErrorCategoryNetworkServerErrors: // Just set the connection error state to FAILED. return GoogleServiceAuthError::FromConnectionError( net::URLRequestStatus::FAILED); - case ios::kAuthenticationErrorCategoryUserCancellationErrors: + case kAuthenticationErrorCategoryUserCancellationErrors: return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); - case ios::kAuthenticationErrorCategoryUnknownIdentityErrors: + case kAuthenticationErrorCategoryUnknownIdentityErrors: return GoogleServiceAuthError(GoogleServiceAuthError::USER_NOT_SIGNED_UP); } } @@ -64,7 +64,7 @@ GoogleServiceAuthError GetGoogleServiceAuthErrorFromNSError( class SSOAccessTokenFetcher : public OAuth2AccessTokenFetcher { public: SSOAccessTokenFetcher(OAuth2AccessTokenConsumer* consumer, - ios::ProfileOAuth2TokenServiceIOSProvider* provider, + ProfileOAuth2TokenServiceIOSProvider* provider, const std::string account_id); ~SSOAccessTokenFetcher() override; @@ -80,7 +80,7 @@ class SSOAccessTokenFetcher : public OAuth2AccessTokenFetcher { NSError* error); private: - ios::ProfileOAuth2TokenServiceIOSProvider* provider_; // weak + ProfileOAuth2TokenServiceIOSProvider* provider_; // weak std::string account_id_; bool request_was_cancelled_; base::WeakPtrFactory<SSOAccessTokenFetcher> weak_factory_; @@ -90,7 +90,7 @@ class SSOAccessTokenFetcher : public OAuth2AccessTokenFetcher { SSOAccessTokenFetcher::SSOAccessTokenFetcher( OAuth2AccessTokenConsumer* consumer, - ios::ProfileOAuth2TokenServiceIOSProvider* provider, + ProfileOAuth2TokenServiceIOSProvider* provider, const std::string account_id) : OAuth2AccessTokenFetcher(consumer), provider_(provider), @@ -173,11 +173,14 @@ ProfileOAuth2TokenServiceIOSDelegate::AccountInfo::GetAuthStatus() const { ProfileOAuth2TokenServiceIOSDelegate::ProfileOAuth2TokenServiceIOSDelegate( SigninClient* client, + ProfileOAuth2TokenServiceIOSProvider* provider, SigninErrorController* signin_error_controller) - : client_(client), signin_error_controller_(signin_error_controller) { - DCHECK(thread_checker_.CalledOnValidThread()); - DCHECK(client); - DCHECK(signin_error_controller); + : client_(client), + provider_(provider), + signin_error_controller_(signin_error_controller) { + DCHECK(client_); + DCHECK(provider_); + DCHECK(signin_error_controller_); } ProfileOAuth2TokenServiceIOSDelegate::~ProfileOAuth2TokenServiceIOSDelegate() { @@ -189,14 +192,6 @@ void ProfileOAuth2TokenServiceIOSDelegate::Shutdown() { accounts_.clear(); } -ios::ProfileOAuth2TokenServiceIOSProvider* -ProfileOAuth2TokenServiceIOSDelegate::GetProvider() { - ios::ProfileOAuth2TokenServiceIOSProvider* provider = - client_->GetIOSProvider(); - DCHECK(provider); - return provider; -} - void ProfileOAuth2TokenServiceIOSDelegate::LoadCredentials( const std::string& primary_account_id) { DCHECK(thread_checker_.CalledOnValidThread()); @@ -205,7 +200,6 @@ void ProfileOAuth2TokenServiceIOSDelegate::LoadCredentials( // primary account id must not be empty. DCHECK(!primary_account_id.empty()); - GetProvider()->InitializeSharedAuthentication(); ReloadCredentials(primary_account_id); FireRefreshTokensLoaded(); } @@ -226,7 +220,7 @@ void ProfileOAuth2TokenServiceIOSDelegate::ReloadCredentials() { return; } - std::vector<std::string> new_accounts(GetProvider()->GetAllAccountIds()); + std::vector<std::string> new_accounts(provider_->GetAllAccountIds()); if (GetExcludeAllSecondaryAccounts()) { // Only keep the |primary_account_id| in the list of new accounts. if (std::find(new_accounts.begin(), new_accounts.end(), @@ -299,7 +293,7 @@ ProfileOAuth2TokenServiceIOSDelegate::CreateAccessTokenFetcher( const std::string& account_id, net::URLRequestContextGetter* getter, OAuth2AccessTokenConsumer* consumer) { - return new SSOAccessTokenFetcher(consumer, GetProvider(), account_id); + return new SSOAccessTokenFetcher(consumer, provider_, account_id); } std::vector<std::string> ProfileOAuth2TokenServiceIOSDelegate::GetAccounts() { diff --git a/components/signin/ios/browser/profile_oauth2_token_service_ios_delegate_unittest.mm b/components/signin/ios/browser/profile_oauth2_token_service_ios_delegate_unittest.mm index bf4b0b2..6ec18aa 100644 --- a/components/signin/ios/browser/profile_oauth2_token_service_ios_delegate_unittest.mm +++ b/components/signin/ios/browser/profile_oauth2_token_service_ios_delegate_unittest.mm @@ -10,10 +10,10 @@ #include "components/signin/core/browser/profile_oauth2_token_service.h" #include "components/signin/core/browser/test_signin_client.h" #include "components/signin/core/common/signin_pref_names.h" +#include "components/signin/ios/browser/fake_profile_oauth2_token_service_ios_provider.h" #include "google_apis/gaia/gaia_urls.h" #include "google_apis/gaia/oauth2_access_token_consumer.h" #include "google_apis/gaia/oauth2_token_service_test_util.h" -#include "ios/public/test/fake_profile_oauth2_token_service_ios_provider.h" #include "net/url_request/test_url_fetcher_factory.h" #include "testing/gtest/include/gtest/gtest.h" @@ -40,9 +40,8 @@ class ProfileOAuth2TokenServiceIOSDelegateTest factory_.SetFakeResponse(GaiaUrls::GetInstance()->oauth2_revoke_url(), "", net::HTTP_OK, net::URLRequestStatus::SUCCESS); - fake_provider_ = client_.GetIOSProviderAsFake(); oauth2_service_delegate_.reset(new ProfileOAuth2TokenServiceIOSDelegate( - &client_, &signin_error_controller_)); + &client_, &fake_provider_, &signin_error_controller_)); oauth2_service_delegate_->AddObserver(this); } @@ -85,7 +84,7 @@ class ProfileOAuth2TokenServiceIOSDelegateTest TestingPrefServiceSimple prefs_; TestSigninClient client_; SigninErrorController signin_error_controller_; - ios::FakeProfileOAuth2TokenServiceIOSProvider* fake_provider_; + FakeProfileOAuth2TokenServiceIOSProvider fake_provider_; scoped_ptr<ProfileOAuth2TokenServiceIOSDelegate> oauth2_service_delegate_; TestingOAuth2TokenServiceConsumer consumer_; int token_available_count_; @@ -98,7 +97,7 @@ class ProfileOAuth2TokenServiceIOSDelegateTest TEST_F(ProfileOAuth2TokenServiceIOSDelegateTest, LoadRevokeCredentialsOneAccount) { - fake_provider_->AddAccount("account_id"); + fake_provider_.AddAccount("account_id"); oauth2_service_delegate_->LoadCredentials("account_id"); base::RunLoop().RunUntilIdle(); EXPECT_EQ(1, token_available_count_); @@ -119,9 +118,9 @@ TEST_F(ProfileOAuth2TokenServiceIOSDelegateTest, TEST_F(ProfileOAuth2TokenServiceIOSDelegateTest, LoadRevokeCredentialsMultipleAccounts) { - fake_provider_->AddAccount("account_id_1"); - fake_provider_->AddAccount("account_id_2"); - fake_provider_->AddAccount("account_id_3"); + fake_provider_.AddAccount("account_id_1"); + fake_provider_.AddAccount("account_id_2"); + fake_provider_.AddAccount("account_id_3"); oauth2_service_delegate_->LoadCredentials("account_id_1"); base::RunLoop().RunUntilIdle(); EXPECT_EQ(3, token_available_count_); @@ -150,17 +149,17 @@ TEST_F(ProfileOAuth2TokenServiceIOSDelegateTest, } TEST_F(ProfileOAuth2TokenServiceIOSDelegateTest, ReloadCredentials) { - fake_provider_->AddAccount("account_id_1"); - fake_provider_->AddAccount("account_id_2"); - fake_provider_->AddAccount("account_id_3"); + fake_provider_.AddAccount("account_id_1"); + fake_provider_.AddAccount("account_id_2"); + fake_provider_.AddAccount("account_id_3"); oauth2_service_delegate_->LoadCredentials("account_id_1"); base::RunLoop().RunUntilIdle(); // Change the accounts. ResetObserverCounts(); - fake_provider_->ClearAccounts(); - fake_provider_->AddAccount("account_id_1"); - fake_provider_->AddAccount("account_id_4"); + fake_provider_.ClearAccounts(); + fake_provider_.AddAccount("account_id_1"); + fake_provider_.AddAccount("account_id_4"); oauth2_service_delegate_->ReloadCredentials(); EXPECT_EQ(1, token_available_count_); @@ -181,8 +180,8 @@ TEST_F(ProfileOAuth2TokenServiceIOSDelegateTest, ReloadCredentialsIgnoredIfNoPrimaryAccountId) { // Change the accounts. ResetObserverCounts(); - fake_provider_->AddAccount("account_id_1"); - fake_provider_->AddAccount("account_id_2"); + fake_provider_.AddAccount("account_id_1"); + fake_provider_.AddAccount("account_id_2"); base::RunLoop().RunUntilIdle(); oauth2_service_delegate_->ReloadCredentials(); @@ -201,8 +200,8 @@ TEST_F(ProfileOAuth2TokenServiceIOSDelegateTest, ReloadCredentialsWithPrimaryAccountId) { // Change the accounts. ResetObserverCounts(); - fake_provider_->AddAccount("account_id_1"); - fake_provider_->AddAccount("account_id_2"); + fake_provider_.AddAccount("account_id_1"); + fake_provider_.AddAccount("account_id_2"); base::RunLoop().RunUntilIdle(); oauth2_service_delegate_->ReloadCredentials("account_id_1"); @@ -219,8 +218,8 @@ TEST_F(ProfileOAuth2TokenServiceIOSDelegateTest, TEST_F(ProfileOAuth2TokenServiceIOSDelegateTest, ExcludeAllSecondaryAccounts) { // Change the accounts. ResetObserverCounts(); - fake_provider_->AddAccount("account_id_1"); - fake_provider_->AddAccount("account_id_2"); + fake_provider_.AddAccount("account_id_1"); + fake_provider_.AddAccount("account_id_2"); base::RunLoop().RunUntilIdle(); oauth2_service_delegate_->ExcludeAllSecondaryAccounts(); @@ -236,7 +235,7 @@ TEST_F(ProfileOAuth2TokenServiceIOSDelegateTest, ExcludeAllSecondaryAccounts) { } TEST_F(ProfileOAuth2TokenServiceIOSDelegateTest, StartRequestSuccess) { - fake_provider_->AddAccount("account_id_1"); + fake_provider_.AddAccount("account_id_1"); oauth2_service_delegate_->LoadCredentials("account_id_1"); base::RunLoop().RunUntilIdle(); @@ -252,14 +251,14 @@ TEST_F(ProfileOAuth2TokenServiceIOSDelegateTest, StartRequestSuccess) { EXPECT_EQ(0, access_token_failure_); ResetObserverCounts(); - fake_provider_->IssueAccessTokenForAllRequests(); + fake_provider_.IssueAccessTokenForAllRequests(); base::RunLoop().RunUntilIdle(); EXPECT_EQ(1, access_token_success_); EXPECT_EQ(0, access_token_failure_); } TEST_F(ProfileOAuth2TokenServiceIOSDelegateTest, StartRequestFailure) { - fake_provider_->AddAccount("account_id_1"); + fake_provider_.AddAccount("account_id_1"); oauth2_service_delegate_->LoadCredentials("account_id_1"); base::RunLoop().RunUntilIdle(); @@ -275,16 +274,16 @@ TEST_F(ProfileOAuth2TokenServiceIOSDelegateTest, StartRequestFailure) { EXPECT_EQ(0, access_token_failure_); ResetObserverCounts(); - fake_provider_->IssueAccessTokenErrorForAllRequests(); + fake_provider_.IssueAccessTokenErrorForAllRequests(); base::RunLoop().RunUntilIdle(); EXPECT_EQ(0, access_token_success_); EXPECT_EQ(1, access_token_failure_); } TEST_F(ProfileOAuth2TokenServiceIOSDelegateTest, ExcludeSecondaryAccounts) { - fake_provider_->AddAccount("account_id_1"); - fake_provider_->AddAccount("account_id_2"); - fake_provider_->AddAccount("account_id_3"); + fake_provider_.AddAccount("account_id_1"); + fake_provider_.AddAccount("account_id_2"); + fake_provider_.AddAccount("account_id_3"); oauth2_service_delegate_->LoadCredentials("account_id_1"); base::RunLoop().RunUntilIdle(); @@ -323,8 +322,8 @@ TEST_F(ProfileOAuth2TokenServiceIOSDelegateTest, ExcludeSecondaryAccounts) { // Unit test for for http://crbug.com/453470 . TEST_F(ProfileOAuth2TokenServiceIOSDelegateTest, ExcludeSecondaryAccountTwice) { - fake_provider_->AddAccount("account_id_1"); - fake_provider_->AddAccount("account_id_2"); + fake_provider_.AddAccount("account_id_1"); + fake_provider_.AddAccount("account_id_2"); oauth2_service_delegate_->LoadCredentials("account_id_1"); base::RunLoop().RunUntilIdle(); EXPECT_TRUE( @@ -354,9 +353,9 @@ TEST_F(ProfileOAuth2TokenServiceIOSDelegateTest, ExcludeSecondaryAccountTwice) { TEST_F(ProfileOAuth2TokenServiceIOSDelegateTest, LoadRevokeCredentialsClearsExcludedAccounts) { - fake_provider_->AddAccount("account_id_1"); - fake_provider_->AddAccount("account_id_2"); - fake_provider_->AddAccount("account_id_3"); + fake_provider_.AddAccount("account_id_1"); + fake_provider_.AddAccount("account_id_2"); + fake_provider_.AddAccount("account_id_3"); std::vector<std::string> excluded_accounts; excluded_accounts.push_back("account_id_2"); diff --git a/components/signin/ios/browser/profile_oauth2_token_service_ios_provider.h b/components/signin/ios/browser/profile_oauth2_token_service_ios_provider.h new file mode 100644 index 0000000..ad9966d --- /dev/null +++ b/components/signin/ios/browser/profile_oauth2_token_service_ios_provider.h @@ -0,0 +1,78 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_SIGNIN_IOS_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_PROVIDER_H_ +#define COMPONENTS_SIGNIN_IOS_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_PROVIDER_H_ + +#if defined(__OBJC__) +@class NSDate; +@class NSError; +@class NSString; +#else +class NSDate; +class NSError; +class NSString; +#endif // defined(__OBJC__) + +#include <set> +#include <string> +#include <vector> + +#include "base/callback.h" + +// Account information. +struct AccountInfo { + AccountInfo() {} + ~AccountInfo() {} + std::string gaia; + std::string email; +}; + +enum AuthenticationErrorCategory { + // Unknown errors. + kAuthenticationErrorCategoryUnknownErrors, + // Authorization errors. + kAuthenticationErrorCategoryAuthorizationErrors, + // Authorization errors with HTTP_FORBIDDEN (403) error code. + kAuthenticationErrorCategoryAuthorizationForbiddenErrors, + // Network server errors includes parsing error and should be treated as + // transient/offline errors. + kAuthenticationErrorCategoryNetworkServerErrors, + // User cancellation errors should be handled by treating them as a no-op. + kAuthenticationErrorCategoryUserCancellationErrors, + // User identity not found errors. + kAuthenticationErrorCategoryUnknownIdentityErrors, +}; + +// Interface that provides support for ProfileOAuth2TokenServiceIOS. +class ProfileOAuth2TokenServiceIOSProvider { + public: + typedef base::Callback<void(NSString* token, + NSDate* expiration, + NSError* error)> AccessTokenCallback; + + ProfileOAuth2TokenServiceIOSProvider() {} + virtual ~ProfileOAuth2TokenServiceIOSProvider() {} + + // Returns the ids of all accounts. + virtual std::vector<std::string> GetAllAccountIds() = 0; + + // Starts fetching an access token for the account with id |account_id| with + // the given |scopes|. Once the token is obtained, |callback| is called. + virtual void GetAccessToken(const std::string& account_id, + const std::string& client_id, + const std::string& client_secret, + const std::set<std::string>& scopes, + const AccessTokenCallback& callback) = 0; + + // Returns the authentication error category of |error|. + virtual AuthenticationErrorCategory GetAuthenticationErrorCategory( + NSError* error) const = 0; + + // Returns the account info composed of a GAIA id and email corresponding to + // |account_id|. + virtual AccountInfo GetAccountInfo(const std::string& account_id) const = 0; +}; + +#endif // COMPONENTS_SIGNIN_IOS_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_PROVIDER_H_ |