| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // Use this class to authenticate users with Gaia and access cookies sent | 5 // Use this class to authenticate users with Gaia and access cookies sent |
| 6 // by the Gaia servers. This class lives on the SyncEngine_AuthWatcherThread. | 6 // by the Gaia servers. This class lives on the SyncEngine_AuthWatcherThread. |
| 7 // | 7 // |
| 8 // Sample usage: | 8 // Sample usage: |
| 9 // GaiaAuthenticator gaia_auth("User-Agent", SYNC_SERVICE_NAME, | 9 // GaiaAuthenticator gaia_auth("User-Agent", SYNC_SERVICE_NAME, |
| 10 // browser_sync::kExternalGaiaUrl); | 10 // browser_sync::kExternalGaiaUrl); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // to choose the server to authenticate with (e.g. | 98 // to choose the server to authenticate with (e.g. |
| 99 // http://www.google.com/accounts/ClientLogin). | 99 // http://www.google.com/accounts/ClientLogin). |
| 100 GaiaAuthenticator(const std::string& user_agent, | 100 GaiaAuthenticator(const std::string& user_agent, |
| 101 const std::string& service_id, | 101 const std::string& service_id, |
| 102 const std::string& gaia_url); | 102 const std::string& gaia_url); |
| 103 | 103 |
| 104 virtual ~GaiaAuthenticator(); | 104 virtual ~GaiaAuthenticator(); |
| 105 | 105 |
| 106 // This object should only be invoked from the AuthWatcherThread message | 106 // This object should only be invoked from the AuthWatcherThread message |
| 107 // loop, which is injected here. | 107 // loop, which is injected here. |
| 108 void set_message_loop(MessageLoop* loop) { | 108 void set_message_loop(const MessageLoop* loop) { |
| 109 message_loop_ = loop; | 109 message_loop_ = loop; |
| 110 } | 110 } |
| 111 | 111 |
| 112 // Pass credentials to authenticate with, or use saved credentials via an | 112 // Pass credentials to authenticate with, or use saved credentials via an |
| 113 // overload. If authentication succeeds, you can retrieve the authentication | 113 // overload. If authentication succeeds, you can retrieve the authentication |
| 114 // token via the respective accessors. Returns a boolean indicating whether | 114 // token via the respective accessors. Returns a boolean indicating whether |
| 115 // authentication succeeded or not. | 115 // authentication succeeded or not. |
| 116 bool Authenticate(const std::string& user_name, const std::string& password, | 116 bool Authenticate(const std::string& user_name, const std::string& password, |
| 117 SaveCredentials should_save_credentials, | 117 SaveCredentials should_save_credentials, |
| 118 const std::string& captcha_token, | 118 const std::string& captcha_token, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 AuthParams MakeParams(const std::string& user_name, | 174 AuthParams MakeParams(const std::string& user_name, |
| 175 const std::string& password, | 175 const std::string& password, |
| 176 SaveCredentials should_save_credentials, | 176 SaveCredentials should_save_credentials, |
| 177 const std::string& captcha_token, | 177 const std::string& captcha_token, |
| 178 const std::string& captcha_value, | 178 const std::string& captcha_value, |
| 179 SignIn try_first); | 179 SignIn try_first); |
| 180 | 180 |
| 181 // The real Authenticate implementations. | 181 // The real Authenticate implementations. |
| 182 bool AuthenticateImpl(const AuthParams& params); | 182 bool AuthenticateImpl(const AuthParams& params); |
| 183 bool AuthenticateImpl(const AuthParams& params, AuthResults* results); | 183 bool AuthenticateImpl(const AuthParams& params, AuthResults* results); |
| 184 bool PerformGaiaRequest(const AuthParams& params, AuthResults* results); | |
| 185 | 184 |
| 186 // virtual for testing purposes. | 185 // virtual for testing purposes. |
| 186 virtual bool PerformGaiaRequest(const AuthParams& params, |
| 187 AuthResults* results); |
| 187 virtual bool Post(const GURL& url, const std::string& post_body, | 188 virtual bool Post(const GURL& url, const std::string& post_body, |
| 188 unsigned long* response_code, std::string* response_body) { | 189 unsigned long* response_code, std::string* response_body) { |
| 189 return false; | 190 return false; |
| 190 } | 191 } |
| 191 | 192 |
| 192 // Caller should fill in results->LSID before calling. Result in | 193 // Caller should fill in results->LSID before calling. Result in |
| 193 // results->primary_email. | 194 // results->primary_email. |
| 194 bool LookupEmail(AuthResults* results); | 195 virtual bool LookupEmail(AuthResults* results); |
| 195 | 196 |
| 196 public: | 197 public: |
| 197 // Retrieve email. | 198 // Retrieve email. |
| 198 inline std::string email() const { | 199 inline std::string email() const { |
| 199 DCHECK_EQ(MessageLoop::current(), message_loop_); | 200 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 200 return auth_results_.email; | 201 return auth_results_.email; |
| 201 } | 202 } |
| 202 | 203 |
| 203 // Retrieve password. | 204 // Retrieve password. |
| 204 inline std::string password() const { | 205 inline std::string password() const { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 | 282 |
| 282 Channel* channel_; | 283 Channel* channel_; |
| 283 | 284 |
| 284 // Used to compute backoff time for next allowed authentication. | 285 // Used to compute backoff time for next allowed authentication. |
| 285 int delay_; // In seconds. | 286 int delay_; // In seconds. |
| 286 time_t next_allowed_auth_attempt_time_; | 287 time_t next_allowed_auth_attempt_time_; |
| 287 int early_auth_attempt_count_; | 288 int early_auth_attempt_count_; |
| 288 | 289 |
| 289 // The message loop all our methods are invoked on. Generally this is the | 290 // The message loop all our methods are invoked on. Generally this is the |
| 290 // SyncEngine_AuthWatcherThread's message loop. | 291 // SyncEngine_AuthWatcherThread's message loop. |
| 291 MessageLoop* message_loop_; | 292 const MessageLoop* message_loop_; |
| 292 }; | 293 }; |
| 293 | 294 |
| 294 } // namespace browser_sync | 295 } // namespace browser_sync |
| 295 | 296 |
| 296 #endif // CHROME_BROWSER_SYNC_ENGINE_NET_GAIA_AUTHENTICATOR_H_ | 297 #endif // CHROME_BROWSER_SYNC_ENGINE_NET_GAIA_AUTHENTICATOR_H_ |
| OLD | NEW |