diff options
Diffstat (limited to 'chrome/browser/sync/profile_sync_service.cc')
-rw-r--r-- | chrome/browser/sync/profile_sync_service.cc | 93 |
1 files changed, 40 insertions, 53 deletions
diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc index d6a4d8d..65ffb22 100644 --- a/chrome/browser/sync/profile_sync_service.cc +++ b/chrome/browser/sync/profile_sync_service.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -24,8 +24,10 @@ #include "chrome/browser/about_flags.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/net/chrome_cookie_notification_details.h" -#include "chrome/browser/net/gaia/token_service.h" + #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/signin/signin_manager.h" +#include "chrome/browser/signin/token_service.h" #include "chrome/browser/sync/api/sync_error.h" #include "chrome/browser/sync/backend_migrator.h" #include "chrome/browser/sync/glue/change_processor.h" @@ -39,7 +41,6 @@ #include "chrome/browser/sync/js/js_arg_list.h" #include "chrome/browser/sync/js/js_event_details.h" #include "chrome/browser/sync/profile_sync_components_factory.h" -#include "chrome/browser/sync/signin_manager.h" #include "chrome/browser/sync/sync_global_error.h" #include "chrome/browser/sync/util/cryptographer.h" #include "chrome/browser/sync/util/oauth.h" @@ -192,8 +193,6 @@ void ProfileSyncService::Initialize() { if (!HasSyncSetupCompleted()) DisableForUser(); // Clean up in case of previous crash / setup abort. - signin_->Initialize(profile_); - TryStart(); } @@ -224,6 +223,9 @@ void ProfileSyncService::RegisterAuthNotifications() { registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, content::Source<Profile>(profile_)); + registrar_.Add(this, + chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, + content::Source<Profile>(profile_)); } void ProfileSyncService::RegisterDataTypeController( @@ -434,7 +436,6 @@ void ProfileSyncService::Shutdown(bool sync_disabled) { encrypt_everything_ = false; encrypted_types_ = browser_sync::Cryptographer::SensitiveTypes(); passphrase_required_reason_ = sync_api::REASON_PASSPHRASE_NOT_REQUIRED; - last_attempted_user_email_.clear(); last_auth_error_ = GoogleServiceAuthError::None(); if (sync_global_error_.get()) { @@ -463,7 +464,11 @@ void ProfileSyncService::DisableForUser() { ClearUnrecoverableError(); Shutdown(true); - signin_->SignOut(); + // TODO(atwilson): Don't call SignOut() on *any* platform - move this into + // the UI layer if needed (sync activity should never result in the user + // being logged out of all chrome services). + if (!auto_start_enabled_) + signin_->SignOut(); NotifyObservers(); } @@ -706,7 +711,6 @@ void ProfileSyncService::UpdateAuthErrorState( auth_start_time_ = base::TimeTicks(); } - is_auth_in_progress_ = false; // Fan the notification out to interested UI-thread components. NotifyObservers(); } @@ -1033,6 +1037,17 @@ bool ProfileSyncService::UIShouldDepictAuthInProgress() const { return is_auth_in_progress_; } +void ProfileSyncService::SetUIShouldDepictAuthInProgress( + bool auth_in_progress) { + is_auth_in_progress_ = auth_in_progress; + // TODO(atwilson): Figure out if we still need to track this or if we should + // move this up to the UI (or break it out into two stats that track GAIA + // auth and sync auth separately). + if (is_auth_in_progress_) + auth_start_time_ = base::TimeTicks::Now(); + NotifyObservers(); +} + bool ProfileSyncService::IsPassphraseRequired() const { return passphrase_required_reason_ != sync_api::REASON_PASSPHRASE_NOT_REQUIRED; @@ -1059,41 +1074,6 @@ string16 ProfileSyncService::GetLastSyncedTimeString() const { return TimeFormat::TimeElapsed(last_synced); } -void ProfileSyncService::OnUserSubmittedAuth( - const std::string& username, const std::string& password, - const std::string& captcha, const std::string& access_code) { - last_attempted_user_email_ = username; - is_auth_in_progress_ = true; - NotifyObservers(); - - auth_start_time_ = base::TimeTicks::Now(); - - if (!access_code.empty()) { - signin_->ProvideSecondFactorAccessCode(access_code); - return; - } - - // The user has submitted credentials, which indicates they don't - // want to suppress start up anymore. - sync_prefs_.SetStartSuppressed(false); - - signin_->StartSignIn(username, - password, - last_auth_error_.captcha().token, - captcha); -} - -void ProfileSyncService::OnUserSubmittedOAuth( - const std::string& oauth1_request_token) { - is_auth_in_progress_ = true; - - // The user has submitted credentials, which indicates they don't - // want to suppress start up anymore. - sync_prefs_.SetStartSuppressed(false); - - signin_->StartOAuthSignIn(oauth1_request_token); -} - void ProfileSyncService::OnUserChoseDatatypes(bool sync_everything, syncable::ModelTypeSet chosen_types) { if (!backend_.get() && @@ -1121,16 +1101,6 @@ void ProfileSyncService::OnUserCancelledDialog() { // allow them to cancel out. encryption_pending_ = false; - // Though an auth could still be in progress, once the dialog is closed we - // don't want the UI to stay stuck in the "waiting for authentication" state - // as that could take forever. We set this to false so the buttons to re- - // login will appear until either a) the original request finishes and - // succeeds, calling OnAuthError(NONE), or b) the user clicks the button, - // and tries to re-authenticate. (b) is a little awkward as this second - // request will get queued behind the first and could wind up "undoing" the - // good if invalid creds were provided, but it's an edge case and the user - // can of course get themselves out of it. - is_auth_in_progress_ = false; NotifyObservers(); } @@ -1414,6 +1384,23 @@ void ProfileSyncService::Observe(int type, UpdateAuthErrorState(error); break; } + case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { + const GoogleServiceSigninSuccessDetails* successful = + content::Details<const GoogleServiceSigninSuccessDetails>( + details).ptr(); + // The user has submitted credentials, which indicates they don't + // want to suppress start up anymore. + sync_prefs_.SetStartSuppressed(false); + + // We pass 'false' to SetPassphrase to denote that this is an implicit + // request and shouldn't override an explicit one. Thus, we either + // update the implicit passphrase (idempotent if the passphrase didn't + // actually change), or the user has an explicit passphrase set so this + // becomes a no-op. + if (!successful->password.empty()) + SetPassphrase(successful->password, false); + break; + } case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { const TokenService::TokenRequestFailedDetails& token_details = *(content::Details<const TokenService::TokenRequestFailedDetails>( |