cc: Remove implicit conversions from Rect to RectF in src/cc/.
[chromium-blink-merge.git] / remoting / test / access_token_fetcher.h
blob50062f7ee6f8cdcf246ae7258e44b0ce8dc55320
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.
5 #ifndef REMOTING_TEST_ACCESS_TOKEN_FETCHER_H_
6 #define REMOTING_TEST_ACCESS_TOKEN_FETCHER_H_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "google_apis/gaia/gaia_oauth_client.h"
15 namespace remoting {
16 namespace test {
18 // Supplied by the client for each request to GAIA and returns valid tokens on
19 // success or empty tokens on failure.
20 typedef base::Callback<void(const std::string& access_token,
21 const std::string& refresh_token)>
22 AccessTokenCallback;
24 // Retrieves an access token from either an authorization code or a refresh
25 // token. Destroying the AccessTokenFetcher while a request is outstanding will
26 // cancel the request. It is safe to delete the fetcher from within a completion
27 // callback. Must be used from a thread running an IO message loop.
28 // The public methods are virtual to allow for mocking and fakes.
29 class AccessTokenFetcher : public gaia::GaiaOAuthClient::Delegate {
30 public:
31 AccessTokenFetcher();
32 ~AccessTokenFetcher() override;
34 // Retrieve an access token from a one time use authorization code.
35 virtual void GetAccessTokenFromAuthCode(const std::string& auth_code,
36 const AccessTokenCallback& callback);
38 // Retrieve an access token from a refresh token.
39 virtual void GetAccessTokenFromRefreshToken(
40 const std::string& refresh_token,
41 const AccessTokenCallback& callback);
43 private:
44 // gaia::GaiaOAuthClient::Delegate Interface.
45 void OnGetTokensResponse(const std::string& refresh_token,
46 const std::string& access_token,
47 int expires_in_seconds) override;
48 void OnRefreshTokenResponse(const std::string& access_token,
49 int expires_in_seconds) override;
50 void OnGetUserEmailResponse(const std::string& user_email) override;
51 void OnGetUserIdResponse(const std::string& user_id) override;
52 void OnGetUserInfoResponse(
53 scoped_ptr<base::DictionaryValue> user_info) override;
54 void OnGetTokenInfoResponse(
55 scoped_ptr<base::DictionaryValue> token_info) override;
56 void OnOAuthError() override;
57 void OnNetworkError(int response_code) override;
59 // Updates |auth_client_| with a new GaiaOAuthClient instance.
60 void CreateNewGaiaOAuthClientInstance();
62 // Validates the retrieved access token.
63 void ValidateAccessToken();
65 // Caller-supplied callback used to return valid tokens on success or empty
66 // tokens on failure.
67 AccessTokenCallback access_token_callback_;
69 // Retrieved based on the |refresh_token_|.
70 std::string access_token_;
72 // Supplied by the caller or retrieved from a caller-supplied auth token.
73 std::string refresh_token_;
75 // Holds the client id, secret, and redirect url used to make
76 // the Gaia service request.
77 gaia::OAuthClientInfo oauth_client_info_;
79 // Used to make token requests to GAIA.
80 scoped_ptr<gaia::GaiaOAuthClient> auth_client_;
82 DISALLOW_COPY_AND_ASSIGN(AccessTokenFetcher);
85 } // namespace test
86 } // namespace remoting
88 #endif // REMOTING_TEST_ACCESS_TOKEN_FETCHER_H_