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
3 // found in the LICENSE file.
5 #ifndef REMOTING_HOST_OAUTH_TOKEN_GETTER_IMPL_H_
6 #define REMOTING_HOST_OAUTH_TOKEN_GETTER_IMPL_H_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/threading/non_thread_safe.h"
13 #include "base/time/time.h"
14 #include "base/timer/timer.h"
15 #include "google_apis/gaia/gaia_oauth_client.h"
16 #include "remoting/host/oauth_token_getter.h"
19 class URLRequestContextGetter
;
24 // OAuthTokenGetter caches OAuth access tokens and refreshes them as needed.
25 class OAuthTokenGetterImpl
: public OAuthTokenGetter
,
26 public base::NonThreadSafe
,
27 public gaia::GaiaOAuthClient::Delegate
{
29 OAuthTokenGetterImpl(scoped_ptr
<OAuthCredentials
> oauth_credentials
,
30 const scoped_refptr
<net::URLRequestContextGetter
>&
31 url_request_context_getter
,
34 ~OAuthTokenGetterImpl() override
;
36 // OAuthTokenGetter interface.
38 const OAuthTokenGetter::TokenCallback
& on_access_token
) override
;
41 // gaia::GaiaOAuthClient::Delegate interface.
42 void OnGetTokensResponse(const std::string
& user_email
,
43 const std::string
& access_token
,
44 int expires_seconds
) override
;
45 void OnRefreshTokenResponse(const std::string
& access_token
,
46 int expires_in_seconds
) override
;
47 void OnGetUserEmailResponse(const std::string
& user_email
) override
;
48 void OnOAuthError() override
;
49 void OnNetworkError(int response_code
) override
;
51 void NotifyCallbacks(Status status
,
52 const std::string
& user_email
,
53 const std::string
& access_token
);
54 void RefreshOAuthToken();
56 scoped_ptr
<OAuthCredentials
> oauth_credentials_
;
57 scoped_ptr
<gaia::GaiaOAuthClient
> gaia_oauth_client_
;
58 scoped_refptr
<net::URLRequestContextGetter
> url_request_context_getter_
;
59 const bool verify_email_
;
61 bool refreshing_oauth_token_
= false;
62 bool email_verified_
= false;
63 std::string oauth_access_token_
;
64 base::Time auth_token_expiry_time_
;
65 std::queue
<OAuthTokenGetter::TokenCallback
> pending_callbacks_
;
66 scoped_ptr
<base::OneShotTimer
<OAuthTokenGetterImpl
>> refresh_timer_
;
69 } // namespace remoting
71 #endif // REMOTING_HOST_OAUTH_TOKEN_GETTER_IMPL_H_