| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/profile_sync_service.h" | 5 #include "chrome/browser/sync/profile_sync_service.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 GaiaConstants::kSyncService); | 397 GaiaConstants::kSyncService); |
| 398 return credentials; | 398 return credentials; |
| 399 } | 399 } |
| 400 | 400 |
| 401 void ProfileSyncService::InitializeBackend(bool delete_sync_data_folder) { | 401 void ProfileSyncService::InitializeBackend(bool delete_sync_data_folder) { |
| 402 if (!backend_.get()) { | 402 if (!backend_.get()) { |
| 403 NOTREACHED(); | 403 NOTREACHED(); |
| 404 return; | 404 return; |
| 405 } | 405 } |
| 406 | 406 |
| 407 // TODO(chron): Reimplement invalidate XMPP login / Sync login | |
| 408 // command line switches. Perhaps make it a command | |
| 409 // line in the TokenService itself to pass an arbitrary | |
| 410 // token. | |
| 411 | |
| 412 | |
| 413 syncable::ModelTypeSet types; | 407 syncable::ModelTypeSet types; |
| 414 // If sync setup hasn't finished, we don't want to initialize routing info | 408 // If sync setup hasn't finished, we don't want to initialize routing info |
| 415 // for any data types so that we don't download updates for types that the | 409 // for any data types so that we don't download updates for types that the |
| 416 // user chooses not to sync on the first DownloadUpdatesCommand. | 410 // user chooses not to sync on the first DownloadUpdatesCommand. |
| 417 if (HasSyncSetupCompleted()) { | 411 if (HasSyncSetupCompleted()) { |
| 418 GetPreferredDataTypes(&types); | 412 GetPreferredDataTypes(&types); |
| 419 } | 413 } |
| 420 | 414 |
| 421 SyncCredentials credentials = GetCredentials(); | 415 SyncCredentials credentials = GetCredentials(); |
| 422 | 416 |
| 423 backend_->Initialize(sync_service_url_, | 417 backend_->Initialize(sync_service_url_, |
| 424 types, | 418 types, |
| 425 profile_->GetRequestContext(), | 419 profile_->GetRequestContext(), |
| 426 credentials, | 420 credentials, |
| 427 delete_sync_data_folder, | 421 delete_sync_data_folder, |
| 428 notifier_options_); | 422 notifier_options_); |
| 429 } | 423 } |
| 430 | 424 |
| 431 void ProfileSyncService::CreateBackend() { | 425 void ProfileSyncService::CreateBackend() { |
| 432 backend_.reset( | 426 backend_.reset(new SyncBackendHost(this, profile_)); |
| 433 new SyncBackendHost(this, profile_, profile_->GetPath(), | |
| 434 data_type_controllers_)); | |
| 435 } | 427 } |
| 436 | 428 |
| 437 void ProfileSyncService::StartUp() { | 429 void ProfileSyncService::StartUp() { |
| 438 // Don't start up multiple times. | 430 // Don't start up multiple times. |
| 439 if (backend_.get()) { | 431 if (backend_.get()) { |
| 440 VLOG(1) << "Skipping bringing up backend host."; | 432 VLOG(1) << "Skipping bringing up backend host."; |
| 441 return; | 433 return; |
| 442 } | 434 } |
| 443 | 435 |
| 444 DCHECK(AreCredentialsAvailable()); | 436 DCHECK(AreCredentialsAvailable()); |
| 445 | 437 |
| 446 last_synced_time_ = base::Time::FromInternalValue( | 438 last_synced_time_ = base::Time::FromInternalValue( |
| 447 profile_->GetPrefs()->GetInt64(prefs::kSyncLastSyncedTime)); | 439 profile_->GetPrefs()->GetInt64(prefs::kSyncLastSyncedTime)); |
| 448 | 440 |
| 449 CreateBackend(); | 441 CreateBackend(); |
| 450 | 442 |
| 451 registrar_.Add(this, | |
| 452 NotificationType::SYNC_PASSPHRASE_REQUIRED, | |
| 453 Source<SyncBackendHost>(backend_.get())); | |
| 454 registrar_.Add(this, | |
| 455 NotificationType::SYNC_PASSPHRASE_ACCEPTED, | |
| 456 Source<SyncBackendHost>(backend_.get())); | |
| 457 | |
| 458 // Initialize the backend. Every time we start up a new SyncBackendHost, | 443 // Initialize the backend. Every time we start up a new SyncBackendHost, |
| 459 // we'll want to start from a fresh SyncDB, so delete any old one that might | 444 // we'll want to start from a fresh SyncDB, so delete any old one that might |
| 460 // be there. | 445 // be there. |
| 461 InitializeBackend(!HasSyncSetupCompleted()); | 446 InitializeBackend(!HasSyncSetupCompleted()); |
| 462 } | 447 } |
| 463 | 448 |
| 464 void ProfileSyncService::Shutdown(bool sync_disabled) { | 449 void ProfileSyncService::Shutdown(bool sync_disabled) { |
| 465 // Stop all data type controllers, if needed. | 450 // Stop all data type controllers, if needed. |
| 466 if (data_type_manager_.get()) { | 451 if (data_type_manager_.get()) { |
| 467 if (data_type_manager_->state() != DataTypeManager::STOPPED) { | 452 if (data_type_manager_->state() != DataTypeManager::STOPPED) { |
| 468 data_type_manager_->Stop(); | 453 data_type_manager_->Stop(); |
| 469 } | 454 } |
| 470 | 455 |
| 471 registrar_.Remove(this, | 456 registrar_.Remove(this, |
| 472 NotificationType::SYNC_CONFIGURE_START, | 457 NotificationType::SYNC_CONFIGURE_START, |
| 473 Source<DataTypeManager>(data_type_manager_.get())); | 458 Source<DataTypeManager>(data_type_manager_.get())); |
| 474 registrar_.Remove(this, | 459 registrar_.Remove(this, |
| 475 NotificationType::SYNC_CONFIGURE_DONE, | 460 NotificationType::SYNC_CONFIGURE_DONE, |
| 476 Source<DataTypeManager>(data_type_manager_.get())); | 461 Source<DataTypeManager>(data_type_manager_.get())); |
| 477 data_type_manager_.reset(); | 462 data_type_manager_.reset(); |
| 478 } | 463 } |
| 479 | 464 |
| 480 // Move aside the backend so nobody else tries to use it while we are | 465 // Move aside the backend so nobody else tries to use it while we are |
| 481 // shutting it down. | 466 // shutting it down. |
| 482 scoped_ptr<SyncBackendHost> doomed_backend(backend_.release()); | 467 scoped_ptr<SyncBackendHost> doomed_backend(backend_.release()); |
| 483 if (doomed_backend.get()) { | 468 if (doomed_backend.get()) { |
| 484 doomed_backend->Shutdown(sync_disabled); | 469 doomed_backend->Shutdown(sync_disabled); |
| 485 | 470 |
| 486 registrar_.Remove(this, | |
| 487 NotificationType::SYNC_PASSPHRASE_REQUIRED, | |
| 488 Source<SyncBackendHost>(doomed_backend.get())); | |
| 489 registrar_.Remove(this, | |
| 490 NotificationType::SYNC_PASSPHRASE_ACCEPTED, | |
| 491 Source<SyncBackendHost>(doomed_backend.get())); | |
| 492 | |
| 493 doomed_backend.reset(); | 471 doomed_backend.reset(); |
| 494 } | 472 } |
| 495 | 473 |
| 496 // Clear various flags. | 474 // Clear various flags. |
| 497 is_auth_in_progress_ = false; | 475 is_auth_in_progress_ = false; |
| 498 backend_initialized_ = false; | 476 backend_initialized_ = false; |
| 499 observed_passphrase_required_ = false; | 477 observed_passphrase_required_ = false; |
| 500 last_attempted_user_email_.clear(); | 478 last_attempted_user_email_.clear(); |
| 501 last_auth_error_ = GoogleServiceAuthError::None(); | 479 last_auth_error_ = GoogleServiceAuthError::None(); |
| 502 } | 480 } |
| 503 | 481 |
| 504 void ProfileSyncService::ClearServerData() { | 482 void ProfileSyncService::ClearServerData() { |
| 505 clear_server_data_state_ = CLEAR_CLEARING; | 483 clear_server_data_state_ = CLEAR_CLEARING; |
| 506 clear_server_data_timer_.Start( | 484 clear_server_data_timer_.Start( |
| 507 base::TimeDelta::FromSeconds(kSyncClearDataTimeoutInSeconds), this, | 485 base::TimeDelta::FromSeconds(kSyncClearDataTimeoutInSeconds), this, |
| 508 &ProfileSyncService::OnClearServerDataTimeout); | 486 &ProfileSyncService::OnClearServerDataTimeout); |
| 509 backend_->RequestClearServerData(); | 487 backend_->RequestClearServerData(); |
| 510 } | 488 } |
| 511 | 489 |
| 512 void ProfileSyncService::DisableForUser() { | 490 void ProfileSyncService::DisableForUser() { |
| 513 // Clear prefs (including SyncSetupHasCompleted) before shutting down so | 491 // Clear prefs (including SyncSetupHasCompleted) before shutting down so |
| 514 // PSS clients don't think we're set up while we're shutting down. | 492 // PSS clients don't think we're set up while we're shutting down. |
| 515 ClearPreferences(); | 493 ClearPreferences(); |
| 516 Shutdown(true); | 494 Shutdown(true); |
| 517 | 495 |
| 518 if (signin_.get()) { | 496 if (signin_.get()) { |
| 519 signin_->SignOut(); | 497 signin_->SignOut(); |
| 520 } | 498 } |
| 521 | 499 |
| 522 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 500 NotifyObservers(); |
| 523 } | 501 } |
| 524 | 502 |
| 525 bool ProfileSyncService::HasSyncSetupCompleted() const { | 503 bool ProfileSyncService::HasSyncSetupCompleted() const { |
| 526 return profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted); | 504 return profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted); |
| 527 } | 505 } |
| 528 | 506 |
| 529 void ProfileSyncService::SetSyncSetupCompleted() { | 507 void ProfileSyncService::SetSyncSetupCompleted() { |
| 530 PrefService* prefs = profile()->GetPrefs(); | 508 PrefService* prefs = profile()->GetPrefs(); |
| 531 prefs->SetBoolean(prefs::kSyncHasSetupCompleted, true); | 509 prefs->SetBoolean(prefs::kSyncHasSetupCompleted, true); |
| 532 prefs->SetBoolean(prefs::kSyncSuppressStart, false); | 510 prefs->SetBoolean(prefs::kSyncSuppressStart, false); |
| 533 | 511 |
| 534 // Indicate that setup has been completed on the new credentials store | 512 // Indicate that setup has been completed on the new credentials store |
| 535 // so that we don't try to migrate. | 513 // so that we don't try to migrate. |
| 536 prefs->SetBoolean(prefs::kSyncCredentialsMigrated, true); | 514 prefs->SetBoolean(prefs::kSyncCredentialsMigrated, true); |
| 537 | 515 |
| 538 prefs->ScheduleSavePersistentPrefs(); | 516 prefs->ScheduleSavePersistentPrefs(); |
| 539 } | 517 } |
| 540 | 518 |
| 541 void ProfileSyncService::UpdateLastSyncedTime() { | 519 void ProfileSyncService::UpdateLastSyncedTime() { |
| 542 last_synced_time_ = base::Time::Now(); | 520 last_synced_time_ = base::Time::Now(); |
| 543 profile_->GetPrefs()->SetInt64(prefs::kSyncLastSyncedTime, | 521 profile_->GetPrefs()->SetInt64(prefs::kSyncLastSyncedTime, |
| 544 last_synced_time_.ToInternalValue()); | 522 last_synced_time_.ToInternalValue()); |
| 545 profile_->GetPrefs()->ScheduleSavePersistentPrefs(); | 523 profile_->GetPrefs()->ScheduleSavePersistentPrefs(); |
| 546 } | 524 } |
| 547 | 525 |
| 526 void ProfileSyncService::NotifyObservers() { |
| 527 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); |
| 528 } |
| 529 |
| 548 // static | 530 // static |
| 549 const char* ProfileSyncService::GetPrefNameForDataType( | 531 const char* ProfileSyncService::GetPrefNameForDataType( |
| 550 syncable::ModelType data_type) { | 532 syncable::ModelType data_type) { |
| 551 switch (data_type) { | 533 switch (data_type) { |
| 552 case syncable::BOOKMARKS: | 534 case syncable::BOOKMARKS: |
| 553 return prefs::kSyncBookmarks; | 535 return prefs::kSyncBookmarks; |
| 554 case syncable::PASSWORDS: | 536 case syncable::PASSWORDS: |
| 555 return prefs::kSyncPasswords; | 537 return prefs::kSyncPasswords; |
| 556 case syncable::PREFERENCES: | 538 case syncable::PREFERENCES: |
| 557 return prefs::kSyncPreferences; | 539 return prefs::kSyncPreferences; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 584 unrecoverable_error_detected_ = true; | 566 unrecoverable_error_detected_ = true; |
| 585 unrecoverable_error_message_ = message; | 567 unrecoverable_error_message_ = message; |
| 586 unrecoverable_error_location_.reset( | 568 unrecoverable_error_location_.reset( |
| 587 new tracked_objects::Location(from_here.function_name(), | 569 new tracked_objects::Location(from_here.function_name(), |
| 588 from_here.file_name(), | 570 from_here.file_name(), |
| 589 from_here.line_number())); | 571 from_here.line_number())); |
| 590 | 572 |
| 591 // Tell the wizard so it can inform the user only if it is already open. | 573 // Tell the wizard so it can inform the user only if it is already open. |
| 592 wizard_.Step(SyncSetupWizard::FATAL_ERROR); | 574 wizard_.Step(SyncSetupWizard::FATAL_ERROR); |
| 593 | 575 |
| 594 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 576 NotifyObservers(); |
| 595 LOG(ERROR) << "Unrecoverable error detected -- ProfileSyncService unusable." | 577 LOG(ERROR) << "Unrecoverable error detected -- ProfileSyncService unusable." |
| 596 << message; | 578 << message; |
| 597 std::string location; | 579 std::string location; |
| 598 from_here.Write(true, true, &location); | 580 from_here.Write(true, true, &location); |
| 599 LOG(ERROR) << location; | 581 LOG(ERROR) << location; |
| 600 | 582 |
| 601 // Shut all data types down. | 583 // Shut all data types down. |
| 602 MessageLoop::current()->PostTask(FROM_HERE, | 584 MessageLoop::current()->PostTask(FROM_HERE, |
| 603 scoped_runnable_method_factory_.NewRunnableMethod( | 585 scoped_runnable_method_factory_.NewRunnableMethod( |
| 604 &ProfileSyncService::Shutdown, true)); | 586 &ProfileSyncService::Shutdown, true)); |
| 605 } | 587 } |
| 606 | 588 |
| 607 void ProfileSyncService::OnBackendInitialized() { | 589 void ProfileSyncService::OnBackendInitialized() { |
| 608 backend_initialized_ = true; | 590 backend_initialized_ = true; |
| 609 | 591 |
| 610 // The very first time the backend initializes is effectively the first time | 592 // The very first time the backend initializes is effectively the first time |
| 611 // we can say we successfully "synced". last_synced_time_ will only be null | 593 // we can say we successfully "synced". last_synced_time_ will only be null |
| 612 // in this case, because the pref wasn't restored on StartUp. | 594 // in this case, because the pref wasn't restored on StartUp. |
| 613 if (last_synced_time_.is_null()) { | 595 if (last_synced_time_.is_null()) { |
| 614 UpdateLastSyncedTime(); | 596 UpdateLastSyncedTime(); |
| 615 } | 597 } |
| 616 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 598 NotifyObservers(); |
| 617 | 599 |
| 618 if (!cros_user_.empty()) { | 600 if (!cros_user_.empty()) { |
| 619 if (profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)) { | 601 if (profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)) { |
| 620 ShowConfigure(NULL); | 602 ShowConfigure(NULL); |
| 621 } else { | 603 } else { |
| 622 SetSyncSetupCompleted(); | 604 SetSyncSetupCompleted(); |
| 623 } | 605 } |
| 624 } | 606 } |
| 625 | 607 |
| 626 if (HasSyncSetupCompleted()) { | 608 if (HasSyncSetupCompleted()) { |
| 627 ConfigureDataTypeManager(); | 609 ConfigureDataTypeManager(); |
| 628 } | 610 } |
| 629 } | 611 } |
| 630 | 612 |
| 631 void ProfileSyncService::OnSyncCycleCompleted() { | 613 void ProfileSyncService::OnSyncCycleCompleted() { |
| 632 UpdateLastSyncedTime(); | 614 UpdateLastSyncedTime(); |
| 633 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 615 NotifyObservers(); |
| 634 } | 616 } |
| 635 | 617 |
| 636 void ProfileSyncService::UpdateAuthErrorState( | 618 void ProfileSyncService::UpdateAuthErrorState( |
| 637 const GoogleServiceAuthError& error) { | 619 const GoogleServiceAuthError& error) { |
| 638 last_auth_error_ = error; | 620 last_auth_error_ = error; |
| 639 // Protect against the in-your-face dialogs that pop out of nowhere. | 621 // Protect against the in-your-face dialogs that pop out of nowhere. |
| 640 // Require the user to click somewhere to run the setup wizard in the case | 622 // Require the user to click somewhere to run the setup wizard in the case |
| 641 // of a steady-state auth failure. | 623 // of a steady-state auth failure. |
| 642 if (WizardIsVisible()) { | 624 if (WizardIsVisible()) { |
| 643 wizard_.Step(AuthError::NONE == last_auth_error_.state() ? | 625 wizard_.Step(AuthError::NONE == last_auth_error_.state() ? |
| 644 SyncSetupWizard::GAIA_SUCCESS : SyncSetupWizard::GAIA_LOGIN); | 626 SyncSetupWizard::GAIA_SUCCESS : SyncSetupWizard::GAIA_LOGIN); |
| 645 } else { | 627 } else { |
| 646 auth_error_time_ = base::TimeTicks::Now(); | 628 auth_error_time_ = base::TimeTicks::Now(); |
| 647 } | 629 } |
| 648 | 630 |
| 649 if (!auth_start_time_.is_null()) { | 631 if (!auth_start_time_.is_null()) { |
| 650 UMA_HISTOGRAM_TIMES("Sync.AuthorizationTimeInNetwork", | 632 UMA_HISTOGRAM_TIMES("Sync.AuthorizationTimeInNetwork", |
| 651 base::TimeTicks::Now() - auth_start_time_); | 633 base::TimeTicks::Now() - auth_start_time_); |
| 652 auth_start_time_ = base::TimeTicks(); | 634 auth_start_time_ = base::TimeTicks(); |
| 653 } | 635 } |
| 654 | 636 |
| 655 is_auth_in_progress_ = false; | 637 is_auth_in_progress_ = false; |
| 656 // Fan the notification out to interested UI-thread components. | 638 // Fan the notification out to interested UI-thread components. |
| 657 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 639 NotifyObservers(); |
| 658 } | 640 } |
| 659 | 641 |
| 660 void ProfileSyncService::OnAuthError() { | 642 void ProfileSyncService::OnAuthError() { |
| 661 UpdateAuthErrorState(backend_->GetAuthError()); | 643 UpdateAuthErrorState(backend_->GetAuthError()); |
| 662 } | 644 } |
| 663 | 645 |
| 664 void ProfileSyncService::OnStopSyncingPermanently() { | 646 void ProfileSyncService::OnStopSyncingPermanently() { |
| 665 if (SetupInProgress()) { | 647 if (SetupInProgress()) { |
| 666 wizard_.Step(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR); | 648 wizard_.Step(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR); |
| 667 expect_sync_configuration_aborted_ = true; | 649 expect_sync_configuration_aborted_ = true; |
| 668 } | 650 } |
| 669 profile_->GetPrefs()->SetBoolean(prefs::kSyncSuppressStart, true); | 651 profile_->GetPrefs()->SetBoolean(prefs::kSyncSuppressStart, true); |
| 670 DisableForUser(); | 652 DisableForUser(); |
| 671 } | 653 } |
| 672 | 654 |
| 673 void ProfileSyncService::OnClearServerDataTimeout() { | 655 void ProfileSyncService::OnClearServerDataTimeout() { |
| 674 if (clear_server_data_state_ != CLEAR_SUCCEEDED && | 656 if (clear_server_data_state_ != CLEAR_SUCCEEDED && |
| 675 clear_server_data_state_ != CLEAR_FAILED) { | 657 clear_server_data_state_ != CLEAR_FAILED) { |
| 676 clear_server_data_state_ = CLEAR_FAILED; | 658 clear_server_data_state_ = CLEAR_FAILED; |
| 677 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 659 NotifyObservers(); |
| 678 } | 660 } |
| 679 } | 661 } |
| 680 | 662 |
| 681 void ProfileSyncService::OnClearServerDataFailed() { | 663 void ProfileSyncService::OnClearServerDataFailed() { |
| 682 clear_server_data_timer_.Stop(); | 664 clear_server_data_timer_.Stop(); |
| 683 | 665 |
| 684 // Only once clear has succeeded there is no longer a need to transition to | 666 // Only once clear has succeeded there is no longer a need to transition to |
| 685 // a failed state as sync is disabled locally. Also, no need to fire off | 667 // a failed state as sync is disabled locally. Also, no need to fire off |
| 686 // the observers if the state didn't change (i.e. it was FAILED before). | 668 // the observers if the state didn't change (i.e. it was FAILED before). |
| 687 if (clear_server_data_state_ != CLEAR_SUCCEEDED && | 669 if (clear_server_data_state_ != CLEAR_SUCCEEDED && |
| 688 clear_server_data_state_ != CLEAR_FAILED) { | 670 clear_server_data_state_ != CLEAR_FAILED) { |
| 689 clear_server_data_state_ = CLEAR_FAILED; | 671 clear_server_data_state_ = CLEAR_FAILED; |
| 690 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 672 NotifyObservers(); |
| 691 } | 673 } |
| 692 } | 674 } |
| 693 | 675 |
| 694 void ProfileSyncService::OnClearServerDataSucceeded() { | 676 void ProfileSyncService::OnClearServerDataSucceeded() { |
| 695 clear_server_data_timer_.Stop(); | 677 clear_server_data_timer_.Stop(); |
| 696 | 678 |
| 697 // Even if the timout fired, we still transition to the succeeded state as | 679 // Even if the timout fired, we still transition to the succeeded state as |
| 698 // we want UI to update itself and no longer allow the user to press "clear" | 680 // we want UI to update itself and no longer allow the user to press "clear" |
| 699 if (clear_server_data_state_ != CLEAR_SUCCEEDED) { | 681 if (clear_server_data_state_ != CLEAR_SUCCEEDED) { |
| 700 clear_server_data_state_ = CLEAR_SUCCEEDED; | 682 clear_server_data_state_ = CLEAR_SUCCEEDED; |
| 701 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 683 NotifyObservers(); |
| 702 } | 684 } |
| 703 } | 685 } |
| 704 | 686 |
| 687 void ProfileSyncService::OnPassphraseRequired(bool for_decryption) { |
| 688 DCHECK(backend_.get()); |
| 689 DCHECK(backend_->IsNigoriEnabled()); |
| 690 observed_passphrase_required_ = true; |
| 691 passphrase_required_for_decryption_ = for_decryption; |
| 692 |
| 693 if (!cached_passphrase_.value.empty()) { |
| 694 SetPassphrase(cached_passphrase_.value, |
| 695 cached_passphrase_.is_explicit, |
| 696 cached_passphrase_.is_creation); |
| 697 cached_passphrase_ = CachedPassphrase(); |
| 698 return; |
| 699 } |
| 700 |
| 701 if (WizardIsVisible()) { |
| 702 wizard_.Step(SyncSetupWizard::ENTER_PASSPHRASE); |
| 703 } |
| 704 |
| 705 NotifyObservers(); |
| 706 } |
| 707 |
| 708 void ProfileSyncService::OnPassphraseAccepted() { |
| 709 // Make sure the data types that depend on the passphrase are started at |
| 710 // this time. |
| 711 syncable::ModelTypeSet types; |
| 712 GetPreferredDataTypes(&types); |
| 713 data_type_manager_->Configure(types); |
| 714 |
| 715 NotifyObservers(); |
| 716 observed_passphrase_required_ = false; |
| 717 tried_setting_explicit_passphrase_ = false; |
| 718 tried_creating_explicit_passphrase_ = false; |
| 719 |
| 720 wizard_.Step(SyncSetupWizard::DONE); |
| 721 } |
| 722 |
| 705 void ProfileSyncService::ShowLoginDialog(gfx::NativeWindow parent_window) { | 723 void ProfileSyncService::ShowLoginDialog(gfx::NativeWindow parent_window) { |
| 706 // TODO(johnnyg): File a bug to make sure this doesn't happen. | 724 // TODO(johnnyg): File a bug to make sure this doesn't happen. |
| 707 if (!cros_user_.empty()) { | 725 if (!cros_user_.empty()) { |
| 708 LOG(WARNING) << "ShowLoginDialog called on Chrome OS."; | 726 LOG(WARNING) << "ShowLoginDialog called on Chrome OS."; |
| 709 return; | 727 return; |
| 710 } | 728 } |
| 711 | 729 |
| 712 if (WizardIsVisible()) { | 730 if (WizardIsVisible()) { |
| 713 wizard_.Focus(); | 731 wizard_.Focus(); |
| 714 return; | 732 return; |
| 715 } | 733 } |
| 716 | 734 |
| 717 if (!auth_error_time_.is_null()) { | 735 if (!auth_error_time_.is_null()) { |
| 718 UMA_HISTOGRAM_LONG_TIMES("Sync.ReauthorizationTime", | 736 UMA_HISTOGRAM_LONG_TIMES("Sync.ReauthorizationTime", |
| 719 base::TimeTicks::Now() - auth_error_time_); | 737 base::TimeTicks::Now() - auth_error_time_); |
| 720 auth_error_time_ = base::TimeTicks(); // Reset auth_error_time_ to null. | 738 auth_error_time_ = base::TimeTicks(); // Reset auth_error_time_ to null. |
| 721 } | 739 } |
| 722 | 740 |
| 723 wizard_.SetParent(parent_window); | 741 wizard_.SetParent(parent_window); |
| 724 wizard_.Step(SyncSetupWizard::GAIA_LOGIN); | 742 wizard_.Step(SyncSetupWizard::GAIA_LOGIN); |
| 725 | 743 |
| 726 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 744 NotifyObservers(); |
| 727 } | 745 } |
| 728 | 746 |
| 729 void ProfileSyncService::ShowConfigure(gfx::NativeWindow parent_window) { | 747 void ProfileSyncService::ShowConfigure(gfx::NativeWindow parent_window) { |
| 730 if (WizardIsVisible()) { | 748 if (WizardIsVisible()) { |
| 731 wizard_.Focus(); | 749 wizard_.Focus(); |
| 732 return; | 750 return; |
| 733 } | 751 } |
| 734 wizard_.SetParent(parent_window); | 752 wizard_.SetParent(parent_window); |
| 735 wizard_.Step(SyncSetupWizard::CONFIGURE); | 753 wizard_.Step(SyncSetupWizard::CONFIGURE); |
| 736 } | 754 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 return backend_->GetAuthenticatedUsername(); | 835 return backend_->GetAuthenticatedUsername(); |
| 818 else | 836 else |
| 819 return string16(); | 837 return string16(); |
| 820 } | 838 } |
| 821 | 839 |
| 822 void ProfileSyncService::OnUserSubmittedAuth( | 840 void ProfileSyncService::OnUserSubmittedAuth( |
| 823 const std::string& username, const std::string& password, | 841 const std::string& username, const std::string& password, |
| 824 const std::string& captcha, const std::string& access_code) { | 842 const std::string& captcha, const std::string& access_code) { |
| 825 last_attempted_user_email_ = username; | 843 last_attempted_user_email_ = username; |
| 826 is_auth_in_progress_ = true; | 844 is_auth_in_progress_ = true; |
| 827 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 845 NotifyObservers(); |
| 828 | 846 |
| 829 auth_start_time_ = base::TimeTicks::Now(); | 847 auth_start_time_ = base::TimeTicks::Now(); |
| 830 | 848 |
| 831 if (!signin_.get()) { | 849 if (!signin_.get()) { |
| 832 // In ChromeOS we sign in during login, so we do not instantiate signin_. | 850 // In ChromeOS we sign in during login, so we do not instantiate signin_. |
| 833 // If this function gets called, we need to re-authenticate (e.g. for | 851 // If this function gets called, we need to re-authenticate (e.g. for |
| 834 // two factor signin), so instantiante signin_ here. | 852 // two factor signin), so instantiante signin_ here. |
| 835 signin_.reset(new SigninManager()); | 853 signin_.reset(new SigninManager()); |
| 836 signin_->Initialize(profile_); | 854 signin_->Initialize(profile_); |
| 837 } | 855 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 // Though an auth could still be in progress, once the dialog is closed we | 900 // Though an auth could still be in progress, once the dialog is closed we |
| 883 // don't want the UI to stay stuck in the "waiting for authentication" state | 901 // don't want the UI to stay stuck in the "waiting for authentication" state |
| 884 // as that could take forever. We set this to false so the buttons to re- | 902 // as that could take forever. We set this to false so the buttons to re- |
| 885 // login will appear until either a) the original request finishes and | 903 // login will appear until either a) the original request finishes and |
| 886 // succeeds, calling OnAuthError(NONE), or b) the user clicks the button, | 904 // succeeds, calling OnAuthError(NONE), or b) the user clicks the button, |
| 887 // and tries to re-authenticate. (b) is a little awkward as this second | 905 // and tries to re-authenticate. (b) is a little awkward as this second |
| 888 // request will get queued behind the first and could wind up "undoing" the | 906 // request will get queued behind the first and could wind up "undoing" the |
| 889 // good if invalid creds were provided, but it's an edge case and the user | 907 // good if invalid creds were provided, but it's an edge case and the user |
| 890 // can of course get themselves out of it. | 908 // can of course get themselves out of it. |
| 891 is_auth_in_progress_ = false; | 909 is_auth_in_progress_ = false; |
| 892 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 910 NotifyObservers(); |
| 893 } | 911 } |
| 894 | 912 |
| 895 void ProfileSyncService::ChangePreferredDataTypes( | 913 void ProfileSyncService::ChangePreferredDataTypes( |
| 896 const syncable::ModelTypeSet& preferred_types) { | 914 const syncable::ModelTypeSet& preferred_types) { |
| 897 | 915 |
| 898 // Filter out any datatypes which aren't registered, or for which | 916 // Filter out any datatypes which aren't registered, or for which |
| 899 // the preference can't be set. | 917 // the preference can't be set. |
| 900 syncable::ModelTypeSet registered_types; | 918 syncable::ModelTypeSet registered_types; |
| 901 GetRegisteredDataTypes(®istered_types); | 919 GetRegisteredDataTypes(®istered_types); |
| 902 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { | 920 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1029 tried_creating_explicit_passphrase_ = true; | 1047 tried_creating_explicit_passphrase_ = true; |
| 1030 else if (is_explicit) | 1048 else if (is_explicit) |
| 1031 tried_setting_explicit_passphrase_ = true; | 1049 tried_setting_explicit_passphrase_ = true; |
| 1032 } | 1050 } |
| 1033 | 1051 |
| 1034 void ProfileSyncService::Observe(NotificationType type, | 1052 void ProfileSyncService::Observe(NotificationType type, |
| 1035 const NotificationSource& source, | 1053 const NotificationSource& source, |
| 1036 const NotificationDetails& details) { | 1054 const NotificationDetails& details) { |
| 1037 switch (type.value) { | 1055 switch (type.value) { |
| 1038 case NotificationType::SYNC_CONFIGURE_START: { | 1056 case NotificationType::SYNC_CONFIGURE_START: { |
| 1039 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 1057 NotifyObservers(); |
| 1040 // TODO(sync): Maybe toast? | 1058 // TODO(sync): Maybe toast? |
| 1041 break; | 1059 break; |
| 1042 } | 1060 } |
| 1043 case NotificationType::SYNC_CONFIGURE_DONE: { | 1061 case NotificationType::SYNC_CONFIGURE_DONE: { |
| 1044 DataTypeManager::ConfigureResult result = | 1062 DataTypeManager::ConfigureResult result = |
| 1045 *(Details<DataTypeManager::ConfigureResult>(details).ptr()); | 1063 *(Details<DataTypeManager::ConfigureResult>(details).ptr()); |
| 1046 if (result == DataTypeManager::ABORTED && | 1064 if (result == DataTypeManager::ABORTED && |
| 1047 expect_sync_configuration_aborted_) { | 1065 expect_sync_configuration_aborted_) { |
| 1048 expect_sync_configuration_aborted_ = false; | 1066 expect_sync_configuration_aborted_ = false; |
| 1049 return; | 1067 return; |
| 1050 } | 1068 } |
| 1051 if (result != DataTypeManager::OK) { | 1069 if (result != DataTypeManager::OK) { |
| 1052 OnUnrecoverableError(FROM_HERE, "Sync Configuration failed."); | 1070 OnUnrecoverableError(FROM_HERE, "Sync Configuration failed."); |
| 1053 return; | 1071 return; |
| 1054 } | 1072 } |
| 1055 | 1073 |
| 1056 if (!cached_passphrase_.value.empty()) { | 1074 if (!cached_passphrase_.value.empty()) { |
| 1057 // Don't hold on to the passphrase in raw form longer than needed. | 1075 // Don't hold on to the passphrase in raw form longer than needed. |
| 1058 SetPassphrase(cached_passphrase_.value, | 1076 SetPassphrase(cached_passphrase_.value, |
| 1059 cached_passphrase_.is_explicit, | 1077 cached_passphrase_.is_explicit, |
| 1060 cached_passphrase_.is_creation); | 1078 cached_passphrase_.is_creation); |
| 1061 cached_passphrase_ = CachedPassphrase(); | 1079 cached_passphrase_ = CachedPassphrase(); |
| 1062 } | 1080 } |
| 1063 | 1081 |
| 1064 // TODO(sync): Less wizard, more toast. | 1082 // TODO(sync): Less wizard, more toast. |
| 1065 if (!observed_passphrase_required_) | 1083 if (!observed_passphrase_required_) |
| 1066 wizard_.Step(SyncSetupWizard::DONE); | 1084 wizard_.Step(SyncSetupWizard::DONE); |
| 1067 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 1085 NotifyObservers(); |
| 1068 | 1086 |
| 1069 break; | 1087 break; |
| 1070 } | 1088 } |
| 1071 case NotificationType::SYNC_PASSPHRASE_REQUIRED: { | |
| 1072 DCHECK(backend_.get()); | |
| 1073 DCHECK(backend_->IsNigoriEnabled()); | |
| 1074 observed_passphrase_required_ = true; | |
| 1075 passphrase_required_for_decryption_ = *(Details<bool>(details).ptr()); | |
| 1076 | |
| 1077 if (!cached_passphrase_.value.empty()) { | |
| 1078 SetPassphrase(cached_passphrase_.value, | |
| 1079 cached_passphrase_.is_explicit, | |
| 1080 cached_passphrase_.is_creation); | |
| 1081 cached_passphrase_ = CachedPassphrase(); | |
| 1082 break; | |
| 1083 } | |
| 1084 | |
| 1085 if (WizardIsVisible()) { | |
| 1086 wizard_.Step(SyncSetupWizard::ENTER_PASSPHRASE); | |
| 1087 } | |
| 1088 | |
| 1089 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | |
| 1090 break; | |
| 1091 } | |
| 1092 case NotificationType::SYNC_DATA_TYPES_UPDATED: { | 1089 case NotificationType::SYNC_DATA_TYPES_UPDATED: { |
| 1093 if (!HasSyncSetupCompleted()) break; | 1090 if (!HasSyncSetupCompleted()) break; |
| 1094 | 1091 |
| 1095 syncable::ModelTypeSet types; | 1092 syncable::ModelTypeSet types; |
| 1096 GetPreferredDataTypes(&types); | 1093 GetPreferredDataTypes(&types); |
| 1097 OnUserChoseDatatypes(false, types); | 1094 OnUserChoseDatatypes(false, types); |
| 1098 break; | 1095 break; |
| 1099 } | 1096 } |
| 1100 case NotificationType::SYNC_PASSPHRASE_ACCEPTED: { | |
| 1101 // Make sure the data types that depend on the passphrase are started at | |
| 1102 // this time. | |
| 1103 syncable::ModelTypeSet types; | |
| 1104 GetPreferredDataTypes(&types); | |
| 1105 data_type_manager_->Configure(types); | |
| 1106 | |
| 1107 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | |
| 1108 observed_passphrase_required_ = false; | |
| 1109 tried_setting_explicit_passphrase_ = false; | |
| 1110 tried_creating_explicit_passphrase_ = false; | |
| 1111 | |
| 1112 wizard_.Step(SyncSetupWizard::DONE); | |
| 1113 break; | |
| 1114 } | |
| 1115 case NotificationType::PREF_CHANGED: { | 1097 case NotificationType::PREF_CHANGED: { |
| 1116 std::string* pref_name = Details<std::string>(details).ptr(); | 1098 std::string* pref_name = Details<std::string>(details).ptr(); |
| 1117 if (*pref_name == prefs::kSyncManaged) { | 1099 if (*pref_name == prefs::kSyncManaged) { |
| 1118 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 1100 NotifyObservers(); |
| 1119 if (*pref_sync_managed_) { | 1101 if (*pref_sync_managed_) { |
| 1120 DisableForUser(); | 1102 DisableForUser(); |
| 1121 } else if (HasSyncSetupCompleted() && AreCredentialsAvailable()) { | 1103 } else if (HasSyncSetupCompleted() && AreCredentialsAvailable()) { |
| 1122 StartUp(); | 1104 StartUp(); |
| 1123 } | 1105 } |
| 1124 } | 1106 } |
| 1125 break; | 1107 break; |
| 1126 } | 1108 } |
| 1127 case NotificationType::GOOGLE_SIGNIN_SUCCESSFUL: { | 1109 case NotificationType::GOOGLE_SIGNIN_SUCCESSFUL: { |
| 1128 const GoogleServiceSigninSuccessDetails* successful = | 1110 const GoogleServiceSigninSuccessDetails* successful = |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 // is initialized, all enabled data types are consistent with one | 1205 // is initialized, all enabled data types are consistent with one |
| 1224 // another, and no unrecoverable error has transpired. | 1206 // another, and no unrecoverable error has transpired. |
| 1225 if (unrecoverable_error_detected_) | 1207 if (unrecoverable_error_detected_) |
| 1226 return false; | 1208 return false; |
| 1227 | 1209 |
| 1228 if (!data_type_manager_.get()) | 1210 if (!data_type_manager_.get()) |
| 1229 return false; | 1211 return false; |
| 1230 | 1212 |
| 1231 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 1213 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
| 1232 } | 1214 } |
| OLD | NEW |