| 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 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 // strings on error. | 28 // strings on error. |
| 29 typedef base::Callback<void( | 29 typedef base::Callback<void( |
| 30 const std::string& user_email, | 30 const std::string& user_email, |
| 31 const std::string& refresh_token)> CompletionCallback; | 31 const std::string& refresh_token)> CompletionCallback; |
| 32 | 32 |
| 33 OAuthClient( | 33 OAuthClient( |
| 34 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); | 34 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); |
| 35 | 35 |
| 36 ~OAuthClient() override; | 36 ~OAuthClient() override; |
| 37 | 37 |
| 38 // Redeems |auth_code| using |oauth_client_info| to obtain |refresh_token| and | 38 // Redeems |auth_code| using |oauth_client_info| to obtain |
| 39 // |access_token|, then uses the userinfo endpoint to obtain |user_email|. | 39 // |refresh_token| and |access_token|, then, if |need_user_email| is |
| 40 // Calls CompletionCallback with |user_email| and |refresh_token| when done, | 40 // true, uses the userinfo endpoint to obtain |user_email|. Calls |
| 41 // or with empty strings on error. | 41 // CompletionCallback with |user_email| and |refresh_token| when |
| 42 // If a request is received while another one is being processed, it is | 42 // done, or with empty strings on error. If a request is received |
| 43 // enqueued and processed after the first one is finished. | 43 // while another one is being processed, it is enqueued and |
| 44 // processed after the first one is finished. |
| 44 void GetCredentialsFromAuthCode( | 45 void GetCredentialsFromAuthCode( |
| 45 const gaia::OAuthClientInfo& oauth_client_info, | 46 const gaia::OAuthClientInfo& oauth_client_info, |
| 46 const std::string& auth_code, | 47 const std::string& auth_code, |
| 48 bool need_user_email, |
| 47 CompletionCallback on_done); | 49 CompletionCallback on_done); |
| 48 | 50 |
| 49 // gaia::GaiaOAuthClient::Delegate | 51 // gaia::GaiaOAuthClient::Delegate |
| 50 void OnGetTokensResponse(const std::string& refresh_token, | 52 void OnGetTokensResponse(const std::string& refresh_token, |
| 51 const std::string& access_token, | 53 const std::string& access_token, |
| 52 int expires_in_seconds) override; | 54 int expires_in_seconds) override; |
| 53 void OnRefreshTokenResponse(const std::string& access_token, | 55 void OnRefreshTokenResponse(const std::string& access_token, |
| 54 int expires_in_seconds) override; | 56 int expires_in_seconds) override; |
| 55 void OnGetUserEmailResponse(const std::string& user_email) override; | 57 void OnGetUserEmailResponse(const std::string& user_email) override; |
| 56 | 58 |
| 57 void OnOAuthError() override; | 59 void OnOAuthError() override; |
| 58 void OnNetworkError(int response_code) override; | 60 void OnNetworkError(int response_code) override; |
| 59 | 61 |
| 60 private: | 62 private: |
| 61 struct Request { | 63 struct Request { |
| 62 Request(const gaia::OAuthClientInfo& oauth_client_info, | 64 Request(const gaia::OAuthClientInfo& oauth_client_info, |
| 63 const std::string& auth_code, | 65 const std::string& auth_code, |
| 66 bool need_user_email, |
| 64 CompletionCallback on_done); | 67 CompletionCallback on_done); |
| 65 virtual ~Request(); | 68 virtual ~Request(); |
| 66 gaia::OAuthClientInfo oauth_client_info; | 69 gaia::OAuthClientInfo oauth_client_info; |
| 67 std::string auth_code; | 70 std::string auth_code; |
| 71 bool need_user_email; |
| 68 CompletionCallback on_done; | 72 CompletionCallback on_done; |
| 69 }; | 73 }; |
| 70 | 74 |
| 71 void SendResponse(const std::string& user_email, | 75 void SendResponse(const std::string& user_email, |
| 72 const std::string& refresh_token); | 76 const std::string& refresh_token); |
| 73 | 77 |
| 74 std::queue<Request> pending_requests_; | 78 std::queue<Request> pending_requests_; |
| 75 gaia::GaiaOAuthClient gaia_oauth_client_; | 79 gaia::GaiaOAuthClient gaia_oauth_client_; |
| 76 std::string refresh_token_; | 80 std::string refresh_token_; |
| 81 bool need_user_email_; |
| 77 CompletionCallback on_done_; | 82 CompletionCallback on_done_; |
| 78 | 83 |
| 79 DISALLOW_COPY_AND_ASSIGN(OAuthClient); | 84 DISALLOW_COPY_AND_ASSIGN(OAuthClient); |
| 80 }; | 85 }; |
| 81 | 86 |
| 82 } // namespace remoting | 87 } // namespace remoting |
| 83 | 88 |
| 84 #endif // REMOTING_HOST_SETUP_OAUTH_CLIENT | 89 #endif // REMOTING_HOST_SETUP_OAUTH_CLIENT |
| OLD | NEW |