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
,
33 ~OAuthTokenGetterImpl() override
;
35 // OAuthTokenGetter interface.
37 const OAuthTokenGetter::TokenCallback
& on_access_token
) override
;
40 // gaia::GaiaOAuthClient::Delegate interface.
41 void OnGetTokensResponse(const std::string
& user_email
,
42 const std::string
& access_token
,
43 int expires_seconds
) override
;
44 void OnRefreshTokenResponse(const std::string
& access_token
,
45 int expires_in_seconds
) override
;
46 void OnGetUserEmailResponse(const std::string
& user_email
) override
;
47 void OnOAuthError() override
;
48 void OnNetworkError(int response_code
) override
;
50 void NotifyCallbacks(Status status
,
51 const std::string
& user_email
,
52 const std::string
& access_token
);
53 void RefreshOAuthToken();
55 scoped_ptr
<OAuthCredentials
> oauth_credentials_
;
56 scoped_ptr
<gaia::GaiaOAuthClient
> gaia_oauth_client_
;
57 scoped_refptr
<net::URLRequestContextGetter
> url_request_context_getter_
;
59 bool refreshing_oauth_token_
= false;
60 bool email_verified_
= false;
61 std::string oauth_access_token_
;
62 base::Time auth_token_expiry_time_
;
63 std::queue
<OAuthTokenGetter::TokenCallback
> pending_callbacks_
;
64 scoped_ptr
<base::OneShotTimer
<OAuthTokenGetterImpl
>> refresh_timer_
;
67 } // namespace remoting
69 #endif // REMOTING_HOST_OAUTH_TOKEN_GETTER_IMPL_H_