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

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

Issue 389017: Implement the gaia captcha state and unlock capability in the sync setup wiza... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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/syncapi.h ('k') | chrome/browser/sync/glue/sync_backend_host.h » ('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/syncapi.h" 5 #include "chrome/browser/sync/engine/syncapi.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <windows.h> 10 #include <windows.h>
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 // 3. Tell the ServerConnectionManager to pass the newly received GAIA auth 699 // 3. Tell the ServerConnectionManager to pass the newly received GAIA auth
700 // token to a sync server to obtain a sync token. 700 // token to a sync server to obtain a sync token.
701 // 4. On receipt of this token, the ServerConnectionManager broadcasts 701 // 4. On receipt of this token, the ServerConnectionManager broadcasts
702 // a server-reachable event, which will unblock the SyncerThread, 702 // a server-reachable event, which will unblock the SyncerThread,
703 // and the rest is the future. 703 // and the rest is the future.
704 // 704 //
705 // If authentication fails, an event will be broadcast all the way up to 705 // If authentication fails, an event will be broadcast all the way up to
706 // the SyncManager::Observer. It may, in turn, decide to try again with new 706 // the SyncManager::Observer. It may, in turn, decide to try again with new
707 // credentials. Calling this method again is the appropriate course of action 707 // credentials. Calling this method again is the appropriate course of action
708 // to "retry". 708 // to "retry".
709 void Authenticate(const std::string& username, const std::string& password); 709 void Authenticate(const std::string& username, const std::string& password,
710 const std::string& captcha);
710 711
711 // Call periodically from a database-safe thread to persist recent changes 712 // Call periodically from a database-safe thread to persist recent changes
712 // to the syncapi model. 713 // to the syncapi model.
713 void SaveChanges(); 714 void SaveChanges();
714 715
715 // This listener is called upon completion of a syncable transaction, and 716 // This listener is called upon completion of a syncable transaction, and
716 // builds the list of sync-engine initiated changes that will be forwarded to 717 // builds the list of sync-engine initiated changes that will be forwarded to
717 // the SyncManager's Observers. 718 // the SyncManager's Observers.
718 void HandleChangeEvent(const syncable::DirectoryChangeEvent& event); 719 void HandleChangeEvent(const syncable::DirectoryChangeEvent& event);
719 void HandleTransactionCompleteChangeEvent( 720 void HandleTransactionCompleteChangeEvent(
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 gaia_service_id, 928 gaia_service_id,
928 gaia_source, 929 gaia_source,
929 use_ssl, 930 use_ssl,
930 post_factory, 931 post_factory,
931 auth_post_factory, 932 auth_post_factory,
932 model_safe_worker, 933 model_safe_worker,
933 attempt_last_user_authentication, 934 attempt_last_user_authentication,
934 user_agent); 935 user_agent);
935 } 936 }
936 937
937 void SyncManager::Authenticate(const char* username, const char* password) { 938 void SyncManager::Authenticate(const char* username, const char* password,
938 data_->Authenticate(std::string(username), std::string(password)); 939 const char* captcha) {
940 data_->Authenticate(std::string(username), std::string(password),
941 std::string(captcha));
939 } 942 }
940 943
941 const std::string& SyncManager::GetAuthenticatedUsername() { 944 const std::string& SyncManager::GetAuthenticatedUsername() {
942 DCHECK(data_); 945 DCHECK(data_);
943 return data_->username_for_share(); 946 return data_->username_for_share();
944 } 947 }
945 948
946 bool SyncManager::SyncInternal::Init( 949 bool SyncManager::SyncInternal::Init(
947 const FilePath& database_location, 950 const FilePath& database_location,
948 const std::string& sync_server_and_path, 951 const std::string& sync_server_and_path,
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 return; 1054 return;
1052 initialized_ = true; 1055 initialized_ = true;
1053 } 1056 }
1054 1057
1055 // Notify that initialization is complete. 1058 // Notify that initialization is complete.
1056 if (observer_) 1059 if (observer_)
1057 observer_->OnInitializationComplete(); 1060 observer_->OnInitializationComplete();
1058 } 1061 }
1059 1062
1060 void SyncManager::SyncInternal::Authenticate(const std::string& username, 1063 void SyncManager::SyncInternal::Authenticate(const std::string& username,
1061 const std::string& password) { 1064 const std::string& password,
1065 const std::string& captcha) {
1062 DCHECK(username_for_share().empty() || username == username_for_share()) 1066 DCHECK(username_for_share().empty() || username == username_for_share())
1063 << "Username change from valid username detected"; 1067 << "Username change from valid username detected";
1064 if (allstatus()->status().authenticated) 1068 if (allstatus()->status().authenticated)
1065 return; 1069 return;
1066 if (password.empty()) { 1070 if (password.empty()) {
1067 // TODO(timsteele): Seems like this shouldn't be needed, but auth_watcher 1071 // TODO(timsteele): Seems like this shouldn't be needed, but auth_watcher
1068 // currently drops blank password attempts on the floor and doesn't update 1072 // currently drops blank password attempts on the floor and doesn't update
1069 // state; it only LOGs an error in this case. We want to make sure we set 1073 // state; it only LOGs an error in this case. We want to make sure we set
1070 // our GoogleServiceAuthError state to denote an error. 1074 // our GoogleServiceAuthError state to denote an error.
1071 RaiseAuthNeededEvent(); 1075 RaiseAuthNeededEvent();
1072 } 1076 }
1073 auth_watcher()->Authenticate(username, password, true); 1077 auth_watcher()->Authenticate(username, password, std::string(),
1078 captcha, true);
1074 } 1079 }
1075 1080
1076 void SyncManager::SyncInternal::AuthenticateForLastKnownUser() { 1081 void SyncManager::SyncInternal::AuthenticateForLastKnownUser() {
1077 std::string username; 1082 std::string username;
1078 std::string auth_token; 1083 std::string auth_token;
1079 if (!(auth_watcher()->settings()->GetLastUserAndServiceToken( 1084 if (!(auth_watcher()->settings()->GetLastUserAndServiceToken(
1080 SYNC_SERVICE_NAME, &username, &auth_token))) { 1085 SYNC_SERVICE_NAME, &username, &auth_token))) {
1081 RaiseAuthNeededEvent(); 1086 RaiseAuthNeededEvent();
1082 return; 1087 return;
1083 } 1088 }
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 // Start watching the syncer channel directly here. 1433 // Start watching the syncer channel directly here.
1429 DCHECK(syncer_thread() != NULL); 1434 DCHECK(syncer_thread() != NULL);
1430 syncer_event_.reset(NewEventListenerHookup(syncer_thread()->channel(), 1435 syncer_event_.reset(NewEventListenerHookup(syncer_thread()->channel(),
1431 this, &SyncInternal::HandleSyncerEvent)); 1436 this, &SyncInternal::HandleSyncerEvent));
1432 } 1437 }
1433 return; 1438 return;
1434 // Authentication failures translate to GoogleServiceAuthError events. 1439 // Authentication failures translate to GoogleServiceAuthError events.
1435 case AuthWatcherEvent::GAIA_AUTH_FAILED: // Invalid GAIA credentials. 1440 case AuthWatcherEvent::GAIA_AUTH_FAILED: // Invalid GAIA credentials.
1436 if (event.auth_results->auth_error == browser_sync::CaptchaRequired) { 1441 if (event.auth_results->auth_error == browser_sync::CaptchaRequired) {
1437 auth_problem_ = AuthError::CAPTCHA_REQUIRED; 1442 auth_problem_ = AuthError::CAPTCHA_REQUIRED;
1438 GURL captcha("http://www.google.com/accounts/"); 1443 std::string url_string("http://www.google.com/accounts/");
1439 GURL::Replacements replacer; 1444 url_string += event.auth_results->captcha_url;
1440 replacer.SetPathStr(captcha.path().append( 1445 GURL captcha(url_string);
1441 event.auth_results->captcha_url));
1442 captcha = captcha.ReplaceComponents(replacer);
1443 observer_->OnAuthError(AuthError::FromCaptchaChallenge( 1446 observer_->OnAuthError(AuthError::FromCaptchaChallenge(
1444 event.auth_results->captcha_token, captcha, 1447 event.auth_results->captcha_token, captcha,
1445 GURL(event.auth_results->auth_error_url))); 1448 GURL(event.auth_results->auth_error_url)));
1446 return; 1449 return;
1447 } 1450 }
1448 case AuthWatcherEvent::SERVICE_AUTH_FAILED: // Expired GAIA credentials. 1451 case AuthWatcherEvent::SERVICE_AUTH_FAILED: // Expired GAIA credentials.
1449 auth_problem_ = AuthError::INVALID_GAIA_CREDENTIALS; 1452 auth_problem_ = AuthError::INVALID_GAIA_CREDENTIALS;
1450 break; 1453 break;
1451 case AuthWatcherEvent::SERVICE_USER_NOT_SIGNED_UP: 1454 case AuthWatcherEvent::SERVICE_USER_NOT_SIGNED_UP:
1452 auth_problem_ = AuthError::USER_NOT_SIGNED_UP; 1455 auth_problem_ = AuthError::USER_NOT_SIGNED_UP;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 BaseTransaction::~BaseTransaction() { 1530 BaseTransaction::~BaseTransaction() {
1528 delete lookup_; 1531 delete lookup_;
1529 } 1532 }
1530 1533
1531 UserShare* SyncManager::GetUserShare() const { 1534 UserShare* SyncManager::GetUserShare() const {
1532 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; 1535 DCHECK(data_->initialized()) << "GetUserShare requires initialization!";
1533 return data_->GetUserShare(); 1536 return data_->GetUserShare();
1534 } 1537 }
1535 1538
1536 } // namespace sync_api 1539 } // namespace sync_api
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/syncapi.h ('k') | chrome/browser/sync/glue/sync_backend_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698