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 CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_OAUTH2_TOKEN_FETCHER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_OAUTH2_TOKEN_FETCHER_H_
10 #include "base/basictypes.h"
11 #include "base/callback_forward.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/weak_ptr.h"
14 #include "google_apis/gaia/gaia_auth_consumer.h"
15 #include "google_apis/gaia/gaia_auth_fetcher.h"
18 class URLRequestContextGetter
;
23 // OAuth2TokenFetcher is used to convert authenticated cookie jar from the
24 // authentication profile into OAuth2 tokens and GAIA credentials that will be
25 // used to kick off other token retrieval tasks.
26 class OAuth2TokenFetcher
: public base::SupportsWeakPtr
<OAuth2TokenFetcher
>,
27 public GaiaAuthConsumer
{
31 virtual ~Delegate() {}
32 virtual void OnOAuth2TokensAvailable(
33 const GaiaAuthConsumer::ClientOAuthResult
& oauth2_tokens
) = 0;
34 virtual void OnOAuth2TokensFetchFailed() = 0;
37 OAuth2TokenFetcher(OAuth2TokenFetcher::Delegate
* delegate
,
38 net::URLRequestContextGetter
* context_getter
);
39 ~OAuth2TokenFetcher() override
;
41 void StartExchangeFromCookies(const std::string
& session_index
,
42 const std::string
& signin_scoped_device_id
);
43 void StartExchangeFromAuthCode(const std::string
& auth_code
,
44 const std::string
& signin_scoped_device_id
);
47 // Decides how to proceed on GAIA |error|. If the error looks temporary,
48 // retries |task| until max retry count is reached.
49 // If retry count runs out, or error condition is unrecoverable, it runs
51 void RetryOnError(const GoogleServiceAuthError
& error
,
52 const base::Closure
& task
,
53 const base::Closure
& error_handler
);
55 // GaiaAuthConsumer overrides.
56 void OnClientOAuthSuccess(
57 const GaiaAuthConsumer::ClientOAuthResult
& result
) override
;
58 void OnClientOAuthFailure(const GoogleServiceAuthError
& error
) override
;
60 OAuth2TokenFetcher::Delegate
* delegate_
;
61 GaiaAuthConsumer::ClientOAuthResult oauth_tokens_
;
62 GaiaAuthFetcher auth_fetcher_
;
64 // The retry counter. Increment this only when failure happened.
66 std::string session_index_
;
67 std::string signin_scoped_device_id_
;
68 std::string auth_code_
;
70 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenFetcher
);
73 } // namespace chromeos
75 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_OAUTH2_TOKEN_FETCHER_H_