OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH2_POLICY_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH2_POLICY_FETCHER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH2_POLICY_FETCHER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH2_POLICY_FETCHER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
15 #include "google_apis/gaia/gaia_auth_consumer.h" | 16 #include "google_apis/gaia/gaia_auth_consumer.h" |
16 #include "google_apis/gaia/oauth2_access_token_consumer.h" | 17 #include "google_apis/gaia/oauth2_access_token_consumer.h" |
| 18 #include "net/url_request/url_request_context_getter.h" |
17 | 19 |
18 class GaiaAuthFetcher; | 20 class GaiaAuthFetcher; |
19 class OAuth2AccessTokenFetcher; | 21 class OAuth2AccessTokenFetcher; |
20 | 22 |
21 namespace net { | |
22 class URLRequestContextGetter; | |
23 } | |
24 | |
25 namespace chromeos { | 23 namespace chromeos { |
26 | 24 |
27 // Fetches the OAuth2 token for the device management service. Since Profile | 25 // Fetches the OAuth2 token for the device management service. Since Profile |
28 // creation might be blocking on a user policy fetch, this fetcher must always | 26 // creation might be blocking on a user policy fetch, this fetcher must always |
29 // send a (possibly empty) token to the BrowserPolicyConnector, which will then | 27 // send a (possibly empty) token to the BrowserPolicyConnector, which will then |
30 // let the policy subsystem proceed and resume Profile creation. | 28 // let the policy subsystem proceed and resume Profile creation. |
31 // Sending the token even when no Profile is pending is also OK. | 29 // Sending the token even when no Profile is pending is also OK. |
32 class OAuth2PolicyFetcher : public base::SupportsWeakPtr<OAuth2PolicyFetcher>, | 30 class OAuth2PolicyFetcher : public base::SupportsWeakPtr<OAuth2PolicyFetcher>, |
33 public GaiaAuthConsumer, | 31 public GaiaAuthConsumer, |
34 public OAuth2AccessTokenConsumer { | 32 public OAuth2AccessTokenConsumer { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 void StartFetchingAccessToken(); | 81 void StartFetchingAccessToken(); |
84 | 82 |
85 void SetPolicyToken(const std::string& token); | 83 void SetPolicyToken(const std::string& token); |
86 // Decides how to proceed on GAIA |error|. If the error looks temporary, | 84 // Decides how to proceed on GAIA |error|. If the error looks temporary, |
87 // retries |task| until max retry count is reached. | 85 // retries |task| until max retry count is reached. |
88 // If retry count runs out, or error condition is unrecoverable, it calls | 86 // If retry count runs out, or error condition is unrecoverable, it calls |
89 // Delegate::OnOAuth2TokenFetchFailed(). | 87 // Delegate::OnOAuth2TokenFetchFailed(). |
90 void RetryOnError(const GoogleServiceAuthError& error, | 88 void RetryOnError(const GoogleServiceAuthError& error, |
91 const base::Closure& task); | 89 const base::Closure& task); |
92 | 90 |
| 91 scoped_refptr<net::URLRequestContextGetter> auth_context_getter_; |
| 92 scoped_refptr<net::URLRequestContextGetter> system_context_getter_; |
93 scoped_ptr<GaiaAuthFetcher> refresh_token_fetcher_; | 93 scoped_ptr<GaiaAuthFetcher> refresh_token_fetcher_; |
94 scoped_ptr<OAuth2AccessTokenFetcher> access_token_fetcher_; | 94 scoped_ptr<OAuth2AccessTokenFetcher> access_token_fetcher_; |
95 std::string policy_token_; | 95 std::string policy_token_; |
96 GaiaAuthConsumer::ClientOAuthResult oauth2_tokens_; | 96 GaiaAuthConsumer::ClientOAuthResult oauth2_tokens_; |
97 // OAuth2 refresh token. Could come either from the outside or through | 97 // OAuth2 refresh token. Could come either from the outside or through |
98 // refresh token fetching flow within this class. | 98 // refresh token fetching flow within this class. |
99 std::string oauth2_refresh_token_; | 99 std::string oauth2_refresh_token_; |
100 // The retry counter. Increment this only when failure happened. | 100 // The retry counter. Increment this only when failure happened. |
101 int retry_count_; | 101 int retry_count_; |
102 // True if we have already failed to fetch the policy. | 102 // True if we have already failed to fetch the policy. |
103 bool failed_; | 103 bool failed_; |
104 | 104 |
105 DISALLOW_COPY_AND_ASSIGN(OAuth2PolicyFetcher); | 105 DISALLOW_COPY_AND_ASSIGN(OAuth2PolicyFetcher); |
106 }; | 106 }; |
107 | 107 |
108 } // namespace chromeos | 108 } // namespace chromeos |
109 | 109 |
110 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH2_POLICY_FETCHER_H_ | 110 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH2_POLICY_FETCHER_H_ |
OLD | NEW |