OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 browser_sync::StringToNotificationMethod(notification_method_str); | 193 browser_sync::StringToNotificationMethod(notification_method_str); |
194 } | 194 } |
195 } | 195 } |
196 | 196 |
197 void ProfileSyncService::RegisterPreferences() { | 197 void ProfileSyncService::RegisterPreferences() { |
198 PrefService* pref_service = profile_->GetPrefs(); | 198 PrefService* pref_service = profile_->GetPrefs(); |
199 if (pref_service->FindPreference(prefs::kSyncLastSyncedTime)) | 199 if (pref_service->FindPreference(prefs::kSyncLastSyncedTime)) |
200 return; | 200 return; |
201 pref_service->RegisterInt64Pref(prefs::kSyncLastSyncedTime, 0); | 201 pref_service->RegisterInt64Pref(prefs::kSyncLastSyncedTime, 0); |
202 pref_service->RegisterBooleanPref(prefs::kSyncHasSetupCompleted, false); | 202 pref_service->RegisterBooleanPref(prefs::kSyncHasSetupCompleted, false); |
| 203 pref_service->RegisterBooleanPref(prefs::kKeepEverythingSynced, false); |
203 | 204 |
204 // If you've never synced before, or if you're using Chrome OS, all datatypes | 205 // If you've never synced before, or if you're using Chrome OS, all datatypes |
205 // are on by default. | 206 // are on by default. |
206 // TODO(nick): Perhaps a better model would be to always default to false, | 207 // TODO(nick): Perhaps a better model would be to always default to false, |
207 // and explicitly call SetDataTypes() when the user shows the wizard. | 208 // and explicitly call SetDataTypes() when the user shows the wizard. |
208 #if defined(OS_CHROMEOS) | 209 #if defined(OS_CHROMEOS) |
209 bool enable_by_default = true; | 210 bool enable_by_default = true; |
210 #else | 211 #else |
211 bool enable_by_default = | 212 bool enable_by_default = |
212 !pref_service->HasPrefPath(prefs::kSyncHasSetupCompleted); | 213 !pref_service->HasPrefPath(prefs::kSyncHasSetupCompleted); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 UMA_HISTOGRAM_LONG_TIMES("Sync.ReauthorizationTime", | 504 UMA_HISTOGRAM_LONG_TIMES("Sync.ReauthorizationTime", |
504 base::TimeTicks::Now() - auth_error_time_); | 505 base::TimeTicks::Now() - auth_error_time_); |
505 auth_error_time_ = base::TimeTicks(); // Reset auth_error_time_ to null. | 506 auth_error_time_ = base::TimeTicks(); // Reset auth_error_time_ to null. |
506 } | 507 } |
507 | 508 |
508 if (last_auth_error_.state() != AuthError::NONE) { | 509 if (last_auth_error_.state() != AuthError::NONE) { |
509 wizard_.Step(SyncSetupWizard::GAIA_LOGIN); | 510 wizard_.Step(SyncSetupWizard::GAIA_LOGIN); |
510 } | 511 } |
511 } | 512 } |
512 | 513 |
| 514 void ProfileSyncService::ShowChooseDataTypes() { |
| 515 if (WizardIsVisible()) { |
| 516 wizard_.Focus(); |
| 517 return; |
| 518 } |
| 519 |
| 520 wizard_.Step(SyncSetupWizard::CHOOSE_DATA_TYPES); |
| 521 } |
| 522 |
513 SyncBackendHost::StatusSummary ProfileSyncService::QuerySyncStatusSummary() { | 523 SyncBackendHost::StatusSummary ProfileSyncService::QuerySyncStatusSummary() { |
514 if (backend_.get()) | 524 if (backend_.get()) |
515 return backend_->GetStatusSummary(); | 525 return backend_->GetStatusSummary(); |
516 else | 526 else |
517 return SyncBackendHost::Status::OFFLINE_UNUSABLE; | 527 return SyncBackendHost::Status::OFFLINE_UNUSABLE; |
518 } | 528 } |
519 | 529 |
520 SyncBackendHost::Status ProfileSyncService::QueryDetailedSyncStatus() { | 530 SyncBackendHost::Status ProfileSyncService::QueryDetailedSyncStatus() { |
521 if (backend_.get()) { | 531 if (backend_.get()) { |
522 return backend_->GetDetailedStatus(); | 532 return backend_->GetDetailedStatus(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 } | 586 } |
577 last_attempted_user_email_ = username; | 587 last_attempted_user_email_ = username; |
578 is_auth_in_progress_ = true; | 588 is_auth_in_progress_ = true; |
579 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 589 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); |
580 | 590 |
581 auth_start_time_ = base::TimeTicks::Now(); | 591 auth_start_time_ = base::TimeTicks::Now(); |
582 backend_->Authenticate(username, password, captcha); | 592 backend_->Authenticate(username, password, captcha); |
583 } | 593 } |
584 | 594 |
585 void ProfileSyncService::OnUserChoseDatatypes(bool sync_everything, | 595 void ProfileSyncService::OnUserChoseDatatypes(bool sync_everything, |
586 const syncable::ModelTypeSet& data_types) { | 596 const syncable::ModelTypeSet& chosen_types) { |
587 // TODO(dantasse): save sync_everything to prefs | 597 if (!backend_.get()) { |
588 // call StartSyncing(data_types) | 598 NOTREACHED(); |
589 // call ChangePreferredDataTypes(data_types) | 599 return; |
| 600 } |
| 601 profile_->GetPrefs()->SetBoolean(prefs::kKeepEverythingSynced, |
| 602 sync_everything); |
| 603 |
| 604 ChangePreferredDataTypes(chosen_types); |
| 605 profile_->GetPrefs()->ScheduleSavePersistentPrefs(); |
| 606 |
| 607 // If the backend has already started syncing, that's okay; |
| 608 // SyncerThread::Start() checks if it's already running before starting. |
| 609 backend_->StartSyncing(); |
| 610 // TODO(dantasse): pass the chosen_types parameter through to the backend |
590 } | 611 } |
591 | 612 |
592 void ProfileSyncService::OnUserCancelledDialog() { | 613 void ProfileSyncService::OnUserCancelledDialog() { |
593 if (!profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted)) { | 614 if (!profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted)) { |
594 // A sync dialog was aborted before authentication. | 615 // A sync dialog was aborted before authentication. |
595 // Rollback. | 616 // Rollback. |
596 DisableForUser(); | 617 DisableForUser(); |
597 } | 618 } |
598 | 619 |
599 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 620 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 DataTypeManager::ConfigureResult result = | 733 DataTypeManager::ConfigureResult result = |
713 *(Details<DataTypeManager::ConfigureResult>(details).ptr()); | 734 *(Details<DataTypeManager::ConfigureResult>(details).ptr()); |
714 if (result != DataTypeManager::OK) { | 735 if (result != DataTypeManager::OK) { |
715 OnUnrecoverableError(FROM_HERE, "Sync Configuration failed."); | 736 OnUnrecoverableError(FROM_HERE, "Sync Configuration failed."); |
716 return; | 737 return; |
717 } | 738 } |
718 | 739 |
719 // TODO(sync): Less wizard, more toast. | 740 // TODO(sync): Less wizard, more toast. |
720 wizard_.Step(SyncSetupWizard::DONE); | 741 wizard_.Step(SyncSetupWizard::DONE); |
721 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 742 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); |
| 743 |
722 break; | 744 break; |
723 } | 745 } |
724 case NotificationType::SYNC_PASSPHRASE_REQUIRED: { | 746 case NotificationType::SYNC_PASSPHRASE_REQUIRED: { |
725 // TODO(sync): Show the passphrase UI here. | 747 // TODO(sync): Show the passphrase UI here. |
726 SetPassphrase("dummy passphrase"); | 748 SetPassphrase("dummy passphrase"); |
727 break; | 749 break; |
728 } | 750 } |
729 case NotificationType::SYNC_PASSPHRASE_ACCEPTED: { | 751 case NotificationType::SYNC_PASSPHRASE_ACCEPTED: { |
730 // Make sure the data types that depend on the passphrase are started at | 752 // Make sure the data types that depend on the passphrase are started at |
731 // this time. | 753 // this time. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 // is initialized, all enabled data types are consistent with one | 787 // is initialized, all enabled data types are consistent with one |
766 // another, and no unrecoverable error has transpired. | 788 // another, and no unrecoverable error has transpired. |
767 if (unrecoverable_error_detected_) | 789 if (unrecoverable_error_detected_) |
768 return false; | 790 return false; |
769 | 791 |
770 if (!data_type_manager_.get()) | 792 if (!data_type_manager_.get()) |
771 return false; | 793 return false; |
772 | 794 |
773 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 795 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
774 } | 796 } |
OLD | NEW |