| 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 #ifndef REMOTING_HOST_OAUTH_TOKEN_GETTER_H_ | 5 #ifndef REMOTING_HOST_OAUTH_TOKEN_GETTER_H_ |
| 6 #define REMOTING_HOST_OAUTH_TOKEN_GETTER_H_ | 6 #define REMOTING_HOST_OAUTH_TOKEN_GETTER_H_ |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/threading/non_thread_safe.h" | 12 #include "base/threading/non_thread_safe.h" |
| 13 #include "base/time/time.h" |
| 14 #include "base/timer/timer.h" |
| 13 #include "google_apis/gaia/gaia_oauth_client.h" | 15 #include "google_apis/gaia/gaia_oauth_client.h" |
| 14 | 16 |
| 15 namespace net { | 17 namespace net { |
| 16 class URLRequestContextGetter; | 18 class URLRequestContextGetter; |
| 17 } // namespace net | 19 } // namespace net |
| 18 | 20 |
| 19 namespace remoting { | 21 namespace remoting { |
| 20 | 22 |
| 21 // OAuthTokenGetter caches OAuth access tokens and refreshes them as needed. | 23 // OAuthTokenGetter caches OAuth access tokens and refreshes them as needed. |
| 22 class OAuthTokenGetter : | 24 class OAuthTokenGetter : |
| (...skipping 26 matching lines...) Expand all Loading... |
| 49 | 51 |
| 50 // Token delegating authority to us to act as the user. | 52 // Token delegating authority to us to act as the user. |
| 51 std::string refresh_token; | 53 std::string refresh_token; |
| 52 | 54 |
| 53 // Whether these credentials belong to a service account. | 55 // Whether these credentials belong to a service account. |
| 54 bool is_service_account; | 56 bool is_service_account; |
| 55 }; | 57 }; |
| 56 | 58 |
| 57 OAuthTokenGetter( | 59 OAuthTokenGetter( |
| 58 scoped_ptr<OAuthCredentials> oauth_credentials, | 60 scoped_ptr<OAuthCredentials> oauth_credentials, |
| 59 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); | 61 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, |
| 62 bool auto_refresh); |
| 60 virtual ~OAuthTokenGetter(); | 63 virtual ~OAuthTokenGetter(); |
| 61 | 64 |
| 62 // Call |on_access_token| with an access token, or the failure status. | 65 // Call |on_access_token| with an access token, or the failure status. |
| 63 void CallWithToken(const OAuthTokenGetter::TokenCallback& on_access_token); | 66 void CallWithToken(const OAuthTokenGetter::TokenCallback& on_access_token); |
| 64 | 67 |
| 65 // gaia::GaiaOAuthClient::Delegate interface. | 68 // gaia::GaiaOAuthClient::Delegate interface. |
| 66 virtual void OnGetTokensResponse(const std::string& user_email, | 69 virtual void OnGetTokensResponse(const std::string& user_email, |
| 67 const std::string& access_token, | 70 const std::string& access_token, |
| 68 int expires_seconds) OVERRIDE; | 71 int expires_seconds) OVERRIDE; |
| 69 virtual void OnRefreshTokenResponse(const std::string& access_token, | 72 virtual void OnRefreshTokenResponse(const std::string& access_token, |
| 70 int expires_in_seconds) OVERRIDE; | 73 int expires_in_seconds) OVERRIDE; |
| 71 virtual void OnGetUserEmailResponse(const std::string& user_email) OVERRIDE; | 74 virtual void OnGetUserEmailResponse(const std::string& user_email) OVERRIDE; |
| 72 virtual void OnOAuthError() OVERRIDE; | 75 virtual void OnOAuthError() OVERRIDE; |
| 73 virtual void OnNetworkError(int response_code) OVERRIDE; | 76 virtual void OnNetworkError(int response_code) OVERRIDE; |
| 74 | 77 |
| 75 private: | 78 private: |
| 76 void NotifyCallbacks(Status status, | 79 void NotifyCallbacks(Status status, |
| 77 const std::string& user_email, | 80 const std::string& user_email, |
| 78 const std::string& access_token); | 81 const std::string& access_token); |
| 79 void RefreshOAuthToken(); | 82 void RefreshOAuthToken(); |
| 80 | 83 |
| 81 scoped_ptr<OAuthCredentials> oauth_credentials_; | 84 scoped_ptr<OAuthCredentials> oauth_credentials_; |
| 82 scoped_ptr<gaia::GaiaOAuthClient> gaia_oauth_client_; | 85 scoped_ptr<gaia::GaiaOAuthClient> gaia_oauth_client_; |
| 83 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 86 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| 84 | 87 |
| 85 bool refreshing_oauth_token_; | 88 bool refreshing_oauth_token_; |
| 86 std::string oauth_access_token_; | 89 std::string oauth_access_token_; |
| 90 std::string verified_email_; |
| 87 base::Time auth_token_expiry_time_; | 91 base::Time auth_token_expiry_time_; |
| 88 std::queue<OAuthTokenGetter::TokenCallback> pending_callbacks_; | 92 std::queue<OAuthTokenGetter::TokenCallback> pending_callbacks_; |
| 93 scoped_ptr<base::OneShotTimer<OAuthTokenGetter> > refresh_timer_; |
| 89 | 94 |
| 90 DISALLOW_COPY_AND_ASSIGN(OAuthTokenGetter); | 95 DISALLOW_COPY_AND_ASSIGN(OAuthTokenGetter); |
| 91 }; | 96 }; |
| 92 | 97 |
| 93 } // namespace remoting | 98 } // namespace remoting |
| 94 | 99 |
| 95 #endif // REMOTING_HOST_OAUTH_TOKEN_GETTER_H_ | 100 #endif // REMOTING_HOST_OAUTH_TOKEN_GETTER_H_ |
| OLD | NEW |