OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef REMOTING_HOST_SETUP_GAIA_OAUTH_CLIENT_H_ | |
6 #define REMOTING_HOST_SETUP_GAIA_OAUTH_CLIENT_H_ | |
7 | |
8 #include <queue> | |
9 | |
10 #include "base/macros.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "google_apis/gaia/gaia_oauth_client.h" | |
13 #include "net/url_request/url_request_context_getter.h" | |
14 | |
15 #include "remoting/host/setup/oauth_client.h" | |
16 | |
17 namespace remoting { | |
18 | |
19 // A wrapper around gaia::GaiaOAuthClient that provides a more | |
20 // convenient interface, with queueing of requests and a callback | |
21 // rather than a delegate. | |
22 class GaiaOAuthClient : public OAuthClient, | |
23 public gaia::GaiaOAuthClient::Delegate { | |
24 public: | |
25 GaiaOAuthClient( | |
26 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); | |
27 | |
28 ~GaiaOAuthClient() override; | |
29 | |
30 // Redeems |auth_code| using |oauth_client_info| to obtain |refresh_token| and | |
31 // |access_token|, then uses the userinfo endpoint to obtain |user_email|. | |
32 // Calls CompletionCallback with |user_email| and |refresh_token| when done, | |
33 // or with empty strings on error. | |
34 // If a request is received while another one is being processed, it is | |
35 // enqueued and processed after the first one is finished. | |
36 void GetCredentialsFromAuthCode( | |
37 const gaia::OAuthClientInfo& oauth_client_info, | |
38 const std::string& auth_code, | |
39 bool need_user_email, | |
40 CompletionCallback on_done) override; | |
41 | |
42 // gaia::GaiaOAuthClient::Delegate | |
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 | |
50 void OnOAuthError() override; | |
51 void OnNetworkError(int response_code) override; | |
52 | |
53 private: | |
54 struct Request { | |
55 Request(const gaia::OAuthClientInfo& oauth_client_info, | |
56 const std::string& auth_code, | |
57 bool need_user_email, | |
58 CompletionCallback on_done); | |
59 Request(const Request& other); | |
60 virtual ~Request(); | |
61 gaia::OAuthClientInfo oauth_client_info; | |
62 std::string auth_code; | |
63 bool need_user_email; | |
64 CompletionCallback on_done; | |
65 }; | |
66 | |
67 void SendResponse(const std::string& user_email, | |
68 const std::string& refresh_token); | |
69 | |
70 std::queue<Request> pending_requests_; | |
71 gaia::GaiaOAuthClient gaia_oauth_client_; | |
72 std::string refresh_token_; | |
73 bool need_user_email_; | |
74 CompletionCallback on_done_; | |
75 | |
76 DISALLOW_COPY_AND_ASSIGN(GaiaOAuthClient); | |
77 }; | |
78 | |
79 } // namespace remoting | |
80 | |
81 #endif // REMOTING_HOST_SETUP_GAIA_OAUTH_CLIENT_H_ | |
OLD | NEW |