OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ | 5 #ifndef CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ |
6 #define CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ | 6 #define CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "chrome/common/net/gaia/gaia_auth_consumer.h" | 13 #include "chrome/common/net/gaia/gaia_auth_consumer.h" |
14 #include "content/common/net/url_fetcher.h" | 14 #include "content/public/common/url_fetcher_delegate.h" |
15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
16 | 16 |
17 // Authenticate a user against the Google Accounts ClientLogin API | 17 // Authenticate a user against the Google Accounts ClientLogin API |
18 // with various capabilities and return results to a GaiaAuthConsumer. | 18 // with various capabilities and return results to a GaiaAuthConsumer. |
19 // | 19 // |
20 // In the future, we will also issue auth tokens from this class. | 20 // In the future, we will also issue auth tokens from this class. |
21 // This class should be used on a single thread, but it can be whichever thread | 21 // This class should be used on a single thread, but it can be whichever thread |
22 // that you like. | 22 // that you like. |
23 // | 23 // |
24 // This class can handle one request at a time. To parallelize requests, | 24 // This class can handle one request at a time. To parallelize requests, |
25 // create multiple GaiaAuthFetcher's. | 25 // create multiple GaiaAuthFetcher's. |
26 | 26 |
27 class GaiaAuthFetcherTest; | 27 class GaiaAuthFetcherTest; |
28 | 28 |
29 class GaiaAuthFetcher : public URLFetcher::Delegate { | 29 namespace net { |
| 30 class URLRequestContextGetter; |
| 31 class URLRequestStatus; |
| 32 } |
| 33 |
| 34 class GaiaAuthFetcher : public content::URLFetcherDelegate { |
30 public: | 35 public: |
31 enum HostedAccountsSetting { | 36 enum HostedAccountsSetting { |
32 HostedAccountsAllowed, | 37 HostedAccountsAllowed, |
33 HostedAccountsNotAllowed | 38 HostedAccountsNotAllowed |
34 }; | 39 }; |
35 | 40 |
36 // Magic string indicating that, while a second factor is still | 41 // Magic string indicating that, while a second factor is still |
37 // needed to complete authentication, the user provided the right password. | 42 // needed to complete authentication, the user provided the right password. |
38 static const char kSecondFactor[]; | 43 static const char kSecondFactor[]; |
39 | 44 |
(...skipping 29 matching lines...) Expand all Loading... |
69 const std::string& info_key); | 74 const std::string& info_key); |
70 | 75 |
71 // Start a TokenAuth request to pre-login the user with the given credentials. | 76 // Start a TokenAuth request to pre-login the user with the given credentials. |
72 void StartTokenAuth(const std::string& auth_token); | 77 void StartTokenAuth(const std::string& auth_token); |
73 | 78 |
74 // Start a MergeSession request to pre-login the user with the given | 79 // Start a MergeSession request to pre-login the user with the given |
75 // credentials. Unlike TokenAuth above, MergeSession will not sign out any | 80 // credentials. Unlike TokenAuth above, MergeSession will not sign out any |
76 // existing accounts. | 81 // existing accounts. |
77 void StartMergeSession(const std::string& auth_token); | 82 void StartMergeSession(const std::string& auth_token); |
78 | 83 |
79 // Implementation of URLFetcher::Delegate | 84 // Implementation of content::URLFetcherDelegate |
80 virtual void OnURLFetchComplete(const URLFetcher* source, | 85 virtual void OnURLFetchComplete(const URLFetcher* source); |
81 const GURL& url, | |
82 const net::URLRequestStatus& status, | |
83 int response_code, | |
84 const net::ResponseCookies& cookies, | |
85 const std::string& data); | |
86 | 86 |
87 // StartClientLogin been called && results not back yet? | 87 // StartClientLogin been called && results not back yet? |
88 bool HasPendingFetch(); | 88 bool HasPendingFetch(); |
89 | 89 |
90 // Stop any URL fetches in progress. | 90 // Stop any URL fetches in progress. |
91 void CancelRequest(); | 91 void CancelRequest(); |
92 | 92 |
93 // From a URLFetcher result, generate an appropriate error. | 93 // From a URLFetcher result, generate an appropriate error. |
94 // From the API documentation, both IssueAuthToken and ClientLogin have | 94 // From the API documentation, both IssueAuthToken and ClientLogin have |
95 // the same error returns. | 95 // the same error returns. |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 // Supply the authentication token returned from StartIssueAuthToken. | 194 // Supply the authentication token returned from StartIssueAuthToken. |
195 static std::string MakeMergeSessionBody(const std::string& auth_token, | 195 static std::string MakeMergeSessionBody(const std::string& auth_token, |
196 const std::string& continue_url, | 196 const std::string& continue_url, |
197 const std::string& source); | 197 const std::string& source); |
198 | 198 |
199 // Create a fetcher useable for making any Gaia request. | 199 // Create a fetcher useable for making any Gaia request. |
200 static URLFetcher* CreateGaiaFetcher(net::URLRequestContextGetter* getter, | 200 static URLFetcher* CreateGaiaFetcher(net::URLRequestContextGetter* getter, |
201 const std::string& body, | 201 const std::string& body, |
202 const GURL& gaia_gurl, | 202 const GURL& gaia_gurl, |
203 bool send_cookies, | 203 bool send_cookies, |
204 URLFetcher::Delegate* delegate); | 204 content::URLFetcherDelegate* delegate); |
205 | 205 |
206 // From a URLFetcher result, generate an appropriate error. | 206 // From a URLFetcher result, generate an appropriate error. |
207 // From the API documentation, both IssueAuthToken and ClientLogin have | 207 // From the API documentation, both IssueAuthToken and ClientLogin have |
208 // the same error returns. | 208 // the same error returns. |
209 static GoogleServiceAuthError GenerateAuthError( | 209 static GoogleServiceAuthError GenerateAuthError( |
210 const std::string& data, | 210 const std::string& data, |
211 const net::URLRequestStatus& status); | 211 const net::URLRequestStatus& status); |
212 | 212 |
213 // These fields are common to GaiaAuthFetcher, same every request | 213 // These fields are common to GaiaAuthFetcher, same every request |
214 GaiaAuthConsumer* const consumer_; | 214 GaiaAuthConsumer* const consumer_; |
(...skipping 20 matching lines...) Expand all Loading... |
235 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, IncomprehensibleError); | 235 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, IncomprehensibleError); |
236 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ServiceUnavailableError); | 236 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ServiceUnavailableError); |
237 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckNormalErrorCode); | 237 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckNormalErrorCode); |
238 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckTwoFactorResponse); | 238 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckTwoFactorResponse); |
239 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, LoginNetFailure); | 239 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, LoginNetFailure); |
240 | 240 |
241 DISALLOW_COPY_AND_ASSIGN(GaiaAuthFetcher); | 241 DISALLOW_COPY_AND_ASSIGN(GaiaAuthFetcher); |
242 }; | 242 }; |
243 | 243 |
244 #endif // CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ | 244 #endif // CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ |
OLD | NEW |