| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <ostream> | 9 #include <ostream> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "chrome/browser/sync/js_event_details.h" | 36 #include "chrome/browser/sync/js_event_details.h" |
| 37 #include "chrome/browser/sync/profile_sync_factory.h" | 37 #include "chrome/browser/sync/profile_sync_factory.h" |
| 38 #include "chrome/browser/sync/signin_manager.h" | 38 #include "chrome/browser/sync/signin_manager.h" |
| 39 #include "chrome/browser/ui/browser.h" | 39 #include "chrome/browser/ui/browser.h" |
| 40 #include "chrome/browser/ui/browser_list.h" | 40 #include "chrome/browser/ui/browser_list.h" |
| 41 #include "chrome/common/chrome_switches.h" | 41 #include "chrome/common/chrome_switches.h" |
| 42 #include "chrome/common/net/gaia/gaia_constants.h" | 42 #include "chrome/common/net/gaia/gaia_constants.h" |
| 43 #include "chrome/common/pref_names.h" | 43 #include "chrome/common/pref_names.h" |
| 44 #include "chrome/common/time_format.h" | 44 #include "chrome/common/time_format.h" |
| 45 #include "chrome/common/url_constants.h" | 45 #include "chrome/common/url_constants.h" |
| 46 #include "content/browser/webui/web_ui.h" | |
| 47 #include "content/common/notification_details.h" | 46 #include "content/common/notification_details.h" |
| 48 #include "content/common/notification_source.h" | 47 #include "content/common/notification_source.h" |
| 49 #include "content/common/notification_type.h" | 48 #include "content/common/notification_type.h" |
| 50 #include "grit/generated_resources.h" | 49 #include "grit/generated_resources.h" |
| 51 #include "ui/base/l10n/l10n_util.h" | 50 #include "ui/base/l10n/l10n_util.h" |
| 52 | 51 |
| 53 using browser_sync::ChangeProcessor; | 52 using browser_sync::ChangeProcessor; |
| 54 using browser_sync::DataTypeController; | 53 using browser_sync::DataTypeController; |
| 55 using browser_sync::DataTypeManager; | 54 using browser_sync::DataTypeManager; |
| 56 using browser_sync::SyncBackendHost; | 55 using browser_sync::SyncBackendHost; |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 // The very first time the backend initializes is effectively the first time | 534 // The very first time the backend initializes is effectively the first time |
| 536 // we can say we successfully "synced". last_synced_time_ will only be null | 535 // we can say we successfully "synced". last_synced_time_ will only be null |
| 537 // in this case, because the pref wasn't restored on StartUp. | 536 // in this case, because the pref wasn't restored on StartUp. |
| 538 if (last_synced_time_.is_null()) { | 537 if (last_synced_time_.is_null()) { |
| 539 UpdateLastSyncedTime(); | 538 UpdateLastSyncedTime(); |
| 540 } | 539 } |
| 541 NotifyObservers(); | 540 NotifyObservers(); |
| 542 | 541 |
| 543 if (!cros_user_.empty()) { | 542 if (!cros_user_.empty()) { |
| 544 if (profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)) { | 543 if (profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)) { |
| 545 ShowConfigure(NULL, true); | 544 ShowConfigure(true); |
| 546 } else { | 545 } else { |
| 547 SetSyncSetupCompleted(); | 546 SetSyncSetupCompleted(); |
| 548 } | 547 } |
| 549 } | 548 } |
| 550 | 549 |
| 551 if (HasSyncSetupCompleted()) { | 550 if (HasSyncSetupCompleted()) { |
| 552 ConfigureDataTypeManager(); | 551 ConfigureDataTypeManager(); |
| 553 } | 552 } |
| 554 } | 553 } |
| 555 | 554 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 void ProfileSyncService::OnMigrationNeededForTypes( | 701 void ProfileSyncService::OnMigrationNeededForTypes( |
| 703 const syncable::ModelTypeSet& types) { | 702 const syncable::ModelTypeSet& types) { |
| 704 DCHECK(backend_initialized_); | 703 DCHECK(backend_initialized_); |
| 705 DCHECK(data_type_manager_.get()); | 704 DCHECK(data_type_manager_.get()); |
| 706 | 705 |
| 707 // Migrator must be valid, because we don't sync until it is created and this | 706 // Migrator must be valid, because we don't sync until it is created and this |
| 708 // callback originates from a sync cycle. | 707 // callback originates from a sync cycle. |
| 709 migrator_->MigrateTypes(types); | 708 migrator_->MigrateTypes(types); |
| 710 } | 709 } |
| 711 | 710 |
| 712 void ProfileSyncService::ShowLoginDialog(WebUI* web_ui) { | 711 void ProfileSyncService::ShowLoginDialog() { |
| 713 if (WizardIsVisible()) { | 712 if (WizardIsVisible()) { |
| 714 wizard_.Focus(); | 713 wizard_.Focus(); |
| 715 // Force the wizard to step to the login screen (which will only actually | 714 // Force the wizard to step to the login screen (which will only actually |
| 716 // happen if the transition is valid). | 715 // happen if the transition is valid). |
| 717 wizard_.Step(SyncSetupWizard::GAIA_LOGIN); | 716 wizard_.Step(SyncSetupWizard::GAIA_LOGIN); |
| 718 return; | 717 return; |
| 719 } | 718 } |
| 720 | 719 |
| 721 if (!auth_error_time_.is_null()) { | 720 if (!auth_error_time_.is_null()) { |
| 722 UMA_HISTOGRAM_LONG_TIMES("Sync.ReauthorizationTime", | 721 UMA_HISTOGRAM_LONG_TIMES("Sync.ReauthorizationTime", |
| 723 base::TimeTicks::Now() - auth_error_time_); | 722 base::TimeTicks::Now() - auth_error_time_); |
| 724 auth_error_time_ = base::TimeTicks(); // Reset auth_error_time_ to null. | 723 auth_error_time_ = base::TimeTicks(); // Reset auth_error_time_ to null. |
| 725 } | 724 } |
| 726 | 725 |
| 727 ShowSyncSetup(web_ui, SyncSetupWizard::GAIA_LOGIN); | 726 ShowSyncSetup(SyncSetupWizard::GAIA_LOGIN); |
| 728 | 727 |
| 729 NotifyObservers(); | 728 NotifyObservers(); |
| 730 } | 729 } |
| 731 | 730 |
| 732 void ProfileSyncService::ShowErrorUI(WebUI* web_ui) { | 731 void ProfileSyncService::ShowErrorUI() { |
| 733 if (IsPassphraseRequired()) { | 732 if (WizardIsVisible()) { |
| 734 if (IsUsingSecondaryPassphrase()) | 733 wizard_.Focus(); |
| 735 PromptForExistingPassphrase(web_ui); | |
| 736 else | |
| 737 NOTREACHED(); // Migration no longer supported. | |
| 738 | |
| 739 return; | 734 return; |
| 740 } | 735 } |
| 741 | 736 |
| 742 const GoogleServiceAuthError& error = GetAuthError(); | 737 ShowSyncSetup(SyncSetupWizard::NONFATAL_ERROR); |
| 743 if (error.state() == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || | |
| 744 error.state() == GoogleServiceAuthError::CAPTCHA_REQUIRED || | |
| 745 error.state() == GoogleServiceAuthError::ACCOUNT_DELETED || | |
| 746 error.state() == GoogleServiceAuthError::ACCOUNT_DISABLED || | |
| 747 error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE) { | |
| 748 ShowLoginDialog(web_ui); | |
| 749 } | |
| 750 } | 738 } |
| 751 | 739 |
| 752 void ProfileSyncService::ShowConfigure(WebUI* web_ui, bool sync_everything) { | 740 void ProfileSyncService::ShowConfigure(bool sync_everything) { |
| 753 if (WizardIsVisible()) { | 741 if (WizardIsVisible()) { |
| 754 wizard_.Focus(); | 742 wizard_.Focus(); |
| 755 return; | 743 return; |
| 756 } | 744 } |
| 757 | 745 |
| 758 if (sync_everything) | 746 if (sync_everything) |
| 759 ShowSyncSetup(web_ui, SyncSetupWizard::SYNC_EVERYTHING); | 747 ShowSyncSetup(SyncSetupWizard::SYNC_EVERYTHING); |
| 760 else | 748 else |
| 761 ShowSyncSetup(web_ui, SyncSetupWizard::CONFIGURE); | 749 ShowSyncSetup(SyncSetupWizard::CONFIGURE); |
| 762 } | 750 } |
| 763 | 751 |
| 764 void ProfileSyncService::PromptForExistingPassphrase(WebUI* web_ui) { | 752 void ProfileSyncService::PromptForExistingPassphrase() { |
| 765 if (WizardIsVisible()) { | 753 if (WizardIsVisible()) { |
| 766 wizard_.Focus(); | 754 wizard_.Focus(); |
| 767 return; | 755 return; |
| 768 } | 756 } |
| 769 | 757 |
| 770 ShowSyncSetup(web_ui, SyncSetupWizard::ENTER_PASSPHRASE); | 758 ShowSyncSetup(SyncSetupWizard::ENTER_PASSPHRASE); |
| 771 } | 759 } |
| 772 | 760 |
| 773 void ProfileSyncService::ShowSyncSetup(WebUI* web_ui, | 761 void ProfileSyncService::ShowSyncSetup(SyncSetupWizard::State state) { |
| 774 SyncSetupWizard::State state) { | |
| 775 wizard_.Step(state); | 762 wizard_.Step(state); |
| 776 if (web_ui) | 763 BrowserList::GetLastActive()->ShowOptionsTab(chrome::kSyncSetupSubPage); |
| 777 web_ui->CallJavascriptFunction("options.SyncSetupOverlay.showSyncDialog"); | |
| 778 else | |
| 779 BrowserList::GetLastActive()->ShowOptionsTab(chrome::kSyncSetupSubPage); | |
| 780 } | 764 } |
| 781 | 765 |
| 782 SyncBackendHost::StatusSummary ProfileSyncService::QuerySyncStatusSummary() { | 766 SyncBackendHost::StatusSummary ProfileSyncService::QuerySyncStatusSummary() { |
| 783 if (backend_.get() && backend_initialized_) | 767 if (backend_.get() && backend_initialized_) |
| 784 return backend_->GetStatusSummary(); | 768 return backend_->GetStatusSummary(); |
| 785 else | 769 else |
| 786 return SyncBackendHost::Status::OFFLINE_UNUSABLE; | 770 return SyncBackendHost::Status::OFFLINE_UNUSABLE; |
| 787 } | 771 } |
| 788 | 772 |
| 789 SyncBackendHost::Status ProfileSyncService::QueryDetailedSyncStatus() { | 773 SyncBackendHost::Status ProfileSyncService::QueryDetailedSyncStatus() { |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1351 // another, and no unrecoverable error has transpired. | 1335 // another, and no unrecoverable error has transpired. |
| 1352 if (unrecoverable_error_detected_) | 1336 if (unrecoverable_error_detected_) |
| 1353 return false; | 1337 return false; |
| 1354 | 1338 |
| 1355 if (!data_type_manager_.get()) | 1339 if (!data_type_manager_.get()) |
| 1356 return false; | 1340 return false; |
| 1357 | 1341 |
| 1358 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 1342 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
| 1359 } | 1343 } |
| 1360 | 1344 |
| OLD | NEW |