Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / remoting / host / setup / gaia_oauth_client.h
blobd6bb72cbc00aff1400b7571c523df3671369e47d
1 // Copyright 2013 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_HOST_SETUP_GAIA_OAUTH_CLIENT_H_
6 #define REMOTING_HOST_SETUP_GAIA_OAUTH_CLIENT_H_
8 #include <queue>
10 #include "base/memory/ref_counted.h"
11 #include "google_apis/gaia/gaia_oauth_client.h"
12 #include "net/url_request/url_request_context_getter.h"
14 #include "remoting/host/setup/oauth_client.h"
16 namespace net {
17 class URLRequestContext;
20 namespace remoting {
22 // A wrapper around gaia::GaiaOAuthClient that provides a more
23 // convenient interface, with queueing of requests and a callback
24 // rather than a delegate.
25 class GaiaOAuthClient : public OAuthClient,
26 public gaia::GaiaOAuthClient::Delegate {
27 public:
28 GaiaOAuthClient(
29 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter);
31 ~GaiaOAuthClient() override;
33 // Redeems |auth_code| using |oauth_client_info| to obtain |refresh_token| and
34 // |access_token|, then uses the userinfo endpoint to obtain |user_email|.
35 // Calls CompletionCallback with |user_email| and |refresh_token| when done,
36 // or with empty strings on error.
37 // If a request is received while another one is being processed, it is
38 // enqueued and processed after the first one is finished.
39 void GetCredentialsFromAuthCode(
40 const gaia::OAuthClientInfo& oauth_client_info,
41 const std::string& auth_code,
42 bool need_user_email,
43 CompletionCallback on_done) override;
45 // gaia::GaiaOAuthClient::Delegate
46 void OnGetTokensResponse(const std::string& refresh_token,
47 const std::string& access_token,
48 int expires_in_seconds) override;
49 void OnRefreshTokenResponse(const std::string& access_token,
50 int expires_in_seconds) override;
51 void OnGetUserEmailResponse(const std::string& user_email) override;
53 void OnOAuthError() override;
54 void OnNetworkError(int response_code) override;
56 private:
57 struct Request {
58 Request(const gaia::OAuthClientInfo& oauth_client_info,
59 const std::string& auth_code,
60 bool need_user_email,
61 CompletionCallback on_done);
62 virtual ~Request();
63 gaia::OAuthClientInfo oauth_client_info;
64 std::string auth_code;
65 bool need_user_email;
66 CompletionCallback on_done;
69 void SendResponse(const std::string& user_email,
70 const std::string& refresh_token);
72 std::queue<Request> pending_requests_;
73 gaia::GaiaOAuthClient gaia_oauth_client_;
74 std::string refresh_token_;
75 bool need_user_email_;
76 CompletionCallback on_done_;
78 DISALLOW_COPY_AND_ASSIGN(GaiaOAuthClient);
81 } // namespace remoting
83 #endif // REMOTING_HOST_SETUP_GAIA_OAUTH_CLIENT_H_