OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_POLICY_POLICY_OAUTH2_TOKEN_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_POLICY_OAUTH2_TOKEN_FETCHER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_POLICY_POLICY_OAUTH2_TOKEN_FETCHER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POLICY_POLICY_OAUTH2_TOKEN_FETCHER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 return failed_; | 61 return failed_; |
62 } | 62 } |
63 | 63 |
64 const std::string& oauth2_refresh_token() const { | 64 const std::string& oauth2_refresh_token() const { |
65 return oauth2_refresh_token_; | 65 return oauth2_refresh_token_; |
66 } | 66 } |
67 const std::string& oauth2_access_token() const { | 67 const std::string& oauth2_access_token() const { |
68 return oauth2_access_token_; | 68 return oauth2_access_token_; |
69 } | 69 } |
70 | 70 |
| 71 // Causes fake tokens to be returned so no network calls are made. |
| 72 static void EnableFakeForTesting(); |
| 73 |
71 private: | 74 private: |
72 // GaiaAuthConsumer overrides. | 75 // GaiaAuthConsumer overrides. |
73 void OnClientOAuthSuccess( | 76 void OnClientOAuthSuccess( |
74 const GaiaAuthConsumer::ClientOAuthResult& oauth_tokens) override; | 77 const GaiaAuthConsumer::ClientOAuthResult& oauth_tokens) override; |
75 void OnClientOAuthFailure(const GoogleServiceAuthError& error) override; | 78 void OnClientOAuthFailure(const GoogleServiceAuthError& error) override; |
76 | 79 |
77 // OAuth2AccessTokenConsumer overrides. | 80 // OAuth2AccessTokenConsumer overrides. |
78 void OnGetTokenSuccess(const std::string& access_token, | 81 void OnGetTokenSuccess(const std::string& access_token, |
79 const base::Time& expiration_time) override; | 82 const base::Time& expiration_time) override; |
80 void OnGetTokenFailure(const GoogleServiceAuthError& error) override; | 83 void OnGetTokenFailure(const GoogleServiceAuthError& error) override; |
81 | 84 |
82 // Starts fetching OAuth2 refresh token. | 85 // Starts fetching OAuth2 refresh token. |
83 void StartFetchingRefreshToken(); | 86 void StartFetchingRefreshToken(); |
84 | 87 |
85 // Starts fetching OAuth2 access token for the device management service. | 88 // Starts fetching OAuth2 access token for the device management service. |
86 void StartFetchingAccessToken(); | 89 void StartFetchingAccessToken(); |
87 | 90 |
88 // Decides how to proceed on GAIA |error|. If the error looks temporary, | 91 // Decides how to proceed on GAIA |error|. If the error looks temporary, |
89 // retries |task| until max retry count is reached. | 92 // retries |task| until max retry count is reached. |
90 // If retry count runs out, or error condition is unrecoverable, it calls | 93 // If retry count runs out, or error condition is unrecoverable, it calls |
91 // Delegate::OnOAuth2TokenFetchFailed(). | 94 // Delegate::OnOAuth2TokenFetchFailed(). |
92 void RetryOnError(const GoogleServiceAuthError& error, | 95 void RetryOnError(const GoogleServiceAuthError& error, |
93 const base::Closure& task); | 96 const base::Closure& task); |
94 | 97 |
95 // Passes |token| and |error| to the |callback_|. | 98 // Passes |token| and |error| to the |callback_|. |
96 void ForwardPolicyToken(const std::string& token, | 99 void ForwardPolicyToken(const std::string& token, |
97 const GoogleServiceAuthError& error); | 100 const GoogleServiceAuthError& error); |
98 | 101 |
| 102 // If true, fake policy tokens will be sent instead of making network |
| 103 // requests. |
| 104 static bool enable_fake_for_testing_; |
| 105 |
99 // Auth code which is used to retreive a refresh token. | 106 // Auth code which is used to retreive a refresh token. |
100 std::string auth_code_; | 107 std::string auth_code_; |
101 | 108 |
102 scoped_refptr<net::URLRequestContextGetter> auth_context_getter_; | 109 scoped_refptr<net::URLRequestContextGetter> auth_context_getter_; |
103 scoped_refptr<net::URLRequestContextGetter> system_context_getter_; | 110 scoped_refptr<net::URLRequestContextGetter> system_context_getter_; |
104 scoped_ptr<GaiaAuthFetcher> refresh_token_fetcher_; | 111 scoped_ptr<GaiaAuthFetcher> refresh_token_fetcher_; |
105 scoped_ptr<OAuth2AccessTokenFetcher> access_token_fetcher_; | 112 scoped_ptr<OAuth2AccessTokenFetcher> access_token_fetcher_; |
106 | 113 |
107 // OAuth2 refresh token. Could come either from the outside or through | 114 // OAuth2 refresh token. Could come either from the outside or through |
108 // refresh token fetching flow within this class. | 115 // refresh token fetching flow within this class. |
(...skipping 10 matching lines...) Expand all Loading... |
119 | 126 |
120 // The callback to invoke when done. | 127 // The callback to invoke when done. |
121 TokenCallback callback_; | 128 TokenCallback callback_; |
122 | 129 |
123 DISALLOW_COPY_AND_ASSIGN(PolicyOAuth2TokenFetcher); | 130 DISALLOW_COPY_AND_ASSIGN(PolicyOAuth2TokenFetcher); |
124 }; | 131 }; |
125 | 132 |
126 } // namespace policy | 133 } // namespace policy |
127 | 134 |
128 #endif // CHROME_BROWSER_CHROMEOS_POLICY_POLICY_OAUTH2_TOKEN_FETCHER_H_ | 135 #endif // CHROME_BROWSER_CHROMEOS_POLICY_POLICY_OAUTH2_TOKEN_FETCHER_H_ |
OLD | NEW |