Commit fdd91ad2 authored by msarda@chromium.org's avatar msarda@chromium.org

Move RevokeCredentialsOnServer to MutableProfileOAuth2TokenService

This CL moves RevokeCredentialsOnServer and GetRequestContext from
ProfileOAuth2TokenService to MutableProfileOAuth2TokenService.

BUG=320625

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242113 0039d316-1c4b-4281-b951-d872f2087c98
parent 101d0307
...@@ -140,16 +140,6 @@ std::string FakeProfileOAuth2TokenService::GetRefreshToken( ...@@ -140,16 +140,6 @@ std::string FakeProfileOAuth2TokenService::GetRefreshToken(
std::string(); std::string();
} }
net::URLRequestContextGetter*
FakeProfileOAuth2TokenService::GetRequestContext() {
return NULL;
}
void FakeProfileOAuth2TokenService::RevokeCredentialsOnServer(
const std::string& refresh_token) {
// Don't try to contact server in tests.
}
std::vector<FakeProfileOAuth2TokenService::PendingRequest> std::vector<FakeProfileOAuth2TokenService::PendingRequest>
FakeProfileOAuth2TokenService::GetPendingRequests() { FakeProfileOAuth2TokenService::GetPendingRequests() {
std::vector<PendingRequest> valid_requests; std::vector<PendingRequest> valid_requests;
......
...@@ -124,11 +124,6 @@ class FakeProfileOAuth2TokenService ...@@ -124,11 +124,6 @@ class FakeProfileOAuth2TokenService
virtual std::string GetRefreshToken(const std::string& account_id) OVERRIDE; virtual std::string GetRefreshToken(const std::string& account_id) OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
virtual void RevokeCredentialsOnServer(
const std::string& refresh_token) OVERRIDE;
private: private:
// Helper function to complete pending requests - if |all_scopes| is true, // Helper function to complete pending requests - if |all_scopes| is true,
// then all pending requests are completed, otherwise, only those requests // then all pending requests are completed, otherwise, only those requests
......
...@@ -7,7 +7,10 @@ ...@@ -7,7 +7,10 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/webdata/token_web_data.h" #include "chrome/browser/webdata/token_web_data.h"
#include "components/webdata/common/web_data_service_base.h" #include "components/webdata/common/web_data_service_base.h"
#include "google_apis/gaia/gaia_auth_fetcher.h"
#include "google_apis/gaia/gaia_constants.h" #include "google_apis/gaia/gaia_constants.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "net/url_request/url_request_context_getter.h"
#if defined(ENABLE_MANAGED_USERS) #if defined(ENABLE_MANAGED_USERS)
#include "chrome/browser/managed_mode/managed_user_constants.h" #include "chrome/browser/managed_mode/managed_user_constants.h"
...@@ -34,6 +37,39 @@ std::string RemoveAccountIdPrefix(const std::string& prefixed_account_id) { ...@@ -34,6 +37,39 @@ std::string RemoveAccountIdPrefix(const std::string& prefixed_account_id) {
return prefixed_account_id.substr(kAccountIdPrefixLength); return prefixed_account_id.substr(kAccountIdPrefixLength);
} }
// This class sends a request to GAIA to revoke the given refresh token from
// the server. This is a best effort attempt only. This class deletes itself
// when done sucessfully or otherwise.
class RevokeServerRefreshToken : public GaiaAuthConsumer {
public:
RevokeServerRefreshToken(const std::string& account_id,
net::URLRequestContextGetter* request_context);
virtual ~RevokeServerRefreshToken();
private:
// GaiaAuthConsumer overrides:
virtual void OnOAuth2RevokeTokenCompleted() OVERRIDE;
scoped_refptr<net::URLRequestContextGetter> request_context_;
GaiaAuthFetcher fetcher_;
DISALLOW_COPY_AND_ASSIGN(RevokeServerRefreshToken);
};
RevokeServerRefreshToken::RevokeServerRefreshToken(
const std::string& refresh_token,
net::URLRequestContextGetter* request_context)
: request_context_(request_context),
fetcher_(this, GaiaConstants::kChromeSource, request_context) {
fetcher_.StartRevokeOAuth2Token(refresh_token);
}
RevokeServerRefreshToken::~RevokeServerRefreshToken() {}
void RevokeServerRefreshToken::OnOAuth2RevokeTokenCompleted() {
delete this;
}
} // namespace } // namespace
MutableProfileOAuth2TokenService::MutableProfileOAuth2TokenService() MutableProfileOAuth2TokenService::MutableProfileOAuth2TokenService()
...@@ -54,6 +90,11 @@ void MutableProfileOAuth2TokenService::Shutdown() { ...@@ -54,6 +90,11 @@ void MutableProfileOAuth2TokenService::Shutdown() {
ProfileOAuth2TokenService::Shutdown(); ProfileOAuth2TokenService::Shutdown();
} }
net::URLRequestContextGetter*
MutableProfileOAuth2TokenService::GetRequestContext() {
return profile()->GetRequestContext();
}
void MutableProfileOAuth2TokenService::LoadCredentials() { void MutableProfileOAuth2TokenService::LoadCredentials() {
DCHECK_EQ(0, web_data_service_request_); DCHECK_EQ(0, web_data_service_request_);
...@@ -168,3 +209,9 @@ MutableProfileOAuth2TokenService::GetAccountIdForMigratingRefreshToken() { ...@@ -168,3 +209,9 @@ MutableProfileOAuth2TokenService::GetAccountIdForMigratingRefreshToken() {
return GetPrimaryAccountId(); return GetPrimaryAccountId();
} }
void MutableProfileOAuth2TokenService::RevokeCredentialsOnServer(
const std::string& refresh_token) {
// RevokeServerRefreshToken deletes itself when done.
new RevokeServerRefreshToken(refresh_token, GetRequestContext());
}
...@@ -26,6 +26,9 @@ class MutableProfileOAuth2TokenService : public ProfileOAuth2TokenService, ...@@ -26,6 +26,9 @@ class MutableProfileOAuth2TokenService : public ProfileOAuth2TokenService,
MutableProfileOAuth2TokenService(); MutableProfileOAuth2TokenService();
virtual ~MutableProfileOAuth2TokenService(); virtual ~MutableProfileOAuth2TokenService();
// OAuth2TokenService implementation.
virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
private: private:
FRIEND_TEST_ALL_PREFIXES(MutableProfileOAuth2TokenServiceTest, FRIEND_TEST_ALL_PREFIXES(MutableProfileOAuth2TokenServiceTest,
TokenServiceUpdateClearsCache); TokenServiceUpdateClearsCache);
...@@ -57,6 +60,10 @@ class MutableProfileOAuth2TokenService : public ProfileOAuth2TokenService, ...@@ -57,6 +60,10 @@ class MutableProfileOAuth2TokenService : public ProfileOAuth2TokenService,
virtual void ClearPersistedCredentials( virtual void ClearPersistedCredentials(
const std::string& account_id) OVERRIDE; const std::string& account_id) OVERRIDE;
// Revokes the refresh token on the server.
virtual void RevokeCredentialsOnServer(
const std::string& refresh_token) OVERRIDE;
// Handle to the request reading tokens from database. // Handle to the request reading tokens from database.
WebDataServiceBase::Handle web_data_service_request_; WebDataServiceBase::Handle web_data_service_request_;
......
...@@ -23,47 +23,6 @@ ...@@ -23,47 +23,6 @@
#include "google_apis/gaia/google_service_auth_error.h" #include "google_apis/gaia/google_service_auth_error.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
namespace {
// This class sends a request to GAIA to revoke the given refresh token from
// the server. This is a best effort attempt only. This class deletes itself
// when done sucessfully or otherwise.
class RevokeServerRefreshToken : public GaiaAuthConsumer {
public:
RevokeServerRefreshToken(const std::string& account_id,
net::URLRequestContextGetter* request_context);
virtual ~RevokeServerRefreshToken();
private:
// GaiaAuthConsumer overrides:
virtual void OnOAuth2RevokeTokenCompleted() OVERRIDE;
scoped_refptr<net::URLRequestContextGetter> request_context_;
scoped_ptr<GaiaAuthFetcher> fetcher_;
DISALLOW_COPY_AND_ASSIGN(RevokeServerRefreshToken);
};
RevokeServerRefreshToken::RevokeServerRefreshToken(
const std::string& refresh_token,
net::URLRequestContextGetter* request_context)
: request_context_(request_context) {
fetcher_.reset(
new GaiaAuthFetcher(this,
GaiaConstants::kChromeSource,
request_context_.get()));
fetcher_->StartRevokeOAuth2Token(refresh_token);
}
RevokeServerRefreshToken::~RevokeServerRefreshToken() {}
void RevokeServerRefreshToken::OnOAuth2RevokeTokenCompleted() {
delete this;
}
} // namespace
ProfileOAuth2TokenService::AccountInfo::AccountInfo( ProfileOAuth2TokenService::AccountInfo::AccountInfo(
ProfileOAuth2TokenService* token_service, ProfileOAuth2TokenService* token_service,
const std::string& account_id, const std::string& account_id,
...@@ -136,7 +95,7 @@ std::string ProfileOAuth2TokenService::GetRefreshToken( ...@@ -136,7 +95,7 @@ std::string ProfileOAuth2TokenService::GetRefreshToken(
} }
net::URLRequestContextGetter* ProfileOAuth2TokenService::GetRequestContext() { net::URLRequestContextGetter* ProfileOAuth2TokenService::GetRequestContext() {
return profile_->GetRequestContext(); return NULL;
} }
void ProfileOAuth2TokenService::UpdateAuthError( void ProfileOAuth2TokenService::UpdateAuthError(
...@@ -261,6 +220,5 @@ void ProfileOAuth2TokenService::LoadCredentials() { ...@@ -261,6 +220,5 @@ void ProfileOAuth2TokenService::LoadCredentials() {
void ProfileOAuth2TokenService::RevokeCredentialsOnServer( void ProfileOAuth2TokenService::RevokeCredentialsOnServer(
const std::string& refresh_token) { const std::string& refresh_token) {
// RevokeServerRefreshToken deletes itself when done. // Empty implementation by default.
new RevokeServerRefreshToken(refresh_token, GetRequestContext());
} }
...@@ -151,6 +151,9 @@ class ProfileOAuth2TokenService : public OAuth2TokenService, ...@@ -151,6 +151,9 @@ class ProfileOAuth2TokenService : public OAuth2TokenService,
PersistenceLoadCredentials); PersistenceLoadCredentials);
// Revokes the refresh token on the server. // Revokes the refresh token on the server.
//
// Note: Empty implementation as all credentials logic is being migrated to
// MutableProfileOAuth2TokenService.
virtual void RevokeCredentialsOnServer(const std::string& refresh_token); virtual void RevokeCredentialsOnServer(const std::string& refresh_token);
// The profile with which this instance was initialized, or NULL. // The profile with which this instance was initialized, or NULL.
......
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