| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 55 |
| 56 const char* ProfileSyncService::kDevServerUrl = | 56 const char* ProfileSyncService::kDevServerUrl = |
| 57 "https://clients4.google.com/chrome-sync/dev"; | 57 "https://clients4.google.com/chrome-sync/dev"; |
| 58 | 58 |
| 59 static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. | 59 static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. |
| 60 | 60 |
| 61 ProfileSyncService::ProfileSyncService(ProfileSyncFactory* factory, | 61 ProfileSyncService::ProfileSyncService(ProfileSyncFactory* factory, |
| 62 Profile* profile, | 62 Profile* profile, |
| 63 const std::string& cros_user) | 63 const std::string& cros_user) |
| 64 : last_auth_error_(AuthError::None()), | 64 : last_auth_error_(AuthError::None()), |
| 65 observed_passphrase_required_(false), |
| 65 factory_(factory), | 66 factory_(factory), |
| 66 profile_(profile), | 67 profile_(profile), |
| 67 cros_user_(cros_user), | 68 cros_user_(cros_user), |
| 68 sync_service_url_(kDevServerUrl), | 69 sync_service_url_(kDevServerUrl), |
| 69 backend_initialized_(false), | 70 backend_initialized_(false), |
| 70 is_auth_in_progress_(false), | 71 is_auth_in_progress_(false), |
| 71 ALLOW_THIS_IN_INITIALIZER_LIST(wizard_(this)), | 72 ALLOW_THIS_IN_INITIALIZER_LIST(wizard_(this)), |
| 72 unrecoverable_error_detected_(false), | 73 unrecoverable_error_detected_(false), |
| 73 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_runnable_method_factory_(this)), | 74 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_runnable_method_factory_(this)), |
| 74 token_migrator_(NULL), | 75 token_migrator_(NULL), |
| 75 observed_passphrase_required_(false), | 76 |
| 76 clear_server_data_state_(CLEAR_NOT_STARTED) { | 77 clear_server_data_state_(CLEAR_NOT_STARTED) { |
| 77 DCHECK(factory); | 78 DCHECK(factory); |
| 78 DCHECK(profile); | 79 DCHECK(profile); |
| 79 registrar_.Add(this, | 80 registrar_.Add(this, |
| 80 NotificationType::SYNC_DATA_TYPES_UPDATED, | 81 NotificationType::SYNC_DATA_TYPES_UPDATED, |
| 81 Source<Profile>(profile)); | 82 Source<Profile>(profile)); |
| 82 | 83 |
| 83 // By default, dev & chromium users will go to the development servers. | 84 // By default, dev & chromium users will go to the development servers. |
| 84 // Dev servers have more features than standard sync servers. | 85 // Dev servers have more features than standard sync servers. |
| 85 // Chrome stable and beta builds will go to the standard sync servers. | 86 // Chrome stable and beta builds will go to the standard sync servers. |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 // The very first time the backend initializes is effectively the first time | 558 // The very first time the backend initializes is effectively the first time |
| 558 // we can say we successfully "synced". last_synced_time_ will only be null | 559 // we can say we successfully "synced". last_synced_time_ will only be null |
| 559 // in this case, because the pref wasn't restored on StartUp. | 560 // in this case, because the pref wasn't restored on StartUp. |
| 560 if (last_synced_time_.is_null()) { | 561 if (last_synced_time_.is_null()) { |
| 561 UpdateLastSyncedTime(); | 562 UpdateLastSyncedTime(); |
| 562 } | 563 } |
| 563 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 564 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); |
| 564 | 565 |
| 565 if (!cros_user_.empty()) { | 566 if (!cros_user_.empty()) { |
| 566 if (profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)) { | 567 if (profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)) { |
| 567 ShowChooseDataTypes(NULL); | 568 ShowConfigure(NULL); |
| 568 } else { | 569 } else { |
| 569 SetSyncSetupCompleted(); | 570 SetSyncSetupCompleted(); |
| 570 } | 571 } |
| 571 } | 572 } |
| 572 | 573 |
| 573 if (HasSyncSetupCompleted()) { | 574 if (HasSyncSetupCompleted()) { |
| 574 ConfigureDataTypeManager(); | 575 ConfigureDataTypeManager(); |
| 575 } | 576 } |
| 576 } | 577 } |
| 577 | 578 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 return; | 662 return; |
| 662 } | 663 } |
| 663 | 664 |
| 664 if (!auth_error_time_.is_null()) { | 665 if (!auth_error_time_.is_null()) { |
| 665 UMA_HISTOGRAM_LONG_TIMES("Sync.ReauthorizationTime", | 666 UMA_HISTOGRAM_LONG_TIMES("Sync.ReauthorizationTime", |
| 666 base::TimeTicks::Now() - auth_error_time_); | 667 base::TimeTicks::Now() - auth_error_time_); |
| 667 auth_error_time_ = base::TimeTicks(); // Reset auth_error_time_ to null. | 668 auth_error_time_ = base::TimeTicks(); // Reset auth_error_time_ to null. |
| 668 } | 669 } |
| 669 | 670 |
| 670 wizard_.SetParent(parent_window); | 671 wizard_.SetParent(parent_window); |
| 671 wizard_.Step(SyncSetupWizard::GAIA_LOGIN); | 672 // This method will also be called if a passphrase is needed. |
| 673 if (observed_passphrase_required_) |
| 674 wizard_.Step(SyncSetupWizard::ENTER_PASSPHRASE); |
| 675 else |
| 676 wizard_.Step(SyncSetupWizard::GAIA_LOGIN); |
| 672 | 677 |
| 673 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 678 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); |
| 674 } | 679 } |
| 675 | 680 |
| 676 void ProfileSyncService::ShowChooseDataTypes(gfx::NativeWindow parent_window) { | 681 void ProfileSyncService::ShowConfigure(gfx::NativeWindow parent_window) { |
| 677 if (WizardIsVisible()) { | 682 if (WizardIsVisible()) { |
| 678 wizard_.Focus(); | 683 wizard_.Focus(); |
| 679 return; | 684 return; |
| 680 } | 685 } |
| 681 wizard_.SetParent(parent_window); | 686 wizard_.SetParent(parent_window); |
| 682 wizard_.Step(SyncSetupWizard::CONFIGURE); | 687 wizard_.Step(SyncSetupWizard::CONFIGURE); |
| 683 } | 688 } |
| 684 | 689 |
| 685 SyncBackendHost::StatusSummary ProfileSyncService::QuerySyncStatusSummary() { | 690 SyncBackendHost::StatusSummary ProfileSyncService::QuerySyncStatusSummary() { |
| 686 if (backend_.get() && backend_initialized_) | 691 if (backend_.get() && backend_initialized_) |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 return; | 955 return; |
| 951 } | 956 } |
| 952 | 957 |
| 953 if (!cached_passphrase_.empty()) { | 958 if (!cached_passphrase_.empty()) { |
| 954 // Don't hold on to the passphrase in raw form longer than needed. | 959 // Don't hold on to the passphrase in raw form longer than needed. |
| 955 SetPassphrase(cached_passphrase_); | 960 SetPassphrase(cached_passphrase_); |
| 956 cached_passphrase_.clear(); | 961 cached_passphrase_.clear(); |
| 957 } | 962 } |
| 958 | 963 |
| 959 // TODO(sync): Less wizard, more toast. | 964 // TODO(sync): Less wizard, more toast. |
| 960 wizard_.Step(SyncSetupWizard::DONE); | 965 if (!observed_passphrase_required_) |
| 966 wizard_.Step(SyncSetupWizard::DONE); |
| 961 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 967 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); |
| 962 | 968 |
| 963 break; | 969 break; |
| 964 } | 970 } |
| 965 case NotificationType::SYNC_PASSPHRASE_REQUIRED: { | 971 case NotificationType::SYNC_PASSPHRASE_REQUIRED: { |
| 966 DCHECK(backend_.get()); | 972 DCHECK(backend_.get()); |
| 967 DCHECK(backend_->IsNigoriEnabled()); | 973 DCHECK(backend_->IsNigoriEnabled()); |
| 968 observed_passphrase_required_ = true; | 974 observed_passphrase_required_ = true; |
| 969 | 975 |
| 970 if (!cached_passphrase_.empty()) { | 976 if (!cached_passphrase_.empty()) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 990 break; | 996 break; |
| 991 } | 997 } |
| 992 case NotificationType::SYNC_PASSPHRASE_ACCEPTED: { | 998 case NotificationType::SYNC_PASSPHRASE_ACCEPTED: { |
| 993 // Make sure the data types that depend on the passphrase are started at | 999 // Make sure the data types that depend on the passphrase are started at |
| 994 // this time. | 1000 // this time. |
| 995 syncable::ModelTypeSet types; | 1001 syncable::ModelTypeSet types; |
| 996 GetPreferredDataTypes(&types); | 1002 GetPreferredDataTypes(&types); |
| 997 data_type_manager_->Configure(types); | 1003 data_type_manager_->Configure(types); |
| 998 | 1004 |
| 999 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 1005 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); |
| 1006 observed_passphrase_required_ = false; |
| 1007 wizard_.Step(SyncSetupWizard::DONE); |
| 1000 break; | 1008 break; |
| 1001 } | 1009 } |
| 1002 case NotificationType::PREF_CHANGED: { | 1010 case NotificationType::PREF_CHANGED: { |
| 1003 std::string* pref_name = Details<std::string>(details).ptr(); | 1011 std::string* pref_name = Details<std::string>(details).ptr(); |
| 1004 if (*pref_name == prefs::kSyncManaged) { | 1012 if (*pref_name == prefs::kSyncManaged) { |
| 1005 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 1013 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); |
| 1006 if (*pref_sync_managed_) { | 1014 if (*pref_sync_managed_) { |
| 1007 DisableForUser(); | 1015 DisableForUser(); |
| 1008 } else if (HasSyncSetupCompleted() && AreCredentialsAvailable()) { | 1016 } else if (HasSyncSetupCompleted() && AreCredentialsAvailable()) { |
| 1009 StartUp(); | 1017 StartUp(); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 // is initialized, all enabled data types are consistent with one | 1093 // is initialized, all enabled data types are consistent with one |
| 1086 // another, and no unrecoverable error has transpired. | 1094 // another, and no unrecoverable error has transpired. |
| 1087 if (unrecoverable_error_detected_) | 1095 if (unrecoverable_error_detected_) |
| 1088 return false; | 1096 return false; |
| 1089 | 1097 |
| 1090 if (!data_type_manager_.get()) | 1098 if (!data_type_manager_.get()) |
| 1091 return false; | 1099 return false; |
| 1092 | 1100 |
| 1093 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 1101 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
| 1094 } | 1102 } |
| OLD | NEW |