Commit 0e14f17d authored by satorux@chromium.org's avatar satorux@chromium.org

gdata: Rename functions in GDataAuthService per OAuth2 terminology

This is based on a suggestion from derat@ at
http://codereview.chromium.org/10808108/

Reference:
http://code.google.com/apis/accounts/docs/OAuth2WebServer.html

BUG=none
TEST=out/Release/unit_tests --gtest_filter='GData*'

Review URL: https://chromiumcodereview.appspot.com/10827018

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148540 0039d316-1c4b-4281-b951-d872f2087c98
parent cc4a3798
......@@ -55,10 +55,10 @@ void GDataAuthService::StartAuthentication(
scoped_refptr<base::MessageLoopProxy> relay_proxy(
base::MessageLoopProxy::current());
if (IsFullyAuthenticated()) {
if (HasAccessToken()) {
relay_proxy->PostTask(FROM_HERE,
base::Bind(callback, gdata::HTTP_SUCCESS, oauth2_auth_token()));
} else if (IsPartiallyAuthenticated()) {
base::Bind(callback, gdata::HTTP_SUCCESS, access_token_));
} else if (HasRefreshToken()) {
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
......@@ -83,22 +83,22 @@ void GDataAuthService::StartAuthenticationOnUIThread(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// We have refresh token, let's gets authenticated.
(new AuthOperation(registry, profile_,
callback, GetOAuth2RefreshToken()))->Start();
callback, refresh_token_))->Start();
}
void GDataAuthService::OnAuthCompleted(
scoped_refptr<base::MessageLoopProxy> relay_proxy,
const AuthStatusCallback& callback,
GDataErrorCode error,
const std::string& auth_token) {
const std::string& access_token) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (error == HTTP_SUCCESS)
auth_token_ = auth_token;
access_token_ = access_token;
// TODO(zelidrag): Add retry, back-off logic when things go wrong here.
if (!callback.is_null())
relay_proxy->PostTask(FROM_HERE, base::Bind(callback, error, auth_token));
relay_proxy->PostTask(FROM_HERE, base::Bind(callback, error, access_token));
}
void GDataAuthService::AddObserver(Observer* observer) {
......@@ -120,7 +120,7 @@ void GDataAuthService::Observe(int type,
if (token_details->service() != GaiaConstants::kGaiaOAuth2LoginRefreshToken)
return;
auth_token_.clear();
access_token_.clear();
if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) {
TokenService* service = TokenServiceFactory::GetForProfile(profile_);
refresh_token_ = service->GetOAuth2LoginRefreshToken();
......
......@@ -54,36 +54,35 @@ class GDataAuthService : public content::NotificationObserver {
void StartAuthentication(GDataOperationRegistry* registry,
const AuthStatusCallback& callback);
// True if OAuth2 auth token is retrieved and believed to be fresh.
bool IsFullyAuthenticated() const { return !auth_token_.empty(); }
// True if an OAuth2 access token is retrieved and believed to be fresh.
// The access token is used to access the gdata server.
bool HasAccessToken() const { return !access_token_.empty(); }
// True if OAuth2 refresh token is present. It's absence means that user
// True if an OAuth2 refresh token is present. Its absence means that user
// is not properly authenticated.
bool IsPartiallyAuthenticated() const { return !refresh_token_.empty(); }
// The refresh token is used to get the access token.
bool HasRefreshToken() const { return !refresh_token_.empty(); }
// Gets OAuth2 auth token.
const std::string& oauth2_auth_token() const { return auth_token_; }
// Returns OAuth2 access token.
const std::string& access_token() const { return access_token_; }
// Clears OAuth2 token.
void ClearOAuth2Token() { auth_token_.clear(); }
// Gets OAuth2 refresh token.
const std::string& GetOAuth2RefreshToken() { return refresh_token_; }
// Clears OAuth2 access token.
void ClearAccessToken() { access_token_.clear(); }
// Callback for AuthOperation (InternalAuthStatusCallback).
void OnAuthCompleted(scoped_refptr<base::MessageLoopProxy> relay_proxy,
const AuthStatusCallback& callback,
GDataErrorCode error,
const std::string& auth_token);
const std::string& access_token);
// Overridden from content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// Sets the auth_token as specified. This should be used only for testing.
void set_oauth2_auth_token_for_testing(const std::string& token) {
auth_token_ = token;
// Sets the access_token as specified. This should be used only for testing.
void set_access_token_for_testing(const std::string& token) {
access_token_ = token;
}
private:
......@@ -95,7 +94,7 @@ class GDataAuthService : public content::NotificationObserver {
Profile* profile_;
std::string refresh_token_;
std::string auth_token_;
std::string access_token_;
ObserverList<Observer> observers_;
content::NotificationRegistrar registrar_;
......
......@@ -271,16 +271,16 @@ void DocumentsService::AuthorizeApp(const GURL& resource_url,
resource_url, app_ids));
}
bool DocumentsService::IsFullyAuthenticated() const {
bool DocumentsService::HasAccessToken() const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
return runner_->auth_service()->IsFullyAuthenticated();
return runner_->auth_service()->HasAccessToken();
}
bool DocumentsService::IsPartiallyAuthenticated() const {
bool DocumentsService::HasRefreshToken() const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
return runner_->auth_service()->IsPartiallyAuthenticated();
return runner_->auth_service()->HasRefreshToken();
}
} // namespace gdata
......@@ -185,11 +185,11 @@ class DocumentsServiceInterface {
const std::string& app_id,
const GetDataCallback& callback) = 0;
// True if OAuth2 auth token is retrieved and believed to be fresh.
virtual bool IsFullyAuthenticated() const = 0;
// True if OAuth2 access token is retrieved and believed to be fresh.
virtual bool HasAccessToken() const = 0;
// True if OAuth2 refresh token is present.
virtual bool IsPartiallyAuthenticated() const = 0;
virtual bool HasRefreshToken() const = 0;
};
// This class provides documents feed service calls.
......@@ -254,8 +254,8 @@ class DocumentsService : public DocumentsServiceInterface {
virtual void AuthorizeApp(const GURL& resource_url,
const std::string& app_id,
const GetDataCallback& callback) OVERRIDE;
virtual bool IsFullyAuthenticated() const OVERRIDE;
virtual bool IsPartiallyAuthenticated() const OVERRIDE;
virtual bool HasAccessToken() const OVERRIDE;
virtual bool HasRefreshToken() const OVERRIDE;
private:
Profile* profile_;
......
......@@ -30,7 +30,7 @@ class GDataTest : public InProcessBrowserTest {
ASSERT_TRUE(gdata_test_server_.Start());
service_.reset(new gdata::DocumentsService);
service_->Initialize(browser()->profile());
service_->auth_service_for_testing()->set_oauth2_auth_token_for_testing(
service_->auth_service_for_testing()->set_access_token_for_testing(
net::TestServer::kGDataAuthToken);
}
......
......@@ -57,7 +57,7 @@ void GDataOperationRunner::StartOperationWithRetry(
void GDataOperationRunner::StartOperation(GDataOperationInterface* operation) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!auth_service_->IsFullyAuthenticated()) {
if (!auth_service_->HasAccessToken()) {
// Fetch OAuth2 authentication token from the refresh token first.
auth_service_->StartAuthentication(
operation_registry_.get(),
......@@ -67,7 +67,7 @@ void GDataOperationRunner::StartOperation(GDataOperationInterface* operation) {
return;
}
operation->Start(auth_service_->oauth2_auth_token());
operation->Start(auth_service_->access_token());
}
void GDataOperationRunner::OnOperationAuthRefresh(
......@@ -77,7 +77,7 @@ void GDataOperationRunner::OnOperationAuthRefresh(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (code == HTTP_SUCCESS) {
DCHECK(auth_service_->IsPartiallyAuthenticated());
DCHECK(auth_service_->HasRefreshToken());
StartOperation(operation);
} else {
operation->OnAuthFailed(code);
......@@ -87,7 +87,7 @@ void GDataOperationRunner::OnOperationAuthRefresh(
void GDataOperationRunner::RetryOperation(GDataOperationInterface* operation) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
auth_service_->ClearOAuth2Token();
auth_service_->ClearAccessToken();
// User authentication might have expired - rerun the request to force
// auth token refresh.
StartOperation(operation);
......
......@@ -77,8 +77,8 @@ class MockDocumentsService : public DocumentsServiceInterface {
MOCK_METHOD3(AuthorizeApp, void(const GURL& resource_url,
const std::string& app_ids,
const GetDataCallback& callback));
MOCK_CONST_METHOD0(IsFullyAuthenticated, bool());
MOCK_CONST_METHOD0(IsPartiallyAuthenticated, bool());
MOCK_CONST_METHOD0(HasAccessToken, bool());
MOCK_CONST_METHOD0(HasRefreshToken, bool());
void set_account_metadata(base::Value* account_metadata) {
feed_data_.reset(account_metadata);
......
......@@ -56,13 +56,13 @@ AuthOperation::AuthOperation(GDataOperationRegistry* registry,
const AuthStatusCallback& callback,
const std::string& refresh_token)
: GDataOperationRegistry::Operation(registry),
profile_(profile), token_(refresh_token), callback_(callback) {
profile_(profile), refresh_token_(refresh_token), callback_(callback) {
}
AuthOperation::~AuthOperation() {}
void AuthOperation::Start() {
DCHECK(!token_.empty());
DCHECK(!refresh_token_.empty());
std::vector<std::string> scopes;
scopes.push_back(kDocsListScope);
scopes.push_back(kSpreadsheetsScope);
......@@ -73,7 +73,7 @@ void AuthOperation::Start() {
oauth2_access_token_fetcher_->Start(
GaiaUrls::GetInstance()->oauth2_chrome_client_id(),
GaiaUrls::GetInstance()->oauth2_chrome_client_secret(),
token_,
refresh_token_,
scopes);
}
......
......@@ -43,7 +43,7 @@ class AuthOperation : public GDataOperationRegistry::Operation,
private:
Profile* profile_;
std::string token_;
std::string refresh_token_;
AuthStatusCallback callback_;
scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_;
......
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