| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/oauth_token_getter_impl.h" | 5 #include "remoting/host/oauth_token_getter_impl.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 9 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 10 #include "google_apis/google_api_keys.h" | 12 #include "google_apis/google_api_keys.h" |
| 11 #include "net/url_request/url_request_context_getter.h" | 13 #include "net/url_request/url_request_context_getter.h" |
| 12 #include "remoting/base/logging.h" | 14 #include "remoting/base/logging.h" |
| 13 | 15 |
| 14 namespace remoting { | 16 namespace remoting { |
| 15 | 17 |
| 16 namespace { | 18 namespace { |
| 17 | 19 |
| 18 // Maximum number of retries on network/500 errors. | 20 // Maximum number of retries on network/500 errors. |
| 19 const int kMaxRetries = 3; | 21 const int kMaxRetries = 3; |
| 20 | 22 |
| 21 // Time when we we try to update OAuth token before its expiration. | 23 // Time when we we try to update OAuth token before its expiration. |
| 22 const int kTokenUpdateTimeBeforeExpirySeconds = 60; | 24 const int kTokenUpdateTimeBeforeExpirySeconds = 60; |
| 23 | 25 |
| 24 } // namespace | 26 } // namespace |
| 25 | 27 |
| 26 OAuthTokenGetterImpl::OAuthTokenGetterImpl( | 28 OAuthTokenGetterImpl::OAuthTokenGetterImpl( |
| 27 scoped_ptr<OAuthCredentials> oauth_credentials, | 29 scoped_ptr<OAuthCredentials> oauth_credentials, |
| 28 const scoped_refptr<net::URLRequestContextGetter>& | 30 const scoped_refptr<net::URLRequestContextGetter>& |
| 29 url_request_context_getter, | 31 url_request_context_getter, |
| 30 bool auto_refresh) | 32 bool auto_refresh) |
| 31 : oauth_credentials_(oauth_credentials.Pass()), | 33 : oauth_credentials_(std::move(oauth_credentials)), |
| 32 gaia_oauth_client_( | 34 gaia_oauth_client_( |
| 33 new gaia::GaiaOAuthClient(url_request_context_getter.get())), | 35 new gaia::GaiaOAuthClient(url_request_context_getter.get())), |
| 34 url_request_context_getter_(url_request_context_getter) { | 36 url_request_context_getter_(url_request_context_getter) { |
| 35 if (auto_refresh) { | 37 if (auto_refresh) { |
| 36 refresh_timer_.reset(new base::OneShotTimer()); | 38 refresh_timer_.reset(new base::OneShotTimer()); |
| 37 } | 39 } |
| 38 } | 40 } |
| 39 | 41 |
| 40 OAuthTokenGetterImpl::~OAuthTokenGetterImpl() { | 42 OAuthTokenGetterImpl::~OAuthTokenGetterImpl() {} |
| 41 } | |
| 42 | 43 |
| 43 void OAuthTokenGetterImpl::OnGetTokensResponse(const std::string& user_email, | 44 void OAuthTokenGetterImpl::OnGetTokensResponse(const std::string& user_email, |
| 44 const std::string& access_token, | 45 const std::string& access_token, |
| 45 int expires_seconds) { | 46 int expires_seconds) { |
| 46 NOTREACHED(); | 47 NOTREACHED(); |
| 47 } | 48 } |
| 48 | 49 |
| 49 void OAuthTokenGetterImpl::OnRefreshTokenResponse( | 50 void OAuthTokenGetterImpl::OnRefreshTokenResponse( |
| 50 const std::string& access_token, | 51 const std::string& access_token, |
| 51 int expires_seconds) { | 52 int expires_seconds) { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 ""}; | 172 ""}; |
| 172 | 173 |
| 173 refreshing_oauth_token_ = true; | 174 refreshing_oauth_token_ = true; |
| 174 std::vector<std::string> empty_scope_list; // Use scope from refresh token. | 175 std::vector<std::string> empty_scope_list; // Use scope from refresh token. |
| 175 gaia_oauth_client_->RefreshToken(client_info, | 176 gaia_oauth_client_->RefreshToken(client_info, |
| 176 oauth_credentials_->refresh_token, | 177 oauth_credentials_->refresh_token, |
| 177 empty_scope_list, kMaxRetries, this); | 178 empty_scope_list, kMaxRetries, this); |
| 178 } | 179 } |
| 179 | 180 |
| 180 } // namespace remoting | 181 } // namespace remoting |
| OLD | NEW |