OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef REMOTING_HOST_SETUP_OAUTH_CLIENT | 5 #ifndef REMOTING_HOST_SETUP_OAUTH_CLIENT |
6 #define REMOTING_HOST_SETUP_OAUTH_CLIENT | 6 #define REMOTING_HOST_SETUP_OAUTH_CLIENT |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "google_apis/gaia/gaia_oauth_client.h" | 13 #include "google_apis/gaia/gaia_oauth_client.h" |
14 #include "net/url_request/url_request_context_getter.h" | 14 #include "net/url_request/url_request_context_getter.h" |
15 | 15 |
16 namespace net { | 16 namespace net { |
17 class URLRequestContext; | 17 class URLRequestContext; |
18 } | 18 } |
19 | 19 |
20 namespace remoting { | 20 namespace remoting { |
21 | 21 |
22 // A wrapper around GaiaOAuthClient that provides a more convenient interface, | 22 class OAuthClient { |
23 // with queueing of requests and a callback rather than a delegate. | |
24 class OAuthClient : public gaia::GaiaOAuthClient::Delegate { | |
25 public: | 23 public: |
26 // Called when GetCredentialsFromAuthCode is completed, with the |user_email| | 24 // Called when GetCredentialsFromAuthCode is completed, with the |user_email| |
27 // and |refresh_token| that correspond to the given |auth_code|, or with empty | 25 // and |refresh_token| that correspond to the given |auth_code|, or with empty |
28 // strings on error. | 26 // strings on error. |
29 typedef base::Callback<void( | 27 typedef base::Callback<void( |
30 const std::string& user_email, | 28 const std::string& user_email, |
31 const std::string& refresh_token)> CompletionCallback; | 29 const std::string& refresh_token)> CompletionCallback; |
32 | 30 |
33 OAuthClient( | 31 virtual ~OAuthClient(); |
Lambros
2015/04/24 18:15:50
You should inline this dtor, because this class is
John Williams
2015/04/24 21:05:13
Done.
| |
34 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); | |
35 | |
36 ~OAuthClient() override; | |
37 | 32 |
38 // Redeems |auth_code| using |oauth_client_info| to obtain |refresh_token| and | 33 // Redeems |auth_code| using |oauth_client_info| to obtain |refresh_token| and |
39 // |access_token|, then uses the userinfo endpoint to obtain |user_email|. | 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 virtual void GetCredentialsFromAuthCode( | |
40 const gaia::OAuthClientInfo& oauth_client_info, | |
41 const std::string& auth_code, | |
42 CompletionCallback on_done) = 0; | |
43 }; | |
44 | |
45 // A wrapper around GaiaOAuthClient that provides a more convenient interface, | |
Lambros
2015/04/24 18:15:50
nit: gaia::GaiaOAuthClient, because of the naming
John Williams
2015/04/24 21:05:13
Done.
| |
46 // with queueing of requests and a callback rather than a delegate. | |
47 class GaiaOAuthClient : | |
Lambros
2015/04/24 18:15:50
I think this should be in its own file, gaia_oauth
John Williams
2015/04/24 21:05:13
Done.
| |
48 public OAuthClient, | |
49 public gaia::GaiaOAuthClient::Delegate { | |
50 public: | |
51 GaiaOAuthClient( | |
52 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); | |
53 | |
54 ~GaiaOAuthClient() override; | |
55 | |
56 // Redeems |auth_code| using |oauth_client_info| to obtain |refresh_token| and | |
57 // |access_token|, then uses the userinfo endpoint to obtain |user_email|. | |
40 // Calls CompletionCallback with |user_email| and |refresh_token| when done, | 58 // Calls CompletionCallback with |user_email| and |refresh_token| when done, |
41 // or with empty strings on error. | 59 // or with empty strings on error. |
42 // If a request is received while another one is being processed, it is | 60 // If a request is received while another one is being processed, it is |
43 // enqueued and processed after the first one is finished. | 61 // enqueued and processed after the first one is finished. |
44 void GetCredentialsFromAuthCode( | 62 void GetCredentialsFromAuthCode( |
45 const gaia::OAuthClientInfo& oauth_client_info, | 63 const gaia::OAuthClientInfo& oauth_client_info, |
46 const std::string& auth_code, | 64 const std::string& auth_code, |
47 CompletionCallback on_done); | 65 CompletionCallback on_done) override; |
48 | 66 |
49 // gaia::GaiaOAuthClient::Delegate | 67 // gaia::GaiaOAuthClient::Delegate |
50 void OnGetTokensResponse(const std::string& refresh_token, | 68 void OnGetTokensResponse(const std::string& refresh_token, |
51 const std::string& access_token, | 69 const std::string& access_token, |
52 int expires_in_seconds) override; | 70 int expires_in_seconds) override; |
53 void OnRefreshTokenResponse(const std::string& access_token, | 71 void OnRefreshTokenResponse(const std::string& access_token, |
54 int expires_in_seconds) override; | 72 int expires_in_seconds) override; |
55 void OnGetUserEmailResponse(const std::string& user_email) override; | 73 void OnGetUserEmailResponse(const std::string& user_email) override; |
56 | 74 |
57 void OnOAuthError() override; | 75 void OnOAuthError() override; |
(...skipping 11 matching lines...) Expand all Loading... | |
69 }; | 87 }; |
70 | 88 |
71 void SendResponse(const std::string& user_email, | 89 void SendResponse(const std::string& user_email, |
72 const std::string& refresh_token); | 90 const std::string& refresh_token); |
73 | 91 |
74 std::queue<Request> pending_requests_; | 92 std::queue<Request> pending_requests_; |
75 gaia::GaiaOAuthClient gaia_oauth_client_; | 93 gaia::GaiaOAuthClient gaia_oauth_client_; |
76 std::string refresh_token_; | 94 std::string refresh_token_; |
77 CompletionCallback on_done_; | 95 CompletionCallback on_done_; |
78 | 96 |
79 DISALLOW_COPY_AND_ASSIGN(OAuthClient); | 97 DISALLOW_COPY_AND_ASSIGN(GaiaOAuthClient); |
80 }; | 98 }; |
81 | 99 |
82 } // namespace remoting | 100 } // namespace remoting |
83 | 101 |
84 #endif // REMOTING_HOST_SETUP_OAUTH_CLIENT | 102 #endif // REMOTING_HOST_SETUP_OAUTH_CLIENT |
OLD | NEW |