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 #include "remoting/host/setup/oauth_client.h" | 5 #include "remoting/host/setup/gaia_oauth_client.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace { | 9 namespace { |
10 const int kMaxGaiaRetries = 3; | 10 const int kMaxGaiaRetries = 3; |
11 } // namespace | 11 } // namespace |
12 | 12 |
13 namespace remoting { | 13 namespace remoting { |
14 | 14 |
15 OAuthClient::OAuthClient( | 15 GaiaOAuthClient::GaiaOAuthClient( |
16 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) | 16 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) |
17 : gaia_oauth_client_(url_request_context_getter.get()) { | 17 : gaia_oauth_client_(url_request_context_getter.get()) { |
18 } | 18 } |
19 | 19 |
20 OAuthClient::~OAuthClient() { | 20 GaiaOAuthClient::~GaiaOAuthClient() { |
21 } | 21 } |
22 | 22 |
23 void OAuthClient::GetCredentialsFromAuthCode( | 23 void GaiaOAuthClient::GetCredentialsFromAuthCode( |
24 const gaia::OAuthClientInfo& oauth_client_info, | 24 const gaia::OAuthClientInfo& oauth_client_info, |
25 const std::string& auth_code, | 25 const std::string& auth_code, |
26 CompletionCallback on_done) { | 26 CompletionCallback on_done) { |
27 | 27 |
28 if (!on_done_.is_null()) { | 28 if (!on_done_.is_null()) { |
29 pending_requests_.push(Request(oauth_client_info, auth_code, on_done)); | 29 pending_requests_.push(Request(oauth_client_info, auth_code, on_done)); |
30 return; | 30 return; |
31 } | 31 } |
32 | 32 |
33 on_done_ = on_done; | 33 on_done_ = on_done; |
34 // Map the authorization code to refresh and access tokens. | 34 // Map the authorization code to refresh and access tokens. |
35 gaia_oauth_client_.GetTokensFromAuthCode(oauth_client_info, auth_code, | 35 gaia_oauth_client_.GetTokensFromAuthCode(oauth_client_info, auth_code, |
36 kMaxGaiaRetries, this); | 36 kMaxGaiaRetries, this); |
37 } | 37 } |
38 | 38 |
39 void OAuthClient::OnGetTokensResponse( | 39 void GaiaOAuthClient::OnGetTokensResponse( |
40 const std::string& refresh_token, | 40 const std::string& refresh_token, |
41 const std::string& access_token, | 41 const std::string& access_token, |
42 int expires_in_seconds) { | 42 int expires_in_seconds) { |
43 refresh_token_ = refresh_token; | 43 refresh_token_ = refresh_token; |
44 // Get the email corresponding to the access token. | 44 // Get the email corresponding to the access token. |
45 gaia_oauth_client_.GetUserEmail(access_token, kMaxGaiaRetries, this); | 45 gaia_oauth_client_.GetUserEmail(access_token, kMaxGaiaRetries, this); |
46 } | 46 } |
47 | 47 |
48 void OAuthClient::OnRefreshTokenResponse( | 48 void GaiaOAuthClient::OnRefreshTokenResponse( |
49 const std::string& access_token, | 49 const std::string& access_token, |
50 int expires_in_seconds) { | 50 int expires_in_seconds) { |
51 // We never request a refresh token, so this call is not expected. | 51 // We never request a refresh token, so this call is not expected. |
52 NOTREACHED(); | 52 NOTREACHED(); |
53 } | 53 } |
54 | 54 |
55 void OAuthClient::SendResponse(const std::string& user_email, | 55 void GaiaOAuthClient::SendResponse( |
56 const std::string& refresh_token) { | 56 const std::string& user_email, |
Lambros
2015/04/24 21:38:56
Don't need to change formatting - the old formatti
John Williams
2015/04/24 21:48:42
Done.
| |
57 const std::string& refresh_token) { | |
57 CompletionCallback on_done = on_done_; | 58 CompletionCallback on_done = on_done_; |
58 on_done_.Reset(); | 59 on_done_.Reset(); |
59 on_done.Run(user_email, refresh_token); | 60 on_done.Run(user_email, refresh_token); |
60 | 61 |
61 // Process the next request in the queue. | 62 // Process the next request in the queue. |
62 if (pending_requests_.size()) { | 63 if (pending_requests_.size()) { |
63 Request request = pending_requests_.front(); | 64 Request request = pending_requests_.front(); |
64 pending_requests_.pop(); | 65 pending_requests_.pop(); |
65 // GetCredentialsFromAuthCode is asynchronous, so it's safe to call it here. | 66 // GetCredentialsFromAuthCode is asynchronous, so it's safe to call it here. |
66 GetCredentialsFromAuthCode( | 67 GetCredentialsFromAuthCode( |
67 request.oauth_client_info, request.auth_code, request.on_done); | 68 request.oauth_client_info, request.auth_code, request.on_done); |
68 } | 69 } |
69 } | 70 } |
70 | 71 |
71 void OAuthClient::OnGetUserEmailResponse(const std::string& user_email) { | 72 void GaiaOAuthClient::OnGetUserEmailResponse(const std::string& user_email) { |
72 SendResponse(user_email, refresh_token_); | 73 SendResponse(user_email, refresh_token_); |
73 } | 74 } |
74 | 75 |
75 void OAuthClient::OnOAuthError() { | 76 void GaiaOAuthClient::OnOAuthError() { |
76 SendResponse("", ""); | 77 SendResponse("", ""); |
77 } | 78 } |
78 | 79 |
79 void OAuthClient::OnNetworkError(int response_code) { | 80 void GaiaOAuthClient::OnNetworkError(int response_code) { |
80 SendResponse("", ""); | 81 SendResponse("", ""); |
81 } | 82 } |
82 | 83 |
83 OAuthClient::Request::Request( | 84 GaiaOAuthClient::Request::Request( |
84 const gaia::OAuthClientInfo& oauth_client_info, | 85 const gaia::OAuthClientInfo& oauth_client_info, |
85 const std::string& auth_code, | 86 const std::string& auth_code, |
86 CompletionCallback on_done) { | 87 CompletionCallback on_done) { |
87 this->oauth_client_info = oauth_client_info; | 88 this->oauth_client_info = oauth_client_info; |
88 this->auth_code = auth_code; | 89 this->auth_code = auth_code; |
89 this->on_done = on_done; | 90 this->on_done = on_done; |
90 } | 91 } |
91 | 92 |
92 OAuthClient::Request::~Request() { | 93 GaiaOAuthClient::Request::~Request() { |
93 } | 94 } |
94 | 95 |
95 } // namespace remoting | 96 } // namespace remoting |
OLD | NEW |