Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef REMOTING_TEST_ACCESS_TOKEN_FETCHER_H_ | |
| 6 #define REMOTING_TEST_ACCESS_TOKEN_FETCHER_H_ | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "google_apis/gaia/gaia_oauth_client.h" | |
| 12 | |
| 13 namespace remoting { | |
| 14 namespace test { | |
| 15 | |
| 16 typedef base::Callback<void( | |
| 17 const std::string& access_token, | |
| 18 const std::string& refresh_token)> AccessTokenCallback; | |
| 19 | |
| 20 // Retrieves an access token from either an authorization code or a refresh | |
| 21 // token. A new callback is supplied by the client for each gaia network call | |
| 22 // which will return a valid token on success or an empty token on failure. | |
|
Wez
2015/02/19 22:00:23
I think you mean "for each request to GAIA".
Why
joedow
2015/02/20 02:58:35
Done.
| |
| 23 // Destroying the AccessTokenFetcher while a request is outstanding will cancel | |
| 24 // the request. It is safe to delete the fetcher from within a completion | |
| 25 // callback. Must be used from a thread running an IO message loop. | |
| 26 // The public methods are virtual to allow for mocking and fakes. | |
| 27 class AccessTokenFetcher : public gaia::GaiaOAuthClient::Delegate { | |
| 28 public: | |
| 29 AccessTokenFetcher(); | |
| 30 ~AccessTokenFetcher() override; | |
| 31 | |
| 32 // Retrieve an access token from a one time use authorization code. | |
| 33 virtual void GetAccessTokenFromAuthCode(const std::string& auth_code, | |
| 34 const AccessTokenCallback& callback); | |
| 35 | |
| 36 // Retrieve an access token from a refresh token. | |
| 37 virtual void GetAccessTokenFromRefreshToken( | |
| 38 const std::string& refresh_token, | |
| 39 const AccessTokenCallback& callback); | |
| 40 | |
| 41 private: | |
| 42 // gaia::GaiaOAuthClient::Delegate Interface. | |
| 43 void OnGetTokensResponse(const std::string& refresh_token, | |
| 44 const std::string& access_token, | |
| 45 int expires_in_seconds) override; | |
| 46 void OnRefreshTokenResponse(const std::string& access_token, | |
| 47 int expires_in_seconds) override; | |
| 48 void OnGetUserEmailResponse(const std::string& user_email) override; | |
| 49 void OnGetUserIdResponse(const std::string& user_id) override; | |
| 50 void OnGetUserInfoResponse( | |
| 51 scoped_ptr<base::DictionaryValue> user_info) override; | |
| 52 void OnGetTokenInfoResponse( | |
| 53 scoped_ptr<base::DictionaryValue> token_info) override; | |
| 54 void OnOAuthError() override; | |
| 55 void OnNetworkError(int response_code) override; | |
| 56 | |
| 57 // Updates |auth_client_| with a new GaiaOAuthClient instance. | |
| 58 void CreateNewGaiaOAuthClientInstance(); | |
| 59 | |
| 60 // Validates the retrieved access token. | |
| 61 void ValidateAccessToken(); | |
| 62 | |
| 63 // Caller-supplied callback used to return valid tokens on success or empty | |
| 64 // tokens on failure. | |
| 65 AccessTokenCallback access_token_callback_; | |
| 66 | |
| 67 // Retrieved based on the |refresh_token_|. | |
| 68 std::string access_token_; | |
| 69 | |
| 70 // Supplied by the caller or retrieved from a caller-supplied auth token. | |
| 71 std::string refresh_token_; | |
| 72 | |
| 73 // Holds the client id, secret, and redirect url used to make | |
| 74 // the Gaia service request. | |
| 75 gaia::OAuthClientInfo oauth_client_info_; | |
| 76 | |
| 77 // Used to make token requests to GAIA. Uses a request_context_getter | |
| 78 // to make those requests on the current thread's task runner. | |
|
Wez
2015/02/19 22:00:23
Do you need the second line? Is that property not
joedow
2015/02/20 02:58:35
I think that line was more pertinent in a previous
| |
| 79 scoped_ptr<gaia::GaiaOAuthClient> auth_client_; | |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(AccessTokenFetcher); | |
| 82 }; | |
| 83 | |
| 84 } // namespace test | |
| 85 } // namespace remoting | |
| 86 | |
| 87 #endif // REMOTING_TEST_ACCESS_TOKEN_FETCHER_H_ | |
| OLD | NEW |