diff options
author | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-21 22:54:40 +0000 |
---|---|---|
committer | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-21 22:54:40 +0000 |
commit | 68bb816549ce2ec21ad1a2c18b0b91a30efd7935 (patch) | |
tree | bb6f4dbf4ca7ddef5b0c819e417a5744db441776 /google_apis | |
parent | 3fafa72d03466b435a9fc19f328ef3a0980f2127 (diff) | |
download | chromium_src-68bb816549ce2ec21ad1a2c18b0b91a30efd7935.zip chromium_src-68bb816549ce2ec21ad1a2c18b0b91a30efd7935.tar.gz chromium_src-68bb816549ce2ec21ad1a2c18b0b91a30efd7935.tar.bz2 |
Remove unused code in google_apis/gaia
BUG=none
TBR=joi@chromium.org
Review URL: https://codereview.chromium.org/12755010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@189710 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis')
-rw-r--r-- | google_apis/gaia/gaia_constants.cc | 4 | ||||
-rw-r--r-- | google_apis/gaia/gaia_constants.h | 2 | ||||
-rw-r--r-- | google_apis/gaia/oauth2_api_call_flow.h | 2 | ||||
-rw-r--r-- | google_apis/gaia/oauth2_mint_token_consumer.h | 22 | ||||
-rw-r--r-- | google_apis/gaia/oauth2_mint_token_fetcher.cc | 195 | ||||
-rw-r--r-- | google_apis/gaia/oauth2_mint_token_fetcher.h | 104 | ||||
-rw-r--r-- | google_apis/gaia/oauth2_mint_token_fetcher_unittest.cc | 179 | ||||
-rw-r--r-- | google_apis/gaia/oauth2_mint_token_flow_unittest.cc | 1 | ||||
-rw-r--r-- | google_apis/gaia/oauth2_revocation_consumer.h | 22 | ||||
-rw-r--r-- | google_apis/gaia/oauth2_revocation_fetcher.cc | 170 | ||||
-rw-r--r-- | google_apis/gaia/oauth2_revocation_fetcher.h | 94 | ||||
-rw-r--r-- | google_apis/gaia/oauth2_revocation_fetcher_unittest.cc | 122 | ||||
-rw-r--r-- | google_apis/google_apis.gyp | 6 |
13 files changed, 0 insertions, 923 deletions
diff --git a/google_apis/gaia/gaia_constants.cc b/google_apis/gaia/gaia_constants.cc index b9193f8..0dd5236 100644 --- a/google_apis/gaia/gaia_constants.cc +++ b/google_apis/gaia/gaia_constants.cc @@ -29,10 +29,6 @@ const char kCloudPrintService[] = "cloudprint"; const char kDeviceManagementServiceOAuth[] = "https://www.googleapis.com/auth/chromeosdevicemanagement"; -// OAuth scopes for chrome web store. -const char kCWSNotificationScope[] = - "https://www.googleapis.com/auth/chromewebstore.notification"; - // Service for LSO endpoint of Google that exposes OAuth APIs. const char kLSOService[] = "lso"; diff --git a/google_apis/gaia/gaia_constants.h b/google_apis/gaia/gaia_constants.h index b68b788..625ab5b 100644 --- a/google_apis/gaia/gaia_constants.h +++ b/google_apis/gaia/gaia_constants.h @@ -20,8 +20,6 @@ extern const char kSyncService[]; extern const char kRemotingService[]; extern const char kCloudPrintService[]; extern const char kDeviceManagementServiceOAuth[]; -extern const char kCWSService[]; -extern const char kCWSNotificationScope[]; extern const char kLSOService[]; // Used with uber auth tokens when needed. diff --git a/google_apis/gaia/oauth2_api_call_flow.h b/google_apis/gaia/oauth2_api_call_flow.h index 419c842..fccd1e7 100644 --- a/google_apis/gaia/oauth2_api_call_flow.h +++ b/google_apis/gaia/oauth2_api_call_flow.h @@ -10,8 +10,6 @@ #include "base/memory/scoped_ptr.h" #include "google_apis/gaia/oauth2_access_token_consumer.h" #include "google_apis/gaia/oauth2_access_token_fetcher.h" -#include "google_apis/gaia/oauth2_mint_token_consumer.h" -#include "google_apis/gaia/oauth2_mint_token_fetcher.h" #include "net/url_request/url_fetcher_delegate.h" class GoogleServiceAuthError; diff --git a/google_apis/gaia/oauth2_mint_token_consumer.h b/google_apis/gaia/oauth2_mint_token_consumer.h deleted file mode 100644 index 95ea12e..0000000 --- a/google_apis/gaia/oauth2_mint_token_consumer.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2012 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 GOOGLE_APIS_GAIA_OAUTH2_MINT_TOKEN_CONSUMER_H_ -#define GOOGLE_APIS_GAIA_OAUTH2_MINT_TOKEN_CONSUMER_H_ - -#include <string> - -class GoogleServiceAuthError; - -// An interface that defines the callbacks for consumers to which -// OAuth2MintTokenFetcher can return results. -class OAuth2MintTokenConsumer { - public: - virtual ~OAuth2MintTokenConsumer() {} - - virtual void OnMintTokenSuccess(const std::string& access_token) {} - virtual void OnMintTokenFailure(const GoogleServiceAuthError& error) {} -}; - -#endif // GOOGLE_APIS_GAIA_OAUTH2_MINT_TOKEN_CONSUMER_H_ diff --git a/google_apis/gaia/oauth2_mint_token_fetcher.cc b/google_apis/gaia/oauth2_mint_token_fetcher.cc deleted file mode 100644 index c5dfc05..0000000 --- a/google_apis/gaia/oauth2_mint_token_fetcher.cc +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright (c) 2012 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 "google_apis/gaia/oauth2_mint_token_fetcher.h" - -#include <algorithm> -#include <string> - -#include "base/json/json_reader.h" -#include "base/string_util.h" -#include "base/stringprintf.h" -#include "base/values.h" -#include "google_apis/gaia/gaia_urls.h" -#include "google_apis/gaia/google_service_auth_error.h" -#include "net/base/escape.h" -#include "net/base/load_flags.h" -#include "net/http/http_status_code.h" -#include "net/url_request/url_fetcher.h" -#include "net/url_request/url_request_context_getter.h" -#include "net/url_request/url_request_status.h" - -using net::URLFetcher; -using net::URLFetcherDelegate; -using net::ResponseCookies; -using net::URLRequestContextGetter; -using net::URLRequestStatus; - -namespace { -static const char kAuthorizationHeaderFormat[] = - "Authorization: Bearer %s"; -static const char kOAuth2IssueTokenBodyFormat[] = - "force=true" - "&response_type=token" - "&scope=%s" - "&client_id=%s" - "&origin=%s"; -static const char kAccessTokenKey[] = "token"; - -static GoogleServiceAuthError CreateAuthError(URLRequestStatus status) { - CHECK(!status.is_success()); - if (status.status() == URLRequestStatus::CANCELED) { - return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); - } else { - DLOG(WARNING) << "Could not reach Google Accounts servers: errno " - << status.error(); - return GoogleServiceAuthError::FromConnectionError(status.error()); - } -} - -static URLFetcher* CreateFetcher(URLRequestContextGetter* getter, - const GURL& url, - const std::string& headers, - const std::string& body, - URLFetcherDelegate* delegate) { - bool empty_body = body.empty(); - URLFetcher* result = net::URLFetcher::Create( - 0, url, - empty_body ? URLFetcher::GET : URLFetcher::POST, - delegate); - - result->SetRequestContext(getter); - result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | - net::LOAD_DO_NOT_SAVE_COOKIES); - // Fetchers are sometimes cancelled because a network change was detected, - // especially at startup and after sign-in on ChromeOS. Retrying once should - // be enough in those cases; let the fetcher retry up to 3 times just in case. - // http://crbug.com/163710 - result->SetAutomaticallyRetryOnNetworkChanges(3); - - if (!empty_body) - result->SetUploadData("application/x-www-form-urlencoded", body); - if (!headers.empty()) - result->SetExtraRequestHeaders(headers); - - return result; -} -} // namespace - -OAuth2MintTokenFetcher::OAuth2MintTokenFetcher( - OAuth2MintTokenConsumer* consumer, - URLRequestContextGetter* getter, - const std::string& source) - : consumer_(consumer), - getter_(getter), - source_(source), - state_(INITIAL) { } - -OAuth2MintTokenFetcher::~OAuth2MintTokenFetcher() { } - -void OAuth2MintTokenFetcher::CancelRequest() { - fetcher_.reset(); -} - -void OAuth2MintTokenFetcher::Start(const std::string& oauth_login_access_token, - const std::string& client_id, - const std::vector<std::string>& scopes, - const std::string& origin) { - oauth_login_access_token_ = oauth_login_access_token; - client_id_ = client_id; - scopes_ = scopes; - origin_ = origin; - StartMintToken(); -} - -void OAuth2MintTokenFetcher::StartMintToken() { - CHECK_EQ(INITIAL, state_); - state_ = MINT_TOKEN_STARTED; - fetcher_.reset(CreateFetcher( - getter_, - MakeMintTokenUrl(), - MakeMintTokenHeader(oauth_login_access_token_), - MakeMintTokenBody(client_id_, scopes_, origin_), - this)); - fetcher_->Start(); // OnURLFetchComplete will be called. -} - -void OAuth2MintTokenFetcher::EndMintToken(const net::URLFetcher* source) { - CHECK_EQ(MINT_TOKEN_STARTED, state_); - state_ = MINT_TOKEN_DONE; - - URLRequestStatus status = source->GetStatus(); - if (!status.is_success()) { - OnMintTokenFailure(CreateAuthError(status)); - return; - } - - if (source->GetResponseCode() != net::HTTP_OK) { - OnMintTokenFailure(GoogleServiceAuthError( - GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); - return; - } - - // The request was successfully fetched and it returned OK. - // Parse out the access token. - std::string access_token; - ParseMintTokenResponse(source, &access_token); - OnMintTokenSuccess(access_token); -} - -void OAuth2MintTokenFetcher::OnMintTokenSuccess( - const std::string& access_token) { - consumer_->OnMintTokenSuccess(access_token); -} - -void OAuth2MintTokenFetcher::OnMintTokenFailure( - const GoogleServiceAuthError& error) { - state_ = ERROR_STATE; - consumer_->OnMintTokenFailure(error); -} - -void OAuth2MintTokenFetcher::OnURLFetchComplete(const net::URLFetcher* source) { - CHECK(source); - CHECK_EQ(MINT_TOKEN_STARTED, state_); - EndMintToken(source); -} - -// static -GURL OAuth2MintTokenFetcher::MakeMintTokenUrl() { - return GURL(GaiaUrls::GetInstance()->oauth2_issue_token_url()); -} - -// static -std::string OAuth2MintTokenFetcher::MakeMintTokenHeader( - const std::string& access_token) { - return base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str()); -} - -// static -std::string OAuth2MintTokenFetcher::MakeMintTokenBody( - const std::string& client_id, - const std::vector<std::string>& scopes, - const std::string& origin) { - return base::StringPrintf( - kOAuth2IssueTokenBodyFormat, - net::EscapeUrlEncodedData(JoinString(scopes, ','), true).c_str(), - net::EscapeUrlEncodedData(client_id, true).c_str(), - net::EscapeUrlEncodedData(origin, true).c_str()); -} - -// static -bool OAuth2MintTokenFetcher::ParseMintTokenResponse( - const net::URLFetcher* source, - std::string* access_token) { - CHECK(source); - CHECK(access_token); - std::string data; - source->GetResponseAsString(&data); - scoped_ptr<base::Value> value(base::JSONReader::Read(data)); - if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) - return false; - - DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); - return dict->GetString(kAccessTokenKey, access_token); -} diff --git a/google_apis/gaia/oauth2_mint_token_fetcher.h b/google_apis/gaia/oauth2_mint_token_fetcher.h deleted file mode 100644 index 4995c7a..0000000 --- a/google_apis/gaia/oauth2_mint_token_fetcher.h +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (c) 2012 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 GOOGLE_APIS_GAIA_OAUTH2_MINT_TOKEN_FETCHER_H_ -#define GOOGLE_APIS_GAIA_OAUTH2_MINT_TOKEN_FETCHER_H_ - -#include <string> -#include <vector> - -#include "base/gtest_prod_util.h" -#include "base/memory/scoped_ptr.h" -#include "google_apis/gaia/oauth2_mint_token_consumer.h" -#include "googleurl/src/gurl.h" -#include "net/url_request/url_fetcher_delegate.h" - -class OAuth2MintTokenFetcherTest; - -namespace net { -class URLFetcher; -class URLRequestContextGetter; -class URLRequestStatus; -} - -// Abstracts the details to mint new OAuth2 tokens from OAuth2 login scoped -// token. -// -// This class should be used on a single thread, but it can be whichever thread -// that you like. -// Also, do not reuse the same instance. Once Start() is called, the instance -// should not be reused. -// -// Usage: -// * Create an instance with a consumer. -// * Call Start() -// * The consumer passed in the constructor will be called on the same -// thread Start was called with the results. -// -// This class can handle one request at a time. To parallelize requests, -// create multiple instances. -class OAuth2MintTokenFetcher : public net::URLFetcherDelegate { - public: - OAuth2MintTokenFetcher(OAuth2MintTokenConsumer* consumer, - net::URLRequestContextGetter* getter, - const std::string& source); - virtual ~OAuth2MintTokenFetcher(); - - // Start the flow. - virtual void Start(const std::string& oauth_login_access_token, - const std::string& client_id, - const std::vector<std::string>& scopes, - const std::string& origin); - - void CancelRequest(); - - // Implementation of net::URLFetcherDelegate - virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; - - private: - enum State { - INITIAL, - MINT_TOKEN_STARTED, - MINT_TOKEN_DONE, - ERROR_STATE, - }; - - // Helper methods for the flow. - void StartMintToken(); - void EndMintToken(const net::URLFetcher* source); - - // Helper methods for reporting back results. - void OnMintTokenSuccess(const std::string& access_token); - void OnMintTokenFailure(const GoogleServiceAuthError& error); - - // Other helpers. - static GURL MakeMintTokenUrl(); - static std::string MakeMintTokenHeader(const std::string& access_token); - static std::string MakeMintTokenBody(const std::string& client_id, - const std::vector<std::string>& scopes, - const std::string& origin); - static bool ParseMintTokenResponse(const net::URLFetcher* source, - std::string* access_token); - - // State that is set during construction. - OAuth2MintTokenConsumer* const consumer_; - net::URLRequestContextGetter* const getter_; - std::string source_; - State state_; - - // While a fetch is in progress. - scoped_ptr<net::URLFetcher> fetcher_; - std::string oauth_login_access_token_; - std::string client_id_; - std::vector<std::string> scopes_; - std::string origin_; - - friend class OAuth2MintTokenFetcherTest; - FRIEND_TEST_ALL_PREFIXES(OAuth2MintTokenFetcherTest, - ParseMintTokenResponse); - - DISALLOW_COPY_AND_ASSIGN(OAuth2MintTokenFetcher); -}; - -#endif // GOOGLE_APIS_GAIA_OAUTH2_MINT_TOKEN_FETCHER_H_ diff --git a/google_apis/gaia/oauth2_mint_token_fetcher_unittest.cc b/google_apis/gaia/oauth2_mint_token_fetcher_unittest.cc deleted file mode 100644 index fda775b..0000000 --- a/google_apis/gaia/oauth2_mint_token_fetcher_unittest.cc +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright (c) 2012 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. -// -// A complete set of unit tests for OAuth2MintTokenFetcher. - -#include <string> -#include <vector> - -#include "base/memory/scoped_ptr.h" -#include "base/message_loop.h" -#include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread.h" -#include "google_apis/gaia/gaia_urls.h" -#include "google_apis/gaia/google_service_auth_error.h" -#include "google_apis/gaia/oauth2_mint_token_consumer.h" -#include "google_apis/gaia/oauth2_mint_token_fetcher.h" -#include "googleurl/src/gurl.h" -#include "net/http/http_status_code.h" -#include "net/url_request/test_url_fetcher_factory.h" -#include "net/url_request/url_fetcher.h" -#include "net/url_request/url_fetcher_delegate.h" -#include "net/url_request/url_fetcher_factory.h" -#include "net/url_request/url_request.h" -#include "net/url_request/url_request_status.h" -#include "testing/gmock/include/gmock/gmock.h" -#include "testing/gtest/include/gtest/gtest.h" - -using content::BrowserThread; -using net::ResponseCookies; -using net::ScopedURLFetcherFactory; -using net::TestURLFetcher; -using net::URLFetcher; -using net::URLFetcherDelegate; -using net::URLFetcherFactory; -using net::URLRequestStatus; -using testing::_; -using testing::Return; - -namespace { - -static const char kValidTokenResponse[] = - "{" - " \"token\": \"at1\"," - " \"issueAdvice\": \"Auto\"" - "}"; -static const char kTokenResponseNoAccessToken[] = - "{" - " \"issueAdvice\": \"Auto\"" - "}"; - -class MockUrlFetcherFactory : public ScopedURLFetcherFactory, - public URLFetcherFactory { -public: - MockUrlFetcherFactory() - : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { - } - virtual ~MockUrlFetcherFactory() {} - - MOCK_METHOD4( - CreateURLFetcher, - URLFetcher* (int id, - const GURL& url, - URLFetcher::RequestType request_type, - URLFetcherDelegate* d)); -}; - -class MockOAuth2MintTokenConsumer : public OAuth2MintTokenConsumer { - public: - MockOAuth2MintTokenConsumer() {} - ~MockOAuth2MintTokenConsumer() {} - - MOCK_METHOD1(OnMintTokenSuccess, void(const std::string& access_token)); - MOCK_METHOD1(OnMintTokenFailure, - void(const GoogleServiceAuthError& error)); -}; - -} // namespace - -class OAuth2MintTokenFetcherTest : public testing::Test { - public: - OAuth2MintTokenFetcherTest() - : ui_thread_(BrowserThread::UI, &message_loop_), - fetcher_(&consumer_, profile_.GetRequestContext(), "test") { - test_scopes_.push_back("scope1"); - test_scopes_.push_back("scope1"); - } - - virtual ~OAuth2MintTokenFetcherTest() { } - - virtual TestURLFetcher* SetupIssueToken( - bool fetch_succeeds, int response_code, const std::string& body) { - GURL url(GaiaUrls::GetInstance()->oauth2_issue_token_url()); - TestURLFetcher* url_fetcher = new TestURLFetcher(0, url, &fetcher_); - URLRequestStatus::Status status = - fetch_succeeds ? URLRequestStatus::SUCCESS : URLRequestStatus::FAILED; - url_fetcher->set_status(URLRequestStatus(status, 0)); - - if (response_code != 0) - url_fetcher->set_response_code(response_code); - - if (!body.empty()) - url_fetcher->SetResponseString(body); - - EXPECT_CALL(factory_, CreateURLFetcher(_, url, _, _)) - .WillOnce(Return(url_fetcher)); - return url_fetcher; - } - - protected: - MessageLoop message_loop_; - content::TestBrowserThread ui_thread_; - MockUrlFetcherFactory factory_; - MockOAuth2MintTokenConsumer consumer_; - TestingProfile profile_; - OAuth2MintTokenFetcher fetcher_; - std::vector<std::string> test_scopes_; -}; - -TEST_F(OAuth2MintTokenFetcherTest, GetAccessTokenRequestFailure) { - TestURLFetcher* url_fetcher = SetupIssueToken(false, 0, ""); - EXPECT_CALL(consumer_, OnMintTokenFailure(_)).Times(1); - fetcher_.Start("access_token1", "client1", test_scopes_, "extension1"); - fetcher_.OnURLFetchComplete(url_fetcher); -} - -TEST_F(OAuth2MintTokenFetcherTest, GetAccessTokenResponseCodeFailure) { - TestURLFetcher* url_fetcher = SetupIssueToken( - false, net::HTTP_FORBIDDEN, ""); - EXPECT_CALL(consumer_, OnMintTokenFailure(_)).Times(1); - fetcher_.Start("access_token1", "client1", test_scopes_, "extension1"); - fetcher_.OnURLFetchComplete(url_fetcher); -} - -TEST_F(OAuth2MintTokenFetcherTest, Success) { - TestURLFetcher* url_fetcher = SetupIssueToken( - true, net::HTTP_OK, kValidTokenResponse); - EXPECT_CALL(consumer_, OnMintTokenSuccess("at1")).Times(1); - fetcher_.Start("access_token1", "client1", test_scopes_, "extension1"); - fetcher_.OnURLFetchComplete(url_fetcher); -} - -TEST_F(OAuth2MintTokenFetcherTest, ParseMintTokenResponse) { - { // No body. - TestURLFetcher url_fetcher(0, GURL("www.google.com"), NULL); - - std::string at; - EXPECT_FALSE(OAuth2MintTokenFetcher::ParseMintTokenResponse( - &url_fetcher, &at)); - EXPECT_TRUE(at.empty()); - } - { // Bad json. - TestURLFetcher url_fetcher(0, GURL("www.google.com"), NULL); - url_fetcher.SetResponseString("foo"); - - std::string at; - EXPECT_FALSE(OAuth2MintTokenFetcher::ParseMintTokenResponse( - &url_fetcher, &at)); - EXPECT_TRUE(at.empty()); - } - { // Valid json: access token missing. - TestURLFetcher url_fetcher(0, GURL("www.google.com"), NULL); - url_fetcher.SetResponseString(kTokenResponseNoAccessToken); - - std::string at; - EXPECT_FALSE(OAuth2MintTokenFetcher::ParseMintTokenResponse( - &url_fetcher, &at)); - EXPECT_TRUE(at.empty()); - } - { // Valid json: all good. - TestURLFetcher url_fetcher(0, GURL("www.google.com"), NULL); - url_fetcher.SetResponseString(kValidTokenResponse); - - std::string at; - EXPECT_TRUE(OAuth2MintTokenFetcher::ParseMintTokenResponse( - &url_fetcher, &at)); - EXPECT_EQ("at1", at); - } -} diff --git a/google_apis/gaia/oauth2_mint_token_flow_unittest.cc b/google_apis/gaia/oauth2_mint_token_flow_unittest.cc index 4b24e939..e213984 100644 --- a/google_apis/gaia/oauth2_mint_token_flow_unittest.cc +++ b/google_apis/gaia/oauth2_mint_token_flow_unittest.cc @@ -141,7 +141,6 @@ class MockMintTokenFlow : public OAuth2MintTokenFlow { ~MockMintTokenFlow() {} MOCK_METHOD0(CreateAccessTokenFetcher, OAuth2AccessTokenFetcher*()); - MOCK_METHOD0(CreateMintTokenFetcher, OAuth2MintTokenFetcher*()); }; } // namespace diff --git a/google_apis/gaia/oauth2_revocation_consumer.h b/google_apis/gaia/oauth2_revocation_consumer.h deleted file mode 100644 index 2004fec..0000000 --- a/google_apis/gaia/oauth2_revocation_consumer.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2011 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 GOOGLE_APIS_GAIA_OAUTH2_REVOCATION_CONSUMER_H_ -#define GOOGLE_APIS_GAIA_OAUTH2_REVOCATION_CONSUMER_H_ - -#include <string> - -class GoogleServiceAuthError; - -// An interface that defines the callbacks for consumers to which -// OAuth2RevocationFetcher can return results. -class OAuth2RevocationConsumer { - public: - virtual ~OAuth2RevocationConsumer() {} - - virtual void OnRevocationSuccess() {} - virtual void OnRevocationFailure(const GoogleServiceAuthError& error) {} -}; - -#endif // GOOGLE_APIS_GAIA_OAUTH2_REVOCATION_CONSUMER_H_ diff --git a/google_apis/gaia/oauth2_revocation_fetcher.cc b/google_apis/gaia/oauth2_revocation_fetcher.cc deleted file mode 100644 index eeec213..0000000 --- a/google_apis/gaia/oauth2_revocation_fetcher.cc +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright (c) 2012 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 "google_apis/gaia/oauth2_revocation_fetcher.h" - -#include <algorithm> -#include <string> -#include <vector> - -#include "base/json/json_reader.h" -#include "base/string_util.h" -#include "base/stringprintf.h" -#include "base/values.h" -#include "google_apis/gaia/gaia_urls.h" -#include "google_apis/gaia/google_service_auth_error.h" -#include "net/base/escape.h" -#include "net/base/load_flags.h" -#include "net/http/http_status_code.h" -#include "net/url_request/url_fetcher.h" -#include "net/url_request/url_request_context_getter.h" -#include "net/url_request/url_request_status.h" - -using net::ResponseCookies; -using net::URLFetcher; -using net::URLFetcherDelegate; -using net::URLRequestContextGetter; -using net::URLRequestStatus; - -namespace { -static const char kOAuth2RevokeTokenURL[] = - "https://www.googleapis.com/oauth2/v2/RevokeToken"; - -static const char kAuthorizationHeaderFormat[] = - "Authorization: Bearer %s"; - -static const char kRevocationBodyFormat[] = - "client_id=%s&origin=%s"; - -static GoogleServiceAuthError CreateAuthError(URLRequestStatus status) { - CHECK(!status.is_success()); - if (status.status() == URLRequestStatus::CANCELED) { - return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); - } else { - DLOG(WARNING) << "Could not reach Google Accounts servers: errno " - << status.error(); - return GoogleServiceAuthError::FromConnectionError(status.error()); - } -} - -static URLFetcher* CreateFetcher(URLRequestContextGetter* getter, - const GURL& url, - const std::string& header, - const std::string& body, - URLFetcherDelegate* delegate) { - bool empty_body = body.empty(); - URLFetcher* result = net::URLFetcher::Create( - 0, url, - empty_body ? URLFetcher::GET : URLFetcher::POST, - delegate); - - result->SetRequestContext(getter); - result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | - net::LOAD_DO_NOT_SAVE_COOKIES); - // Fetchers are sometimes cancelled because a network change was detected, - // especially at startup and after sign-in on ChromeOS. Retrying once should - // be enough in those cases; let the fetcher retry up to 3 times just in case. - // http://crbug.com/163710 - result->SetAutomaticallyRetryOnNetworkChanges(3); - if (!header.empty()) - result->SetExtraRequestHeaders(header); - - if (!empty_body) - result->SetUploadData("application/x-www-form-urlencoded", body); - - return result; -} -} // namespace - -OAuth2RevocationFetcher::OAuth2RevocationFetcher( - OAuth2RevocationConsumer* consumer, - URLRequestContextGetter* getter) - : consumer_(consumer), - getter_(getter), - state_(INITIAL) { } - -OAuth2RevocationFetcher::~OAuth2RevocationFetcher() { } - -void OAuth2RevocationFetcher::CancelRequest() { - fetcher_.reset(); -} - -void OAuth2RevocationFetcher::Start(const std::string& access_token, - const std::string& client_id, - const std::string& origin) { - access_token_ = access_token; - client_id_ = client_id; - origin_ = origin; - StartRevocation(); -} - -void OAuth2RevocationFetcher::StartRevocation() { - CHECK_EQ(INITIAL, state_); - state_ = REVOCATION_STARTED; - fetcher_.reset(CreateFetcher( - getter_, - MakeRevocationUrl(), - MakeRevocationHeader(access_token_), - MakeRevocationBody(client_id_, origin_), - this)); - fetcher_->Start(); // OnURLFetchComplete will be called. -} - -void OAuth2RevocationFetcher::EndRevocation(const net::URLFetcher* source) { - CHECK_EQ(REVOCATION_STARTED, state_); - state_ = REVOCATION_DONE; - - URLRequestStatus status = source->GetStatus(); - if (!status.is_success()) { - OnRevocationFailure(CreateAuthError(status)); - return; - } - - if (source->GetResponseCode() != net::HTTP_NO_CONTENT) { - OnRevocationFailure(GoogleServiceAuthError( - GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); - return; - } - - OnRevocationSuccess(); -} - -void OAuth2RevocationFetcher::OnRevocationSuccess() { - consumer_->OnRevocationSuccess(); -} - -void OAuth2RevocationFetcher::OnRevocationFailure( - const GoogleServiceAuthError& error) { - state_ = ERROR_STATE; - consumer_->OnRevocationFailure(error); -} - -void OAuth2RevocationFetcher::OnURLFetchComplete( - const net::URLFetcher* source) { - CHECK(source); - EndRevocation(source); -} - -// static -GURL OAuth2RevocationFetcher::MakeRevocationUrl() { - return GURL(kOAuth2RevokeTokenURL); -} - -// static -std::string OAuth2RevocationFetcher::MakeRevocationHeader( - const std::string& access_token) { - return base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str()); -} - -// static -std::string OAuth2RevocationFetcher::MakeRevocationBody( - const std::string& client_id, - const std::string& origin) { - std::string enc_client_id = net::EscapeUrlEncodedData(client_id, true); - std::string enc_origin = net::EscapeUrlEncodedData(origin, true); - return base::StringPrintf( - kRevocationBodyFormat, - enc_client_id.c_str(), - enc_origin.c_str()); -} diff --git a/google_apis/gaia/oauth2_revocation_fetcher.h b/google_apis/gaia/oauth2_revocation_fetcher.h deleted file mode 100644 index a87ee78..0000000 --- a/google_apis/gaia/oauth2_revocation_fetcher.h +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) 2012 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 GOOGLE_APIS_GAIA_OAUTH2_REVOCATION_FETCHER_H_ -#define GOOGLE_APIS_GAIA_OAUTH2_REVOCATION_FETCHER_H_ - -#include <string> - -#include "base/gtest_prod_util.h" -#include "base/memory/scoped_ptr.h" -#include "google_apis/gaia/oauth2_revocation_consumer.h" -#include "googleurl/src/gurl.h" -#include "net/url_request/url_fetcher_delegate.h" - -class OAuth2RevocationFetcherTest; - -namespace net { -class URLFetcher; -class URLRequestContextGetter; -class URLRequestStatus; -} - -// Abstracts the details to perform OAuth2 grant revocation. -// -// This class should be used on a single thread, but it can be whichever thread -// that you like. -// Also, do not reuse the same instance. Once Start() is called, the instance -// should not be reused. -// -// Usage: -// * Create an instance with a consumer. -// * Call Start() -// * The consumer passed in the constructor will be called on the same -// thread Start was called with the results. -// -// This class can handle one request at a time. To parallelize requests, -// create multiple instances. -class OAuth2RevocationFetcher : public net::URLFetcherDelegate { - public: - OAuth2RevocationFetcher(OAuth2RevocationConsumer* consumer, - net::URLRequestContextGetter* getter); - virtual ~OAuth2RevocationFetcher(); - - // Starts the flow with the given parameters. - // |access_token| should be an OAuth2 login scoped access token. - void Start(const std::string& access_token, - const std::string& client_id, - const std::string& origin); - - void CancelRequest(); - - // Implementation of net::URLFetcherDelegate - virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; - - private: - enum State { - INITIAL, - REVOCATION_STARTED, - REVOCATION_DONE, - ERROR_STATE, - }; - - // Helper methods for the flow. - void StartRevocation(); - void EndRevocation(const net::URLFetcher* source); - - // Helper mehtods for reporting back results. - void OnRevocationSuccess(); - void OnRevocationFailure(const GoogleServiceAuthError& error); - - // Other helpers. - static GURL MakeRevocationUrl(); - static std::string MakeRevocationHeader(const std::string& access_token); - static std::string MakeRevocationBody(const std::string& client_id, - const std::string& origin); - - // State that is set during construction. - OAuth2RevocationConsumer* const consumer_; - net::URLRequestContextGetter* const getter_; - State state_; - - // While a fetch is in progress. - scoped_ptr<net::URLFetcher> fetcher_; - std::string access_token_; - std::string client_id_; - std::string origin_; - - friend class OAuth2RevocationFetcherTest; - - DISALLOW_COPY_AND_ASSIGN(OAuth2RevocationFetcher); -}; - -#endif // GOOGLE_APIS_GAIA_OAUTH2_REVOCATION_FETCHER_H_ diff --git a/google_apis/gaia/oauth2_revocation_fetcher_unittest.cc b/google_apis/gaia/oauth2_revocation_fetcher_unittest.cc deleted file mode 100644 index 17f53ad..0000000 --- a/google_apis/gaia/oauth2_revocation_fetcher_unittest.cc +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright (c) 2012 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. -// -// A complete set of unit tests for OAuth2RevocationFetcher. - -#include <string> - -#include "base/memory/scoped_ptr.h" -#include "base/message_loop.h" -#include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread.h" -#include "google_apis/gaia/gaia_urls.h" -#include "google_apis/gaia/google_service_auth_error.h" -#include "google_apis/gaia/oauth2_revocation_consumer.h" -#include "google_apis/gaia/oauth2_revocation_fetcher.h" -#include "googleurl/src/gurl.h" -#include "net/http/http_status_code.h" -#include "net/url_request/test_url_fetcher_factory.h" -#include "net/url_request/url_fetcher.h" -#include "net/url_request/url_fetcher_delegate.h" -#include "net/url_request/url_fetcher_factory.h" -#include "net/url_request/url_request.h" -#include "net/url_request/url_request_status.h" -#include "testing/gmock/include/gmock/gmock.h" -#include "testing/gtest/include/gtest/gtest.h" - -using content::BrowserThread; -using net::ResponseCookies; -using net::ScopedURLFetcherFactory; -using net::TestURLFetcher; -using net::URLFetcher; -using net::URLFetcherDelegate; -using net::URLFetcherFactory; -using net::URLRequestStatus; -using testing::_; -using testing::Return; - -namespace { - -class MockUrlFetcherFactory : public ScopedURLFetcherFactory, - public URLFetcherFactory { -public: - MockUrlFetcherFactory() - : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { - } - virtual ~MockUrlFetcherFactory() {} - - MOCK_METHOD4( - CreateURLFetcher, - URLFetcher* (int id, - const GURL& url, - URLFetcher::RequestType request_type, - URLFetcherDelegate* d)); -}; - -class MockOAuth2RevocationConsumer : public OAuth2RevocationConsumer { - public: - MockOAuth2RevocationConsumer() {} - ~MockOAuth2RevocationConsumer() {} - - MOCK_METHOD0(OnRevocationSuccess, void()); - MOCK_METHOD1(OnRevocationFailure, - void(const GoogleServiceAuthError& error)); -}; - -} // namespace - -class OAuth2RevocationFetcherTest : public testing::Test { - public: - OAuth2RevocationFetcherTest() - : ui_thread_(BrowserThread::UI, &message_loop_), - fetcher_(&consumer_, profile_.GetRequestContext()) { - } - - virtual ~OAuth2RevocationFetcherTest() { } - - virtual TestURLFetcher* SetupRevocation( - bool fetch_succeeds, int response_code) { - GURL url = OAuth2RevocationFetcher::MakeRevocationUrl(); - TestURLFetcher* url_fetcher = new TestURLFetcher(0, url, &fetcher_); - URLRequestStatus::Status status = - fetch_succeeds ? URLRequestStatus::SUCCESS : URLRequestStatus::FAILED; - url_fetcher->set_status(URLRequestStatus(status, 0)); - - if (response_code != 0) - url_fetcher->set_response_code(response_code); - - EXPECT_CALL(factory_, CreateURLFetcher(_, url, _, _)) - .WillOnce(Return(url_fetcher)); - return url_fetcher; - } - - protected: - MessageLoop message_loop_; - content::TestBrowserThread ui_thread_; - MockUrlFetcherFactory factory_; - MockOAuth2RevocationConsumer consumer_; - TestingProfile profile_; - OAuth2RevocationFetcher fetcher_; -}; - -TEST_F(OAuth2RevocationFetcherTest, RequestFailure) { - TestURLFetcher* url_fetcher = SetupRevocation(false, 0); - EXPECT_CALL(consumer_, OnRevocationFailure(_)).Times(1); - fetcher_.Start("access_token", "client_id", "origin"); - fetcher_.OnURLFetchComplete(url_fetcher); -} - -TEST_F(OAuth2RevocationFetcherTest, ResponseCodeFailure) { - TestURLFetcher* url_fetcher = SetupRevocation(true, net::HTTP_FORBIDDEN); - EXPECT_CALL(consumer_, OnRevocationFailure(_)).Times(1); - fetcher_.Start("access_token", "client_id", "origin"); - fetcher_.OnURLFetchComplete(url_fetcher); -} - -TEST_F(OAuth2RevocationFetcherTest, Success) { - TestURLFetcher* url_fetcher = SetupRevocation(true, net::HTTP_NO_CONTENT); - EXPECT_CALL(consumer_, OnRevocationSuccess()).Times(1); - fetcher_.Start("access_token", "client_id", "origin"); - fetcher_.OnURLFetchComplete(url_fetcher); -} diff --git a/google_apis/google_apis.gyp b/google_apis/google_apis.gyp index c1f44e7..dd346a8 100644 --- a/google_apis/google_apis.gyp +++ b/google_apis/google_apis.gyp @@ -75,14 +75,8 @@ 'gaia/oauth2_access_token_fetcher.h', 'gaia/oauth2_api_call_flow.cc', 'gaia/oauth2_api_call_flow.h', - 'gaia/oauth2_mint_token_consumer.h', - 'gaia/oauth2_mint_token_fetcher.cc', - 'gaia/oauth2_mint_token_fetcher.h', 'gaia/oauth2_mint_token_flow.cc', 'gaia/oauth2_mint_token_flow.h', - 'gaia/oauth2_revocation_consumer.h', - 'gaia/oauth2_revocation_fetcher.cc', - 'gaia/oauth2_revocation_fetcher.h', 'google_api_keys.cc', 'google_api_keys.h', ], |