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); | |
Sergey Ulanov
2014/05/19 22:33:46
Why do we need both this flag and EnableAutoRefres
rmsousa
2014/05/19 22:46:53
I forgot to delete EnableAutoRefresh() from here (
| |
60 virtual ~OAuthTokenGetter(); | 63 virtual ~OAuthTokenGetter(); |
61 | 64 |
65 void EnableAutoRefresh(bool enabled); | |
66 | |
62 // Call |on_access_token| with an access token, or the failure status. | 67 // Call |on_access_token| with an access token, or the failure status. |
63 void CallWithToken(const OAuthTokenGetter::TokenCallback& on_access_token); | 68 void CallWithToken(const OAuthTokenGetter::TokenCallback& on_access_token); |
64 | 69 |
65 // gaia::GaiaOAuthClient::Delegate interface. | 70 // gaia::GaiaOAuthClient::Delegate interface. |
66 virtual void OnGetTokensResponse(const std::string& user_email, | 71 virtual void OnGetTokensResponse(const std::string& user_email, |
67 const std::string& access_token, | 72 const std::string& access_token, |
68 int expires_seconds) OVERRIDE; | 73 int expires_seconds) OVERRIDE; |
69 virtual void OnRefreshTokenResponse(const std::string& access_token, | 74 virtual void OnRefreshTokenResponse(const std::string& access_token, |
70 int expires_in_seconds) OVERRIDE; | 75 int expires_in_seconds) OVERRIDE; |
71 virtual void OnGetUserEmailResponse(const std::string& user_email) OVERRIDE; | 76 virtual void OnGetUserEmailResponse(const std::string& user_email) OVERRIDE; |
72 virtual void OnOAuthError() OVERRIDE; | 77 virtual void OnOAuthError() OVERRIDE; |
73 virtual void OnNetworkError(int response_code) OVERRIDE; | 78 virtual void OnNetworkError(int response_code) OVERRIDE; |
74 | 79 |
75 private: | 80 private: |
76 void NotifyCallbacks(Status status, | 81 void NotifyCallbacks(Status status, |
77 const std::string& user_email, | 82 const std::string& user_email, |
78 const std::string& access_token); | 83 const std::string& access_token); |
79 void RefreshOAuthToken(); | 84 void RefreshOAuthToken(); |
80 | 85 |
81 scoped_ptr<OAuthCredentials> oauth_credentials_; | 86 scoped_ptr<OAuthCredentials> oauth_credentials_; |
82 scoped_ptr<gaia::GaiaOAuthClient> gaia_oauth_client_; | 87 scoped_ptr<gaia::GaiaOAuthClient> gaia_oauth_client_; |
83 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 88 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
84 | 89 |
85 bool refreshing_oauth_token_; | 90 bool refreshing_oauth_token_; |
86 std::string oauth_access_token_; | 91 std::string oauth_access_token_; |
92 std::string verified_email_; | |
87 base::Time auth_token_expiry_time_; | 93 base::Time auth_token_expiry_time_; |
88 std::queue<OAuthTokenGetter::TokenCallback> pending_callbacks_; | 94 std::queue<OAuthTokenGetter::TokenCallback> pending_callbacks_; |
95 scoped_ptr<base::OneShotTimer<OAuthTokenGetter> > refresh_timer_; | |
89 | 96 |
90 DISALLOW_COPY_AND_ASSIGN(OAuthTokenGetter); | 97 DISALLOW_COPY_AND_ASSIGN(OAuthTokenGetter); |
91 }; | 98 }; |
92 | 99 |
93 } // namespace remoting | 100 } // namespace remoting |
94 | 101 |
95 #endif // REMOTING_HOST_OAUTH_TOKEN_GETTER_H_ | 102 #endif // REMOTING_HOST_OAUTH_TOKEN_GETTER_H_ |
OLD | NEW |