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 #include "chrome/common/net/gaia/gaia_authenticator.h" | 5 #include "chrome/common/net/gaia/gaia_authenticator.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/port.h" | 12 #include "base/port.h" |
13 #include "base/string_split.h" | 13 #include "base/string_split.h" |
14 #include "chrome/common/deprecated/event_sys-inl.h" | |
15 #include "chrome/common/net/http_return.h" | 14 #include "chrome/common/net/http_return.h" |
16 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
17 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
18 | 17 |
19 using std::pair; | 18 using std::pair; |
20 using std::string; | 19 using std::string; |
21 using std::vector; | 20 using std::vector; |
22 | 21 |
23 namespace gaia { | 22 namespace gaia { |
24 | 23 |
(...skipping 15 matching lines...) Expand all Loading... |
40 const string& service_id, | 39 const string& service_id, |
41 const string& gaia_url) | 40 const string& gaia_url) |
42 : user_agent_(user_agent), | 41 : user_agent_(user_agent), |
43 service_id_(service_id), | 42 service_id_(service_id), |
44 gaia_url_(gaia_url), | 43 gaia_url_(gaia_url), |
45 request_count_(0), | 44 request_count_(0), |
46 delay_(0), | 45 delay_(0), |
47 next_allowed_auth_attempt_time_(0), | 46 next_allowed_auth_attempt_time_(0), |
48 early_auth_attempt_count_(0), | 47 early_auth_attempt_count_(0), |
49 message_loop_(NULL) { | 48 message_loop_(NULL) { |
50 GaiaAuthEvent done = { GaiaAuthEvent::GAIA_AUTHENTICATOR_DESTROYED, None, | |
51 this }; | |
52 channel_ = new Channel(done); | |
53 } | 49 } |
54 | 50 |
55 GaiaAuthenticator::~GaiaAuthenticator() { | 51 GaiaAuthenticator::~GaiaAuthenticator() { |
56 delete channel_; | |
57 } | 52 } |
58 | 53 |
59 // mutex_ must be entered before calling this function. | 54 // mutex_ must be entered before calling this function. |
60 GaiaAuthenticator::AuthParams GaiaAuthenticator::MakeParams( | 55 GaiaAuthenticator::AuthParams GaiaAuthenticator::MakeParams( |
61 const string& user_name, | 56 const string& user_name, |
62 const string& password, | 57 const string& password, |
63 const string& captcha_token, | 58 const string& captcha_token, |
64 const string& captcha_value) { | 59 const string& captcha_value) { |
65 AuthParams params; | 60 AuthParams params; |
66 params.request_id = ++request_count_; | 61 params.request_id = ++request_count_; |
(...skipping 24 matching lines...) Expand all Loading... |
91 auth_results_.email = auth_results_.primary_email; | 86 auth_results_.email = auth_results_.primary_email; |
92 return IssueAuthToken(&auth_results_, service_id_); | 87 return IssueAuthToken(&auth_results_, service_id_); |
93 } | 88 } |
94 return false; | 89 return false; |
95 } | 90 } |
96 | 91 |
97 bool GaiaAuthenticator::AuthenticateImpl(const AuthParams& params) { | 92 bool GaiaAuthenticator::AuthenticateImpl(const AuthParams& params) { |
98 DCHECK_EQ(MessageLoop::current(), message_loop_); | 93 DCHECK_EQ(MessageLoop::current(), message_loop_); |
99 AuthResults results; | 94 AuthResults results; |
100 const bool succeeded = AuthenticateImpl(params, &results); | 95 const bool succeeded = AuthenticateImpl(params, &results); |
101 if (params.request_id == request_count_) { | |
102 auth_results_ = results; | |
103 GaiaAuthEvent event = { succeeded ? GaiaAuthEvent::GAIA_AUTH_SUCCEEDED | |
104 : GaiaAuthEvent::GAIA_AUTH_FAILED, | |
105 results.auth_error, this }; | |
106 channel_->NotifyListeners(event); | |
107 } | |
108 return succeeded; | 96 return succeeded; |
109 } | 97 } |
110 | 98 |
111 // This method makes an HTTP request to the Gaia server, and calls other | 99 // This method makes an HTTP request to the Gaia server, and calls other |
112 // methods to help parse the response. If authentication succeeded, then | 100 // methods to help parse the response. If authentication succeeded, then |
113 // Gaia-issued cookies are available in the respective variables; if | 101 // Gaia-issued cookies are available in the respective variables; if |
114 // authentication failed, then the exact error is available as an enum. If the | 102 // authentication failed, then the exact error is available as an enum. If the |
115 // client wishes to save the credentials, the last parameter must be true. | 103 // client wishes to save the credentials, the last parameter must be true. |
116 // If a subsequent request is made with fresh credentials, the saved credentials | 104 // If a subsequent request is made with fresh credentials, the saved credentials |
117 // are wiped out; any subsequent request to the zero-parameter overload of this | 105 // are wiped out; any subsequent request to the zero-parameter overload of this |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 | 377 |
390 bool GaiaAuthenticator::Authenticate(const string& user_name, | 378 bool GaiaAuthenticator::Authenticate(const string& user_name, |
391 const string& password) { | 379 const string& password) { |
392 DCHECK_EQ(MessageLoop::current(), message_loop_); | 380 DCHECK_EQ(MessageLoop::current(), message_loop_); |
393 const string empty; | 381 const string empty; |
394 return Authenticate(user_name, password, empty, | 382 return Authenticate(user_name, password, empty, |
395 empty); | 383 empty); |
396 } | 384 } |
397 | 385 |
398 } // namespace gaia | 386 } // namespace gaia |
OLD | NEW |