Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(850)

Side by Side Diff: chrome/browser/sync/engine/auth_watcher.cc

Issue 251080: Sync: Remove pthreads from event_sys code. Remove asynch version of GaiaAuthe... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/engine/auth_watcher.h ('k') | chrome/browser/sync/engine/authenticator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-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 #include "chrome/browser/sync/engine/auth_watcher.h" 5 #include "chrome/browser/sync/engine/auth_watcher.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/sync/engine/all_status.h" 9 #include "chrome/browser/sync/engine/all_status.h"
10 #include "chrome/browser/sync/engine/authenticator.h" 10 #include "chrome/browser/sync/engine/authenticator.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 ServiceUnavailable == results.auth_error; 229 ServiceUnavailable == results.auth_error;
230 if (unavailable) 230 if (unavailable)
231 return; 231 return;
232 } 232 }
233 AuthWatcherEvent myevent = { AuthWatcherEvent::GAIA_AUTH_FAILED, &results }; 233 AuthWatcherEvent myevent = { AuthWatcherEvent::GAIA_AUTH_FAILED, &results };
234 NotifyListeners(&myevent); 234 NotifyListeners(&myevent);
235 } 235 }
236 236
237 void* AuthWatcher::AuthenticationThreadMain(ThreadParams* args) { 237 void* AuthWatcher::AuthenticationThreadMain(ThreadParams* args) {
238 NameCurrentThreadForDebugging("SyncEngine_AuthWatcherThread"); 238 NameCurrentThreadForDebugging("SyncEngine_AuthWatcherThread");
239 // TODO(timsteele): Remove this; this is temporary to satisfy code that
240 // compares MessageLoop pointers until AuthWatcher uses a base::Thread.
241 // We allocate a message_loop from the AuthWatcherThread so that
242 // GaiaAuth and EventChannel get a valid opaque pointer to the current
243 // message loop used for comparison. It gets stored in TLS as the 'current'
244 // loop for this thread.
245 MessageLoop message_loop;
239 { 246 {
240 // This short lock ensures our launching function (StartNewAuthAttempt) is 247 // This short lock ensures our launching function (StartNewAuthAttempt) is
241 // done. 248 // done.
242 MutexLock lock(&mutex_); 249 MutexLock lock(&mutex_);
243 current_attempt_trigger_ = args->trigger; 250 current_attempt_trigger_ = args->trigger;
244 } 251 }
245 SaveCredentials save = args->persist_creds_to_disk ? 252 SaveCredentials save = args->persist_creds_to_disk ?
246 PERSIST_TO_DISK : SAVE_IN_MEMORY_ONLY; 253 PERSIST_TO_DISK : SAVE_IN_MEMORY_ONLY;
247 int attempt = 0; 254 int attempt = 0;
248 SignIn const signin = user_settings_-> 255 SignIn const signin = user_settings_->
249 RecallSigninType(args->email, GMAIL_SIGNIN); 256 RecallSigninType(args->email, GMAIL_SIGNIN);
250 257
251 if (!args->password.empty()) while (true) { 258 gaia_->set_message_loop(&message_loop);
252 bool authenticated; 259
253 if (!args->captcha_token.empty() && !args->captcha_value.empty()) 260 if (!args->password.empty()) {
254 authenticated = gaia_->Authenticate(args->email, args->password, 261 // TODO(timsteele): Split this mess up into functions.
255 save, true, args->captcha_token, 262 while (true) {
256 args->captcha_value, signin); 263 bool authenticated;
257 else 264 if (!args->captcha_token.empty() && !args->captcha_value.empty()) {
258 authenticated = gaia_->Authenticate(args->email, args->password, 265 authenticated = gaia_->Authenticate(args->email, args->password,
259 save, true, signin); 266 save, args->captcha_token,
260 if (authenticated) { 267 args->captcha_value, signin);
261 if (!ProcessGaiaAuthSuccess()) { 268 } else {
262 if (3 != ++attempt) 269 authenticated = gaia_->Authenticate(args->email, args->password,
263 continue; 270 save, signin);
264 AuthWatcherEvent event =
265 { AuthWatcherEvent::SERVICE_CONNECTION_FAILED, 0 };
266 NotifyListeners(&event);
267 } 271 }
268 } else { 272 if (authenticated) {
269 ProcessGaiaAuthFailure(); 273 if (!ProcessGaiaAuthSuccess()) {
274 if (3 != ++attempt) {
275 continue;
276 }
277 AuthWatcherEvent event =
278 { AuthWatcherEvent::SERVICE_CONNECTION_FAILED, 0 };
279 NotifyListeners(&event);
280 }
281 } else {
282 ProcessGaiaAuthFailure();
283 }
284 break; // We are done trying to authenticate.
270 } 285 }
271 break;
272 } else if (!args->auth_token.empty()) { 286 } else if (!args->auth_token.empty()) {
273 AuthenticateWithToken(args->email, args->auth_token); 287 AuthenticateWithToken(args->email, args->auth_token);
274 } else { 288 } else {
275 LOG(ERROR) << "Attempt to authenticate with no credentials."; 289 LOG(ERROR) << "Attempt to authenticate with no credentials.";
276 } 290 }
291
292 // We're done trying to authenticate. Set state and terminate the thread.
277 { 293 {
278 MutexLock lock(&mutex_); 294 MutexLock lock(&mutex_);
279 authenticating_now_ = false; 295 authenticating_now_ = false;
280 } 296 }
297 // TODO(timsteele): Remove this; nothing ever gets posted to this loop.
298 gaia_->set_message_loop(NULL);
281 delete args; 299 delete args;
282 return 0; 300 return 0;
283 } 301 }
284 302
285 void AuthWatcher::Reset() { 303 void AuthWatcher::Reset() {
286 status_ = NOT_AUTHENTICATED; 304 status_ = NOT_AUTHENTICATED;
287 } 305 }
288 306
289 void AuthWatcher::NotifyAuthSucceeded(const string& email) { 307 void AuthWatcher::NotifyAuthSucceeded(const string& email) {
290 LOG(INFO) << "NotifyAuthSucceeded"; 308 LOG(INFO) << "NotifyAuthSucceeded";
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 string AuthWatcher::email() const { 428 string AuthWatcher::email() const {
411 return gaia_->email(); 429 return gaia_->email();
412 } 430 }
413 431
414 void AuthWatcher::NotifyListeners(AuthWatcherEvent* event) { 432 void AuthWatcher::NotifyListeners(AuthWatcherEvent* event) {
415 event->trigger = current_attempt_trigger_; 433 event->trigger = current_attempt_trigger_;
416 channel_->NotifyListeners(*event); 434 channel_->NotifyListeners(*event);
417 } 435 }
418 436
419 } // namespace browser_sync 437 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/auth_watcher.h ('k') | chrome/browser/sync/engine/authenticator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698