Commit 8153ccfd authored by msarda@chromium.org's avatar msarda@chromium.org

Remove MutableProfileOAuth2TokenService on iOS.

Shared Authentication is the only supported scheme starting with M39.
This CL removes the dependency on MutableProfileOAuth2TokenService
on iOS.

BUG=233117

Review URL: https://codereview.chromium.org/489113003

Cr-Commit-Position: refs/heads/master@{#291189}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291189 0039d316-1c4b-4281-b951-d872f2087c98
parent b733d244
...@@ -488,6 +488,7 @@ ...@@ -488,6 +488,7 @@
['include', '^search_engines/'], ['include', '^search_engines/'],
['include', '^search_provider_logos/'], ['include', '^search_provider_logos/'],
['include', '^signin/'], ['include', '^signin/'],
['exclude', '^signin/core/browser/mutable_profile_oauth2_token_service_unittest\\.cc$'],
['include', '^sync_driver/'], ['include', '^sync_driver/'],
['include', '^translate/'], ['include', '^translate/'],
['include', '^url_fixer/'], ['include', '^url_fixer/'],
......
...@@ -77,9 +77,9 @@ ...@@ -77,9 +77,9 @@
'signin/core/browser/webdata/token_web_data.h', 'signin/core/browser/webdata/token_web_data.h',
], ],
'conditions': [ 'conditions': [
['OS=="android"', { ['OS=="android" or OS=="ios"', {
'sources!': [ 'sources!': [
# Not used on Android. # Not used on Android nor iOS.
'signin/core/browser/mutable_profile_oauth2_token_service.cc', 'signin/core/browser/mutable_profile_oauth2_token_service.cc',
'signin/core/browser/mutable_profile_oauth2_token_service.h', 'signin/core/browser/mutable_profile_oauth2_token_service.h',
], ],
......
...@@ -270,16 +270,6 @@ void MutableProfileOAuth2TokenService::UpdateAuthError( ...@@ -270,16 +270,6 @@ void MutableProfileOAuth2TokenService::UpdateAuthError(
error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE) error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE)
return; return;
#if defined(OS_IOS)
// ProfileOauth2TokenService does not manage the refresh tokens on iOS - the
// account info on iOS is only used to manage the authentication error state.
// Simply add an account info entry with empty refresh token if none exists.
if (refresh_tokens_.count(account_id) == 0) {
refresh_tokens_[account_id].reset(
new AccountInfo(this, account_id, std::string()));
}
#endif
if (refresh_tokens_.count(account_id) == 0) { if (refresh_tokens_.count(account_id) == 0) {
// This could happen if the preferences have been corrupted (see // This could happen if the preferences have been corrupted (see
// http://crbug.com/321370). In a Debug build that would be a bug, but in a // http://crbug.com/321370). In a Debug build that would be a bug, but in a
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <string> #include <string>
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
#include "components/signin/core/browser/mutable_profile_oauth2_token_service.h" #include "components/signin/core/browser/profile_oauth2_token_service.h"
class OAuth2AccessTokenFetcher; class OAuth2AccessTokenFetcher;
...@@ -24,11 +24,8 @@ class ProfileOAuth2TokenServiceIOSProvider; ...@@ -24,11 +24,8 @@ class ProfileOAuth2TokenServiceIOSProvider;
// //
// Note: Requests should be started from the UI thread. To start a // Note: Requests should be started from the UI thread. To start a
// request from aother thread, please use OAuth2TokenServiceRequest. // request from aother thread, please use OAuth2TokenServiceRequest.
class ProfileOAuth2TokenServiceIOS : public MutableProfileOAuth2TokenService { class ProfileOAuth2TokenServiceIOS : public ProfileOAuth2TokenService {
public: public:
ProfileOAuth2TokenServiceIOS();
virtual ~ProfileOAuth2TokenServiceIOS();
// KeyedService // KeyedService
virtual void Shutdown() OVERRIDE; virtual void Shutdown() OVERRIDE;
...@@ -57,36 +54,18 @@ class ProfileOAuth2TokenServiceIOS : public MutableProfileOAuth2TokenService { ...@@ -57,36 +54,18 @@ class ProfileOAuth2TokenServiceIOS : public MutableProfileOAuth2TokenService {
// Subsequent calls to |RefreshTokenIsAvailable| will return |false|. // Subsequent calls to |RefreshTokenIsAvailable| will return |false|.
virtual void RevokeAllCredentials() OVERRIDE; virtual void RevokeAllCredentials() OVERRIDE;
// Returns the refresh token for |account_id| .
// Must only be called when |ShouldUseIOSSharedAuthentication| returns false.
std::string GetRefreshTokenWhenNotUsingSharedAuthentication(
const std::string& account_id);
// Reloads accounts from the provider. Fires |OnRefreshTokenAvailable| for // Reloads accounts from the provider. Fires |OnRefreshTokenAvailable| for
// each new account. Fires |OnRefreshTokenRevoked| for each account that was // each new account. Fires |OnRefreshTokenRevoked| for each account that was
// removed. // removed.
void ReloadCredentials(); void ReloadCredentials();
// Upgrades to using shared authentication token service.
//
// Note: If this |ProfileOAuth2TokenServiceIOS| was using the legacy token
// service, then this call also revokes all tokens from the parent
// |MutableProfileOAuth2TokenService|.
void StartUsingSharedAuthentication();
// Sets |use_legacy_token_service_| to |use_legacy_token_service|.
//
// Should only be called for testing.
void SetUseLegacyTokenServiceForTesting(bool use_legacy_token_service);
// Revokes the OAuth2 refresh tokens for all accounts from the parent
// |MutableProfileOAuth2TokenService|.
//
// Note: This method should only be called if the legacy pre-SSOAuth token
// service is used.
void ForceInvalidGrantResponses();
protected: protected:
friend class ProfileOAuth2TokenServiceFactory;
friend class ProfileOAuth2TokenServiceIOSTest;
ProfileOAuth2TokenServiceIOS();
virtual ~ProfileOAuth2TokenServiceIOS();
virtual OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( virtual OAuth2AccessTokenFetcher* CreateAccessTokenFetcher(
const std::string& account_id, const std::string& account_id,
net::URLRequestContextGetter* getter, net::URLRequestContextGetter* getter,
...@@ -129,10 +108,6 @@ class ProfileOAuth2TokenServiceIOS : public MutableProfileOAuth2TokenService { ...@@ -129,10 +108,6 @@ class ProfileOAuth2TokenServiceIOS : public MutableProfileOAuth2TokenService {
// to information about the account. // to information about the account.
typedef std::map<std::string, linked_ptr<AccountInfo> > AccountInfoMap; typedef std::map<std::string, linked_ptr<AccountInfo> > AccountInfoMap;
// MutableProfileOAuth2TokenService
virtual std::string GetRefreshToken(
const std::string& account_id) const OVERRIDE;
// Returns the iOS provider; // Returns the iOS provider;
ios::ProfileOAuth2TokenServiceIOSProvider* GetProvider(); ios::ProfileOAuth2TokenServiceIOSProvider* GetProvider();
...@@ -140,23 +115,10 @@ class ProfileOAuth2TokenServiceIOS : public MutableProfileOAuth2TokenService { ...@@ -140,23 +115,10 @@ class ProfileOAuth2TokenServiceIOS : public MutableProfileOAuth2TokenService {
AccountInfoMap accounts_; AccountInfoMap accounts_;
// Calls to this class are expected to be made from the browser UI thread. // Calls to this class are expected to be made from the browser UI thread.
// The purpose of this this checker is to warn us if the upstream usage of // The purpose of this checker is to detect access to
// ProfileOAuth2TokenService ever gets changed to have it be used across // ProfileOAuth2TokenService from multiple threads in upstream code.
// multiple threads.
base::ThreadChecker thread_checker_; base::ThreadChecker thread_checker_;
// Whether to use the legacy pre-SSOAuth token service.
//
// |use_legacy_token_service_| is true iff the provider is not using shared
// authentication during |LoadCredentials|. Note that |LoadCredentials| is
// called exactly once after the PO2TS initialization iff the user is signed
// in.
//
// If |use_legacy_token_service_| is true, then this
// |ProfileOAuth2TokenServiceIOS| delegates all calls to the parent
// |MutableProfileOAuth2TokenService|.
bool use_legacy_token_service_;
DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenServiceIOS); DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenServiceIOS);
}; };
......
...@@ -32,7 +32,6 @@ class ProfileOAuth2TokenServiceIOSTest : public testing::Test, ...@@ -32,7 +32,6 @@ class ProfileOAuth2TokenServiceIOSTest : public testing::Test,
net::HTTP_OK, net::HTTP_OK,
net::URLRequestStatus::SUCCESS); net::URLRequestStatus::SUCCESS);
fake_provider_ = client_.GetIOSProviderAsFake(); fake_provider_ = client_.GetIOSProviderAsFake();
fake_provider_->set_using_shared_authentication(true);
oauth2_service_.Initialize(&client_); oauth2_service_.Initialize(&client_);
oauth2_service_.AddObserver(this); oauth2_service_.AddObserver(this);
} }
...@@ -197,80 +196,3 @@ TEST_F(ProfileOAuth2TokenServiceIOSTest, StartRequestFailure) { ...@@ -197,80 +196,3 @@ TEST_F(ProfileOAuth2TokenServiceIOSTest, StartRequestFailure) {
EXPECT_EQ(0, access_token_success_); EXPECT_EQ(0, access_token_success_);
EXPECT_EQ(1, access_token_failure_); EXPECT_EQ(1, access_token_failure_);
} }
TEST_F(ProfileOAuth2TokenServiceIOSTest, Migration) {
fake_provider_->set_using_shared_authentication(false);
oauth2_service_.LoadCredentials("account_id_1");
base::RunLoop().RunUntilIdle();
ResetObserverCounts();
oauth2_service_.UpdateCredentials("account_id_1", "pre_sso_refresh_token_1");
oauth2_service_.UpdateCredentials("account_id_2", "pre_sso_refresh_token_2");
EXPECT_EQ(2, token_available_count_);
EXPECT_EQ(0, tokens_loaded_count_);
EXPECT_EQ(0, token_revoked_count_);
EXPECT_EQ(2U, oauth2_service_.GetAccounts().size());
EXPECT_TRUE(oauth2_service_.RefreshTokenIsAvailable("account_id_1"));
EXPECT_TRUE(oauth2_service_.RefreshTokenIsAvailable("account_id_2"));
EXPECT_EQ("pre_sso_refresh_token_1",
oauth2_service_.GetRefreshTokenWhenNotUsingSharedAuthentication(
"account_id_1"));
EXPECT_EQ("pre_sso_refresh_token_2",
oauth2_service_.GetRefreshTokenWhenNotUsingSharedAuthentication(
"account_id_2"));
ResetObserverCounts();
oauth2_service_.StartUsingSharedAuthentication();
EXPECT_EQ(0, token_available_count_);
EXPECT_EQ(0, tokens_loaded_count_);
EXPECT_EQ(2, token_revoked_count_);
EXPECT_EQ(0U, oauth2_service_.GetAccounts().size());
EXPECT_FALSE(oauth2_service_.RefreshTokenIsAvailable("account_id_1"));
EXPECT_FALSE(oauth2_service_.RefreshTokenIsAvailable("account_id_2"));
ResetObserverCounts();
fake_provider_->AddAccount("account_id_1");
oauth2_service_.ReloadCredentials();
EXPECT_EQ(1, token_available_count_);
EXPECT_EQ(0, tokens_loaded_count_);
EXPECT_EQ(0, token_revoked_count_);
EXPECT_EQ(1U, oauth2_service_.GetAccounts().size());
EXPECT_TRUE(oauth2_service_.RefreshTokenIsAvailable("account_id_1"));
EXPECT_FALSE(oauth2_service_.RefreshTokenIsAvailable("account_id_2"));
}
TEST_F(ProfileOAuth2TokenServiceIOSTest, ForceInvalidGrantResponses) {
fake_provider_->set_using_shared_authentication(false);
oauth2_service_.LoadCredentials("account_id_1");
base::RunLoop().RunUntilIdle();
oauth2_service_.UpdateCredentials("account_id_1", "pre_sso_refresh_token_1");
EXPECT_TRUE(oauth2_service_.RefreshTokenIsAvailable("account_id_1"));
// First call revokes the existing token and then updates the credentials
// with a fake token.
ResetObserverCounts();
oauth2_service_.ForceInvalidGrantResponses();
EXPECT_EQ(1, token_available_count_);
EXPECT_EQ(0, tokens_loaded_count_);
EXPECT_EQ(1, token_revoked_count_);
EXPECT_TRUE(oauth2_service_.RefreshTokenIsAvailable("account_id_1"));
// Fetching access tokens fails with invalid grant responses.
OAuth2TokenService::ScopeSet scopes;
scopes.insert("scope");
scoped_ptr<OAuth2TokenService::Request> request(
oauth2_service_.StartRequest("account_id_1", scopes, this));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, access_token_success_);
EXPECT_EQ(1, access_token_failure_);
EXPECT_EQ(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS,
last_access_token_error_.state());
// Second call to force invalid grant responses is ignored.
ResetObserverCounts();
oauth2_service_.ForceInvalidGrantResponses();
EXPECT_EQ(0, token_available_count_);
EXPECT_EQ(0, tokens_loaded_count_);
EXPECT_EQ(0, token_revoked_count_);
EXPECT_TRUE(oauth2_service_.RefreshTokenIsAvailable("account_id_1"));
}
...@@ -235,7 +235,6 @@ OAuth2TokenService::Fetcher::Fetcher( ...@@ -235,7 +235,6 @@ OAuth2TokenService::Fetcher::Fetcher(
client_id_(client_id), client_id_(client_id),
client_secret_(client_secret) { client_secret_(client_secret) {
DCHECK(oauth2_token_service_); DCHECK(oauth2_token_service_);
DCHECK(getter_.get());
waiting_requests_.push_back(waiting_request); waiting_requests_.push_back(waiting_request);
} }
......
...@@ -49,9 +49,6 @@ class ProfileOAuth2TokenServiceIOSProvider { ...@@ -49,9 +49,6 @@ class ProfileOAuth2TokenServiceIOSProvider {
ProfileOAuth2TokenServiceIOSProvider() {}; ProfileOAuth2TokenServiceIOSProvider() {};
virtual ~ProfileOAuth2TokenServiceIOSProvider() {}; virtual ~ProfileOAuth2TokenServiceIOSProvider() {};
// Returns whether authentication is using the shared authentication library.
virtual bool IsUsingSharedAuthentication() const = 0;
// Initializes the shared authentication library. This method should be called // Initializes the shared authentication library. This method should be called
// when loading credentials if the user is signed in to Chrome via the shared // when loading credentials if the user is signed in to Chrome via the shared
// authentication library. // authentication library.
......
...@@ -22,7 +22,6 @@ class FakeProfileOAuth2TokenServiceIOSProvider ...@@ -22,7 +22,6 @@ class FakeProfileOAuth2TokenServiceIOSProvider
virtual ~FakeProfileOAuth2TokenServiceIOSProvider(); virtual ~FakeProfileOAuth2TokenServiceIOSProvider();
// ProfileOAuth2TokenServiceIOSProvider // ProfileOAuth2TokenServiceIOSProvider
virtual bool IsUsingSharedAuthentication() const OVERRIDE;
virtual void InitializeSharedAuthentication() OVERRIDE; virtual void InitializeSharedAuthentication() OVERRIDE;
virtual void GetAccessToken(const std::string& account_id, virtual void GetAccessToken(const std::string& account_id,
...@@ -40,9 +39,6 @@ class FakeProfileOAuth2TokenServiceIOSProvider ...@@ -40,9 +39,6 @@ class FakeProfileOAuth2TokenServiceIOSProvider
void AddAccount(const std::string& account_id); void AddAccount(const std::string& account_id);
void SetAccounts(const std::vector<std::string>& accounts); void SetAccounts(const std::vector<std::string>& accounts);
void ClearAccounts(); void ClearAccounts();
void set_using_shared_authentication(bool is_using_shared_authentication) {
is_using_shared_authentication_ = is_using_shared_authentication;
}
// Issues access token responses. // Issues access token responses.
void IssueAccessTokenForAllRequests(); void IssueAccessTokenForAllRequests();
...@@ -52,7 +48,6 @@ class FakeProfileOAuth2TokenServiceIOSProvider ...@@ -52,7 +48,6 @@ class FakeProfileOAuth2TokenServiceIOSProvider
typedef std::pair<std::string, AccessTokenCallback> AccessTokenRequest; typedef std::pair<std::string, AccessTokenCallback> AccessTokenRequest;
std::vector<std::string> accounts_; std::vector<std::string> accounts_;
bool is_using_shared_authentication_;
std::vector<AccessTokenRequest> requests_; std::vector<AccessTokenRequest> requests_;
DISALLOW_COPY_AND_ASSIGN(FakeProfileOAuth2TokenServiceIOSProvider); DISALLOW_COPY_AND_ASSIGN(FakeProfileOAuth2TokenServiceIOSProvider);
......
...@@ -12,8 +12,7 @@ ...@@ -12,8 +12,7 @@
namespace ios { namespace ios {
FakeProfileOAuth2TokenServiceIOSProvider:: FakeProfileOAuth2TokenServiceIOSProvider::
FakeProfileOAuth2TokenServiceIOSProvider() FakeProfileOAuth2TokenServiceIOSProvider() {}
: is_using_shared_authentication_(true) {}
FakeProfileOAuth2TokenServiceIOSProvider:: FakeProfileOAuth2TokenServiceIOSProvider::
~FakeProfileOAuth2TokenServiceIOSProvider() {} ~FakeProfileOAuth2TokenServiceIOSProvider() {}
...@@ -24,7 +23,6 @@ void FakeProfileOAuth2TokenServiceIOSProvider::GetAccessToken( ...@@ -24,7 +23,6 @@ void FakeProfileOAuth2TokenServiceIOSProvider::GetAccessToken(
const std::string& client_secret, const std::string& client_secret,
const std::set<std::string>& scopes, const std::set<std::string>& scopes,
const AccessTokenCallback& callback) { const AccessTokenCallback& callback) {
DCHECK(is_using_shared_authentication_);
requests_.push_back(AccessTokenRequest(account_id, callback)); requests_.push_back(AccessTokenRequest(account_id, callback));
} }
...@@ -73,11 +71,6 @@ void FakeProfileOAuth2TokenServiceIOSProvider:: ...@@ -73,11 +71,6 @@ void FakeProfileOAuth2TokenServiceIOSProvider::
requests_.clear(); requests_.clear();
} }
bool FakeProfileOAuth2TokenServiceIOSProvider::IsUsingSharedAuthentication()
const {
return is_using_shared_authentication_;
}
void void
FakeProfileOAuth2TokenServiceIOSProvider::InitializeSharedAuthentication() {} FakeProfileOAuth2TokenServiceIOSProvider::InitializeSharedAuthentication() {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment