ozone: DCHECK page_flip_request instead of page_flip_request_
[chromium-blink-merge.git] / remoting / host / oauth_token_getter_impl.h
blob37bd85e5d60da8258c88d947eb3f1e7a571bb252
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_
8 #include <queue>
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"
18 namespace net {
19 class URLRequestContextGetter;
20 } // namespace net
22 namespace remoting {
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 {
28 public:
29 OAuthTokenGetterImpl(scoped_ptr<OAuthCredentials> oauth_credentials,
30 const scoped_refptr<net::URLRequestContextGetter>&
31 url_request_context_getter,
32 bool auto_refresh,
33 bool verify_email);
34 ~OAuthTokenGetterImpl() override;
36 // OAuthTokenGetter interface.
37 void CallWithToken(
38 const OAuthTokenGetter::TokenCallback& on_access_token) override;
40 private:
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_