Chromium Code Reviews| Index: chrome/common/net/gaia/oauth2_token_mint_fetcher.h |
| =================================================================== |
| --- chrome/common/net/gaia/oauth2_token_mint_fetcher.h (revision 0) |
| +++ chrome/common/net/gaia/oauth2_token_mint_fetcher.h (revision 0) |
| @@ -0,0 +1,105 @@ |
| +// 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 CHROME_COMMON_NET_GAIA_OAUTH2_TOKEN_MINT_FETCHER_H_ |
| +#define CHROME_COMMON_NET_GAIA_OAUTH2_TOKEN_MINT_FETCHER_H_ |
| +#pragma once |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/gtest_prod_util.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "chrome/common/net/gaia/oauth2_token_mint_consumer.h" |
| +#include "content/public/common/url_fetcher.h" |
| +#include "content/public/common/url_fetcher_delegate.h" |
| +#include "googleurl/src/gurl.h" |
| + |
| +class OAuth2TokenMintFetcherTest; |
| + |
| +namespace net { |
| +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 OAuth2TokenMintFetcher : public content::URLFetcherDelegate { |
|
jstritar
2012/03/02 13:40:23
Could this be OAuth2TokenMint to use the noun form
|
| + public: |
| + OAuth2TokenMintFetcher(OAuth2TokenMintConsumer* consumer, |
| + net::URLRequestContextGetter* getter, |
| + const std::string& source); |
| + virtual ~OAuth2TokenMintFetcher(); |
| + |
| + // Start the flow. |
| + 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 content::URLFetcherDelegate |
| + virtual void OnURLFetchComplete(const content::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 content::URLFetcher* source); |
| + |
| + // Helper mehtods for reporting back results. |
| + void OnMintTokenSuccess(const std::string& access_token); |
| + void OnMintTokenFailure(GoogleServiceAuthError error); |
| + |
| + // Other helpers. |
| + static GURL MakeMintTokenUrl(); |
|
asargent_no_longer_on_chrome
2012/03/01 00:53:36
Given that this is called "MakeMintTokenUrl" and w
Munjal (Google)
2012/03/01 18:38:52
Done.
jstritar
2012/03/02 13:40:23
Yeah the names are a bit confusing. What do you th
|
| + 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 content::URLFetcher* source, |
| + std::string* access_token); |
| + |
| + // State that is set during construction. |
| + OAuth2TokenMintConsumer* const consumer_; |
| + net::URLRequestContextGetter* const getter_; |
| + std::string source_; |
| + State state_; |
| + |
| + // While a fetch is in progress. |
| + scoped_ptr<content::URLFetcher> fetcher_; |
| + std::string oauth_login_access_token_; |
| + std::string client_id_; |
| + std::vector<std::string> scopes_; |
| + std::string origin_; |
| + |
| + friend class OAuth2TokenMintFetcherTest; |
| + FRIEND_TEST_ALL_PREFIXES(OAuth2TokenMintFetcherTest, |
| + ParseMintTokenResponse); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(OAuth2TokenMintFetcher); |
| +}; |
| + |
| +#endif // CHROME_COMMON_NET_GAIA_OAUTH2_TOKEN_MINT_FETCHER_H_ |