| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <cstddef> | 7 #include <cstddef> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 #include "sync/internal_api/public/util/experiments.h" | 61 #include "sync/internal_api/public/util/experiments.h" |
| 62 #include "sync/js/js_arg_list.h" | 62 #include "sync/js/js_arg_list.h" |
| 63 #include "sync/js/js_event_details.h" | 63 #include "sync/js/js_event_details.h" |
| 64 #include "sync/util/cryptographer.h" | 64 #include "sync/util/cryptographer.h" |
| 65 #include "ui/base/l10n/l10n_util.h" | 65 #include "ui/base/l10n/l10n_util.h" |
| 66 | 66 |
| 67 using browser_sync::ChangeProcessor; | 67 using browser_sync::ChangeProcessor; |
| 68 using browser_sync::DataTypeController; | 68 using browser_sync::DataTypeController; |
| 69 using browser_sync::DataTypeManager; | 69 using browser_sync::DataTypeManager; |
| 70 using browser_sync::SyncBackendHost; | 70 using browser_sync::SyncBackendHost; |
| 71 using syncable::ModelType; | 71 using syncer::ModelType; |
| 72 using syncable::ModelTypeSet; | 72 using syncer::ModelTypeSet; |
| 73 using syncer::JsBackend; | 73 using syncer::JsBackend; |
| 74 using syncer::JsController; | 74 using syncer::JsController; |
| 75 using syncer::JsEventDetails; | 75 using syncer::JsEventDetails; |
| 76 using syncer::JsEventHandler; | 76 using syncer::JsEventHandler; |
| 77 using syncer::ModelSafeRoutingInfo; | 77 using syncer::ModelSafeRoutingInfo; |
| 78 using syncer::SyncCredentials; | 78 using syncer::SyncCredentials; |
| 79 using syncer::SyncProtocolError; | 79 using syncer::SyncProtocolError; |
| 80 using syncer::WeakHandle; | 80 using syncer::WeakHandle; |
| 81 | 81 |
| 82 typedef GoogleServiceAuthError AuthError; | 82 typedef GoogleServiceAuthError AuthError; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 | 255 |
| 256 void ProfileSyncService::RegisterDataTypeController( | 256 void ProfileSyncService::RegisterDataTypeController( |
| 257 DataTypeController* data_type_controller) { | 257 DataTypeController* data_type_controller) { |
| 258 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); | 258 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); |
| 259 data_type_controllers_[data_type_controller->type()] = | 259 data_type_controllers_[data_type_controller->type()] = |
| 260 data_type_controller; | 260 data_type_controller; |
| 261 } | 261 } |
| 262 | 262 |
| 263 browser_sync::SessionModelAssociator* | 263 browser_sync::SessionModelAssociator* |
| 264 ProfileSyncService::GetSessionModelAssociator() { | 264 ProfileSyncService::GetSessionModelAssociator() { |
| 265 if (data_type_controllers_.find(syncable::SESSIONS) == | 265 if (data_type_controllers_.find(syncer::SESSIONS) == |
| 266 data_type_controllers_.end() || | 266 data_type_controllers_.end() || |
| 267 data_type_controllers_.find(syncable::SESSIONS)->second->state() != | 267 data_type_controllers_.find(syncer::SESSIONS)->second->state() != |
| 268 DataTypeController::RUNNING) { | 268 DataTypeController::RUNNING) { |
| 269 return NULL; | 269 return NULL; |
| 270 } | 270 } |
| 271 return static_cast<browser_sync::SessionDataTypeController*>( | 271 return static_cast<browser_sync::SessionDataTypeController*>( |
| 272 data_type_controllers_.find( | 272 data_type_controllers_.find( |
| 273 syncable::SESSIONS)->second.get())->GetModelAssociator(); | 273 syncer::SESSIONS)->second.get())->GetModelAssociator(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 void ProfileSyncService::GetDataTypeControllerStates( | 276 void ProfileSyncService::GetDataTypeControllerStates( |
| 277 browser_sync::DataTypeController::StateMap* state_map) const { | 277 browser_sync::DataTypeController::StateMap* state_map) const { |
| 278 for (browser_sync::DataTypeController::TypeMap::const_iterator iter = | 278 for (browser_sync::DataTypeController::TypeMap::const_iterator iter = |
| 279 data_type_controllers_.begin(); iter != data_type_controllers_.end(); | 279 data_type_controllers_.begin(); iter != data_type_controllers_.end(); |
| 280 ++iter) | 280 ++iter) |
| 281 (*state_map)[iter->first] = iter->second.get()->state(); | 281 (*state_map)[iter->first] = iter->second.get()->state(); |
| 282 } | 282 } |
| 283 | 283 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 } | 318 } |
| 319 return credentials; | 319 return credentials; |
| 320 } | 320 } |
| 321 | 321 |
| 322 void ProfileSyncService::InitializeBackend(bool delete_stale_data) { | 322 void ProfileSyncService::InitializeBackend(bool delete_stale_data) { |
| 323 if (!backend_.get()) { | 323 if (!backend_.get()) { |
| 324 NOTREACHED(); | 324 NOTREACHED(); |
| 325 return; | 325 return; |
| 326 } | 326 } |
| 327 | 327 |
| 328 syncable::ModelTypeSet initial_types; | 328 syncer::ModelTypeSet initial_types; |
| 329 // If sync setup hasn't finished, we don't want to initialize routing info | 329 // If sync setup hasn't finished, we don't want to initialize routing info |
| 330 // for any data types so that we don't download updates for types that the | 330 // for any data types so that we don't download updates for types that the |
| 331 // user chooses not to sync on the first DownloadUpdatesCommand. | 331 // user chooses not to sync on the first DownloadUpdatesCommand. |
| 332 if (HasSyncSetupCompleted()) { | 332 if (HasSyncSetupCompleted()) { |
| 333 initial_types = GetPreferredDataTypes(); | 333 initial_types = GetPreferredDataTypes(); |
| 334 } | 334 } |
| 335 | 335 |
| 336 SyncCredentials credentials = GetCredentials(); | 336 SyncCredentials credentials = GetCredentials(); |
| 337 | 337 |
| 338 scoped_refptr<net::URLRequestContextGetter> request_context_getter( | 338 scoped_refptr<net::URLRequestContextGetter> request_context_getter( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 359 void ProfileSyncService::CreateBackend() { | 359 void ProfileSyncService::CreateBackend() { |
| 360 backend_.reset( | 360 backend_.reset( |
| 361 new SyncBackendHost(profile_->GetDebugName(), | 361 new SyncBackendHost(profile_->GetDebugName(), |
| 362 profile_, sync_prefs_.AsWeakPtr(), | 362 profile_, sync_prefs_.AsWeakPtr(), |
| 363 invalidator_storage_.AsWeakPtr())); | 363 invalidator_storage_.AsWeakPtr())); |
| 364 } | 364 } |
| 365 | 365 |
| 366 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { | 366 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { |
| 367 if (encryption_pending()) | 367 if (encryption_pending()) |
| 368 return true; | 368 return true; |
| 369 const syncable::ModelTypeSet preferred_types = GetPreferredDataTypes(); | 369 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes(); |
| 370 const syncable::ModelTypeSet encrypted_types = GetEncryptedDataTypes(); | 370 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes(); |
| 371 DCHECK(encrypted_types.Has(syncable::PASSWORDS)); | 371 DCHECK(encrypted_types.Has(syncer::PASSWORDS)); |
| 372 return !Intersection(preferred_types, encrypted_types).Empty(); | 372 return !Intersection(preferred_types, encrypted_types).Empty(); |
| 373 } | 373 } |
| 374 | 374 |
| 375 void ProfileSyncService::OnSyncConfigureDone( | 375 void ProfileSyncService::OnSyncConfigureDone( |
| 376 DataTypeManager::ConfigureResult result) { | 376 DataTypeManager::ConfigureResult result) { |
| 377 if (failed_datatypes_handler_.UpdateFailedDatatypes(result.failed_data_types, | 377 if (failed_datatypes_handler_.UpdateFailedDatatypes(result.failed_data_types, |
| 378 FailedDatatypesHandler::STARTUP)) { | 378 FailedDatatypesHandler::STARTUP)) { |
| 379 ReconfigureDatatypeManager(); | 379 ReconfigureDatatypeManager(); |
| 380 } | 380 } |
| 381 } | 381 } |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 } | 557 } |
| 558 | 558 |
| 559 void ProfileSyncService::ClearUnrecoverableError() { | 559 void ProfileSyncService::ClearUnrecoverableError() { |
| 560 unrecoverable_error_reason_ = ERROR_REASON_UNSET; | 560 unrecoverable_error_reason_ = ERROR_REASON_UNSET; |
| 561 unrecoverable_error_message_.clear(); | 561 unrecoverable_error_message_.clear(); |
| 562 unrecoverable_error_location_ = tracked_objects::Location(); | 562 unrecoverable_error_location_ = tracked_objects::Location(); |
| 563 } | 563 } |
| 564 | 564 |
| 565 // static | 565 // static |
| 566 std::string ProfileSyncService::GetExperimentNameForDataType( | 566 std::string ProfileSyncService::GetExperimentNameForDataType( |
| 567 syncable::ModelType data_type) { | 567 syncer::ModelType data_type) { |
| 568 switch (data_type) { | 568 switch (data_type) { |
| 569 case syncable::SESSIONS: | 569 case syncer::SESSIONS: |
| 570 return "sync-tabs"; | 570 return "sync-tabs"; |
| 571 default: | 571 default: |
| 572 break; | 572 break; |
| 573 } | 573 } |
| 574 NOTREACHED(); | 574 NOTREACHED(); |
| 575 return ""; | 575 return ""; |
| 576 } | 576 } |
| 577 | 577 |
| 578 void ProfileSyncService::RegisterNewDataType(syncable::ModelType data_type) { | 578 void ProfileSyncService::RegisterNewDataType(syncer::ModelType data_type) { |
| 579 if (data_type_controllers_.count(data_type) > 0) | 579 if (data_type_controllers_.count(data_type) > 0) |
| 580 return; | 580 return; |
| 581 NOTREACHED(); | 581 NOTREACHED(); |
| 582 } | 582 } |
| 583 | 583 |
| 584 // An invariant has been violated. Transition to an error state where we try | 584 // An invariant has been violated. Transition to an error state where we try |
| 585 // to do as little work as possible, to avoid further corruption or crashes. | 585 // to do as little work as possible, to avoid further corruption or crashes. |
| 586 void ProfileSyncService::OnUnrecoverableError( | 586 void ProfileSyncService::OnUnrecoverableError( |
| 587 const tracked_objects::Location& from_here, | 587 const tracked_objects::Location& from_here, |
| 588 const std::string& message) { | 588 const std::string& message) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 610 << "Unrecoverable error detected at " << location | 610 << "Unrecoverable error detected at " << location |
| 611 << " -- ProfileSyncService unusable: " << message; | 611 << " -- ProfileSyncService unusable: " << message; |
| 612 | 612 |
| 613 // Shut all data types down. | 613 // Shut all data types down. |
| 614 MessageLoop::current()->PostTask(FROM_HERE, | 614 MessageLoop::current()->PostTask(FROM_HERE, |
| 615 base::Bind(&ProfileSyncService::ShutdownImpl, weak_factory_.GetWeakPtr(), | 615 base::Bind(&ProfileSyncService::ShutdownImpl, weak_factory_.GetWeakPtr(), |
| 616 delete_sync_database)); | 616 delete_sync_database)); |
| 617 } | 617 } |
| 618 | 618 |
| 619 void ProfileSyncService::DisableBrokenDatatype( | 619 void ProfileSyncService::DisableBrokenDatatype( |
| 620 syncable::ModelType type, | 620 syncer::ModelType type, |
| 621 const tracked_objects::Location& from_here, | 621 const tracked_objects::Location& from_here, |
| 622 std::string message) { | 622 std::string message) { |
| 623 // First deactivate the type so that no further server changes are | 623 // First deactivate the type so that no further server changes are |
| 624 // passed onto the change processor. | 624 // passed onto the change processor. |
| 625 DeactivateDataType(type); | 625 DeactivateDataType(type); |
| 626 | 626 |
| 627 syncer::SyncError error(from_here, message, type); | 627 syncer::SyncError error(from_here, message, type); |
| 628 | 628 |
| 629 std::list<syncer::SyncError> errors; | 629 std::list<syncer::SyncError> errors; |
| 630 errors.push_back(error); | 630 errors.push_back(error); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 // OnBackendInitialized() to ensure the new datatypes are available at sync | 717 // OnBackendInitialized() to ensure the new datatypes are available at sync |
| 718 // setup. As a result, the migrator won't exist yet. This is fine because for | 718 // setup. As a result, the migrator won't exist yet. This is fine because for |
| 719 // first time sync cases we're only concerned with making the datatype | 719 // first time sync cases we're only concerned with making the datatype |
| 720 // available. | 720 // available. |
| 721 if (migrator_.get() && | 721 if (migrator_.get() && |
| 722 migrator_->state() != browser_sync::BackendMigrator::IDLE) { | 722 migrator_->state() != browser_sync::BackendMigrator::IDLE) { |
| 723 DVLOG(1) << "Dropping OnExperimentsChanged due to migrator busy."; | 723 DVLOG(1) << "Dropping OnExperimentsChanged due to migrator busy."; |
| 724 return; | 724 return; |
| 725 } | 725 } |
| 726 | 726 |
| 727 const syncable::ModelTypeSet registered_types = GetRegisteredDataTypes(); | 727 const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); |
| 728 syncable::ModelTypeSet to_add; | 728 syncer::ModelTypeSet to_add; |
| 729 const syncable::ModelTypeSet to_register = | 729 const syncer::ModelTypeSet to_register = |
| 730 Difference(to_add, registered_types); | 730 Difference(to_add, registered_types); |
| 731 DVLOG(2) << "OnExperimentsChanged called with types: " | 731 DVLOG(2) << "OnExperimentsChanged called with types: " |
| 732 << syncable::ModelTypeSetToString(to_add); | 732 << syncer::ModelTypeSetToString(to_add); |
| 733 DVLOG(2) << "Enabling types: " << syncable::ModelTypeSetToString(to_register); | 733 DVLOG(2) << "Enabling types: " << syncer::ModelTypeSetToString(to_register); |
| 734 | 734 |
| 735 for (syncable::ModelTypeSet::Iterator it = to_register.First(); | 735 for (syncer::ModelTypeSet::Iterator it = to_register.First(); |
| 736 it.Good(); it.Inc()) { | 736 it.Good(); it.Inc()) { |
| 737 // Received notice to enable experimental type. Check if the type is | 737 // Received notice to enable experimental type. Check if the type is |
| 738 // registered, and if not register a new datatype controller. | 738 // registered, and if not register a new datatype controller. |
| 739 RegisterNewDataType(it.Get()); | 739 RegisterNewDataType(it.Get()); |
| 740 #if !defined(OS_ANDROID) | 740 #if !defined(OS_ANDROID) |
| 741 // Enable the about:flags switch for the experimental type so we don't have | 741 // Enable the about:flags switch for the experimental type so we don't have |
| 742 // to always perform this reconfiguration. Once we set this, the type will | 742 // to always perform this reconfiguration. Once we set this, the type will |
| 743 // remain registered on restart, so we will no longer go down this code | 743 // remain registered on restart, so we will no longer go down this code |
| 744 // path. | 744 // path. |
| 745 std::string experiment_name = GetExperimentNameForDataType(it.Get()); | 745 std::string experiment_name = GetExperimentNameForDataType(it.Get()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 758 // covers the case where we're already in the process of reconfiguring | 758 // covers the case where we're already in the process of reconfiguring |
| 759 // to turn an experimental type on. | 759 // to turn an experimental type on. |
| 760 if (sync_prefs_.HasKeepEverythingSynced()) { | 760 if (sync_prefs_.HasKeepEverythingSynced()) { |
| 761 // Mark all data types as preferred. | 761 // Mark all data types as preferred. |
| 762 sync_prefs_.SetPreferredDataTypes(registered_types, registered_types); | 762 sync_prefs_.SetPreferredDataTypes(registered_types, registered_types); |
| 763 | 763 |
| 764 // Only automatically turn on types if we have already finished set up. | 764 // Only automatically turn on types if we have already finished set up. |
| 765 // Otherwise, just leave the experimental types on by default. | 765 // Otherwise, just leave the experimental types on by default. |
| 766 if (!to_register.Empty() && HasSyncSetupCompleted() && migrator_.get()) { | 766 if (!to_register.Empty() && HasSyncSetupCompleted() && migrator_.get()) { |
| 767 DVLOG(1) << "Dynamically enabling new datatypes: " | 767 DVLOG(1) << "Dynamically enabling new datatypes: " |
| 768 << syncable::ModelTypeSetToString(to_register); | 768 << syncer::ModelTypeSetToString(to_register); |
| 769 OnMigrationNeededForTypes(to_register); | 769 OnMigrationNeededForTypes(to_register); |
| 770 } | 770 } |
| 771 } | 771 } |
| 772 | 772 |
| 773 // Now enable any non-datatype features. | 773 // Now enable any non-datatype features. |
| 774 if (experiments.sync_tab_favicons) { | 774 if (experiments.sync_tab_favicons) { |
| 775 DVLOG(1) << "Enabling syncing of tab favicons."; | 775 DVLOG(1) << "Enabling syncing of tab favicons."; |
| 776 about_flags::SetExperimentEnabled(g_browser_process->local_state(), | 776 about_flags::SetExperimentEnabled(g_browser_process->local_state(), |
| 777 "sync-tab-favicons", | 777 "sync-tab-favicons", |
| 778 true); | 778 true); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 "Passphrase no longer required but there is still a cached passphrase"; | 854 "Passphrase no longer required but there is still a cached passphrase"; |
| 855 | 855 |
| 856 // Reset passphrase_required_reason_ since we know we no longer require the | 856 // Reset passphrase_required_reason_ since we know we no longer require the |
| 857 // passphrase. We do this here rather than down in ResolvePassphraseRequired() | 857 // passphrase. We do this here rather than down in ResolvePassphraseRequired() |
| 858 // because that can be called by OnPassphraseRequired() if no encrypted data | 858 // because that can be called by OnPassphraseRequired() if no encrypted data |
| 859 // types are enabled, and we don't want to clobber the true passphrase error. | 859 // types are enabled, and we don't want to clobber the true passphrase error. |
| 860 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED; | 860 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED; |
| 861 | 861 |
| 862 // Make sure the data types that depend on the passphrase are started at | 862 // Make sure the data types that depend on the passphrase are started at |
| 863 // this time. | 863 // this time. |
| 864 const syncable::ModelTypeSet types = GetPreferredDataTypes(); | 864 const syncer::ModelTypeSet types = GetPreferredDataTypes(); |
| 865 | 865 |
| 866 if (data_type_manager_.get()) { | 866 if (data_type_manager_.get()) { |
| 867 // Unblock the data type manager if necessary. | 867 // Unblock the data type manager if necessary. |
| 868 data_type_manager_->Configure(types, | 868 data_type_manager_->Configure(types, |
| 869 syncer::CONFIGURE_REASON_RECONFIGURATION); | 869 syncer::CONFIGURE_REASON_RECONFIGURATION); |
| 870 } | 870 } |
| 871 | 871 |
| 872 NotifyObservers(); | 872 NotifyObservers(); |
| 873 } | 873 } |
| 874 | 874 |
| 875 void ProfileSyncService::OnEncryptedTypesChanged( | 875 void ProfileSyncService::OnEncryptedTypesChanged( |
| 876 syncable::ModelTypeSet encrypted_types, | 876 syncer::ModelTypeSet encrypted_types, |
| 877 bool encrypt_everything) { | 877 bool encrypt_everything) { |
| 878 encrypted_types_ = encrypted_types; | 878 encrypted_types_ = encrypted_types; |
| 879 encrypt_everything_ = encrypt_everything; | 879 encrypt_everything_ = encrypt_everything; |
| 880 DVLOG(1) << "Encrypted types changed to " | 880 DVLOG(1) << "Encrypted types changed to " |
| 881 << syncable::ModelTypeSetToString(encrypted_types_) | 881 << syncer::ModelTypeSetToString(encrypted_types_) |
| 882 << " (encrypt everything is set to " | 882 << " (encrypt everything is set to " |
| 883 << (encrypt_everything_ ? "true" : "false") << ")"; | 883 << (encrypt_everything_ ? "true" : "false") << ")"; |
| 884 DCHECK(encrypted_types_.Has(syncable::PASSWORDS)); | 884 DCHECK(encrypted_types_.Has(syncer::PASSWORDS)); |
| 885 } | 885 } |
| 886 | 886 |
| 887 void ProfileSyncService::OnEncryptionComplete() { | 887 void ProfileSyncService::OnEncryptionComplete() { |
| 888 DVLOG(1) << "Encryption complete"; | 888 DVLOG(1) << "Encryption complete"; |
| 889 if (encryption_pending_ && encrypt_everything_) { | 889 if (encryption_pending_ && encrypt_everything_) { |
| 890 encryption_pending_ = false; | 890 encryption_pending_ = false; |
| 891 // This is to nudge the integration tests when encryption is | 891 // This is to nudge the integration tests when encryption is |
| 892 // finished. | 892 // finished. |
| 893 NotifyObservers(); | 893 NotifyObservers(); |
| 894 } | 894 } |
| 895 } | 895 } |
| 896 | 896 |
| 897 void ProfileSyncService::OnMigrationNeededForTypes( | 897 void ProfileSyncService::OnMigrationNeededForTypes( |
| 898 syncable::ModelTypeSet types) { | 898 syncer::ModelTypeSet types) { |
| 899 DCHECK(backend_initialized_); | 899 DCHECK(backend_initialized_); |
| 900 DCHECK(data_type_manager_.get()); | 900 DCHECK(data_type_manager_.get()); |
| 901 | 901 |
| 902 // Migrator must be valid, because we don't sync until it is created and this | 902 // Migrator must be valid, because we don't sync until it is created and this |
| 903 // callback originates from a sync cycle. | 903 // callback originates from a sync cycle. |
| 904 migrator_->MigrateTypes(types); | 904 migrator_->MigrateTypes(types); |
| 905 } | 905 } |
| 906 | 906 |
| 907 void ProfileSyncService::OnActionableError(const SyncProtocolError& error) { | 907 void ProfileSyncService::OnActionableError(const SyncProtocolError& error) { |
| 908 last_actionable_error_ = error; | 908 last_actionable_error_ = error; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 | 1012 |
| 1013 base::TimeDelta last_synced = base::Time::Now() - last_synced_time_; | 1013 base::TimeDelta last_synced = base::Time::Now() - last_synced_time_; |
| 1014 | 1014 |
| 1015 if (last_synced < base::TimeDelta::FromMinutes(1)) | 1015 if (last_synced < base::TimeDelta::FromMinutes(1)) |
| 1016 return l10n_util::GetStringUTF16(IDS_SYNC_TIME_JUST_NOW); | 1016 return l10n_util::GetStringUTF16(IDS_SYNC_TIME_JUST_NOW); |
| 1017 | 1017 |
| 1018 return TimeFormat::TimeElapsed(last_synced); | 1018 return TimeFormat::TimeElapsed(last_synced); |
| 1019 } | 1019 } |
| 1020 | 1020 |
| 1021 void ProfileSyncService::UpdateSelectedTypesHistogram( | 1021 void ProfileSyncService::UpdateSelectedTypesHistogram( |
| 1022 bool sync_everything, const syncable::ModelTypeSet chosen_types) const { | 1022 bool sync_everything, const syncer::ModelTypeSet chosen_types) const { |
| 1023 if (!HasSyncSetupCompleted() || | 1023 if (!HasSyncSetupCompleted() || |
| 1024 sync_everything != sync_prefs_.HasKeepEverythingSynced()) { | 1024 sync_everything != sync_prefs_.HasKeepEverythingSynced()) { |
| 1025 UMA_HISTOGRAM_BOOLEAN("Sync.SyncEverything", sync_everything); | 1025 UMA_HISTOGRAM_BOOLEAN("Sync.SyncEverything", sync_everything); |
| 1026 } | 1026 } |
| 1027 | 1027 |
| 1028 // Only log the data types that are shown in the sync settings ui. | 1028 // Only log the data types that are shown in the sync settings ui. |
| 1029 const syncable::ModelType model_types[] = { | 1029 const syncer::ModelType model_types[] = { |
| 1030 syncable::APPS, | 1030 syncer::APPS, |
| 1031 syncable::AUTOFILL, | 1031 syncer::AUTOFILL, |
| 1032 syncable::BOOKMARKS, | 1032 syncer::BOOKMARKS, |
| 1033 syncable::EXTENSIONS, | 1033 syncer::EXTENSIONS, |
| 1034 syncable::PASSWORDS, | 1034 syncer::PASSWORDS, |
| 1035 syncable::PREFERENCES, | 1035 syncer::PREFERENCES, |
| 1036 syncable::SESSIONS, | 1036 syncer::SESSIONS, |
| 1037 syncable::THEMES, | 1037 syncer::THEMES, |
| 1038 syncable::TYPED_URLS | 1038 syncer::TYPED_URLS |
| 1039 }; | 1039 }; |
| 1040 | 1040 |
| 1041 const browser_sync::user_selectable_type::UserSelectableSyncType | 1041 const browser_sync::user_selectable_type::UserSelectableSyncType |
| 1042 user_selectable_types[] = { | 1042 user_selectable_types[] = { |
| 1043 browser_sync::user_selectable_type::APPS, | 1043 browser_sync::user_selectable_type::APPS, |
| 1044 browser_sync::user_selectable_type::AUTOFILL, | 1044 browser_sync::user_selectable_type::AUTOFILL, |
| 1045 browser_sync::user_selectable_type::BOOKMARKS, | 1045 browser_sync::user_selectable_type::BOOKMARKS, |
| 1046 browser_sync::user_selectable_type::EXTENSIONS, | 1046 browser_sync::user_selectable_type::EXTENSIONS, |
| 1047 browser_sync::user_selectable_type::PASSWORDS, | 1047 browser_sync::user_selectable_type::PASSWORDS, |
| 1048 browser_sync::user_selectable_type::PREFERENCES, | 1048 browser_sync::user_selectable_type::PREFERENCES, |
| 1049 browser_sync::user_selectable_type::SESSIONS, | 1049 browser_sync::user_selectable_type::SESSIONS, |
| 1050 browser_sync::user_selectable_type::THEMES, | 1050 browser_sync::user_selectable_type::THEMES, |
| 1051 browser_sync::user_selectable_type::TYPED_URLS | 1051 browser_sync::user_selectable_type::TYPED_URLS |
| 1052 }; | 1052 }; |
| 1053 | 1053 |
| 1054 COMPILE_ASSERT(17 == syncable::MODEL_TYPE_COUNT, | 1054 COMPILE_ASSERT(17 == syncer::MODEL_TYPE_COUNT, UpdateCustomConfigHistogram); |
| 1055 UpdateCustomConfigHistogram); | |
| 1056 COMPILE_ASSERT(arraysize(model_types) == | 1055 COMPILE_ASSERT(arraysize(model_types) == |
| 1057 browser_sync::user_selectable_type::SELECTABLE_DATATYPE_COUNT, | 1056 browser_sync::user_selectable_type::SELECTABLE_DATATYPE_COUNT, |
| 1058 UpdateCustomConfigHistogram); | 1057 UpdateCustomConfigHistogram); |
| 1059 COMPILE_ASSERT(arraysize(model_types) == arraysize(user_selectable_types), | 1058 COMPILE_ASSERT(arraysize(model_types) == arraysize(user_selectable_types), |
| 1060 UpdateCustomConfigHistogram); | 1059 UpdateCustomConfigHistogram); |
| 1061 | 1060 |
| 1062 if (!sync_everything) { | 1061 if (!sync_everything) { |
| 1063 const syncable::ModelTypeSet current_types = GetPreferredDataTypes(); | 1062 const syncer::ModelTypeSet current_types = GetPreferredDataTypes(); |
| 1064 for (size_t i = 0; i < arraysize(model_types); ++i) { | 1063 for (size_t i = 0; i < arraysize(model_types); ++i) { |
| 1065 const syncable::ModelType type = model_types[i]; | 1064 const syncer::ModelType type = model_types[i]; |
| 1066 if (chosen_types.Has(type) && | 1065 if (chosen_types.Has(type) && |
| 1067 (!HasSyncSetupCompleted() || !current_types.Has(type))) { | 1066 (!HasSyncSetupCompleted() || !current_types.Has(type))) { |
| 1068 // Selected type has changed - log it. | 1067 // Selected type has changed - log it. |
| 1069 UMA_HISTOGRAM_ENUMERATION( | 1068 UMA_HISTOGRAM_ENUMERATION( |
| 1070 "Sync.CustomSync", | 1069 "Sync.CustomSync", |
| 1071 user_selectable_types[i], | 1070 user_selectable_types[i], |
| 1072 browser_sync::user_selectable_type::SELECTABLE_DATATYPE_COUNT + 1); | 1071 browser_sync::user_selectable_type::SELECTABLE_DATATYPE_COUNT + 1); |
| 1073 } | 1072 } |
| 1074 } | 1073 } |
| 1075 } | 1074 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1086 std::string bootstrap_token; | 1085 std::string bootstrap_token; |
| 1087 if (!temp_cryptographer.AddKey(key_params)) { | 1086 if (!temp_cryptographer.AddKey(key_params)) { |
| 1088 NOTREACHED() << "Failed to add key to cryptographer."; | 1087 NOTREACHED() << "Failed to add key to cryptographer."; |
| 1089 } | 1088 } |
| 1090 temp_cryptographer.GetBootstrapToken(&bootstrap_token); | 1089 temp_cryptographer.GetBootstrapToken(&bootstrap_token); |
| 1091 sync_prefs_.SetSpareBootstrapToken(bootstrap_token); | 1090 sync_prefs_.SetSpareBootstrapToken(bootstrap_token); |
| 1092 } | 1091 } |
| 1093 #endif | 1092 #endif |
| 1094 | 1093 |
| 1095 void ProfileSyncService::OnUserChoseDatatypes(bool sync_everything, | 1094 void ProfileSyncService::OnUserChoseDatatypes(bool sync_everything, |
| 1096 syncable::ModelTypeSet chosen_types) { | 1095 syncer::ModelTypeSet chosen_types) { |
| 1097 if (!backend_.get() && !HasUnrecoverableError()) { | 1096 if (!backend_.get() && !HasUnrecoverableError()) { |
| 1098 NOTREACHED(); | 1097 NOTREACHED(); |
| 1099 return; | 1098 return; |
| 1100 } | 1099 } |
| 1101 | 1100 |
| 1102 UpdateSelectedTypesHistogram(sync_everything, chosen_types); | 1101 UpdateSelectedTypesHistogram(sync_everything, chosen_types); |
| 1103 sync_prefs_.SetKeepEverythingSynced(sync_everything); | 1102 sync_prefs_.SetKeepEverythingSynced(sync_everything); |
| 1104 | 1103 |
| 1105 failed_datatypes_handler_.OnUserChoseDatatypes(); | 1104 failed_datatypes_handler_.OnUserChoseDatatypes(); |
| 1106 ChangePreferredDataTypes(chosen_types); | 1105 ChangePreferredDataTypes(chosen_types); |
| 1107 AcknowledgeSyncedTypes(); | 1106 AcknowledgeSyncedTypes(); |
| 1108 NotifyObservers(); | 1107 NotifyObservers(); |
| 1109 } | 1108 } |
| 1110 | 1109 |
| 1111 void ProfileSyncService::ChangePreferredDataTypes( | 1110 void ProfileSyncService::ChangePreferredDataTypes( |
| 1112 syncable::ModelTypeSet preferred_types) { | 1111 syncer::ModelTypeSet preferred_types) { |
| 1113 | 1112 |
| 1114 DVLOG(1) << "ChangePreferredDataTypes invoked"; | 1113 DVLOG(1) << "ChangePreferredDataTypes invoked"; |
| 1115 const syncable::ModelTypeSet registered_types = GetRegisteredDataTypes(); | 1114 const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); |
| 1116 const syncable::ModelTypeSet registered_preferred_types = | 1115 const syncer::ModelTypeSet registered_preferred_types = |
| 1117 Intersection(registered_types, preferred_types); | 1116 Intersection(registered_types, preferred_types); |
| 1118 sync_prefs_.SetPreferredDataTypes(registered_types, | 1117 sync_prefs_.SetPreferredDataTypes(registered_types, |
| 1119 registered_preferred_types); | 1118 registered_preferred_types); |
| 1120 | 1119 |
| 1121 // Now reconfigure the DTM. | 1120 // Now reconfigure the DTM. |
| 1122 ReconfigureDatatypeManager(); | 1121 ReconfigureDatatypeManager(); |
| 1123 } | 1122 } |
| 1124 | 1123 |
| 1125 syncable::ModelTypeSet ProfileSyncService::GetPreferredDataTypes() const { | 1124 syncer::ModelTypeSet ProfileSyncService::GetPreferredDataTypes() const { |
| 1126 const syncable::ModelTypeSet registered_types = GetRegisteredDataTypes(); | 1125 const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); |
| 1127 const syncable::ModelTypeSet preferred_types = | 1126 const syncer::ModelTypeSet preferred_types = |
| 1128 sync_prefs_.GetPreferredDataTypes(registered_types); | 1127 sync_prefs_.GetPreferredDataTypes(registered_types); |
| 1129 const syncable::ModelTypeSet failed_types = | 1128 const syncer::ModelTypeSet failed_types = |
| 1130 failed_datatypes_handler_.GetFailedTypes(); | 1129 failed_datatypes_handler_.GetFailedTypes(); |
| 1131 return Difference(preferred_types, failed_types); | 1130 return Difference(preferred_types, failed_types); |
| 1132 } | 1131 } |
| 1133 | 1132 |
| 1134 syncable::ModelTypeSet ProfileSyncService::GetRegisteredDataTypes() const { | 1133 syncer::ModelTypeSet ProfileSyncService::GetRegisteredDataTypes() const { |
| 1135 syncable::ModelTypeSet registered_types; | 1134 syncer::ModelTypeSet registered_types; |
| 1136 // The data_type_controllers_ are determined by command-line flags; that's | 1135 // The data_type_controllers_ are determined by command-line flags; that's |
| 1137 // effectively what controls the values returned here. | 1136 // effectively what controls the values returned here. |
| 1138 for (DataTypeController::TypeMap::const_iterator it = | 1137 for (DataTypeController::TypeMap::const_iterator it = |
| 1139 data_type_controllers_.begin(); | 1138 data_type_controllers_.begin(); |
| 1140 it != data_type_controllers_.end(); ++it) { | 1139 it != data_type_controllers_.end(); ++it) { |
| 1141 registered_types.Put(it->first); | 1140 registered_types.Put(it->first); |
| 1142 } | 1141 } |
| 1143 return registered_types; | 1142 return registered_types; |
| 1144 } | 1143 } |
| 1145 | 1144 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1177 | 1176 |
| 1178 // We create the migrator at the same time. | 1177 // We create the migrator at the same time. |
| 1179 migrator_.reset( | 1178 migrator_.reset( |
| 1180 new browser_sync::BackendMigrator( | 1179 new browser_sync::BackendMigrator( |
| 1181 profile_->GetDebugName(), GetUserShare(), | 1180 profile_->GetDebugName(), GetUserShare(), |
| 1182 this, data_type_manager_.get(), | 1181 this, data_type_manager_.get(), |
| 1183 base::Bind(&ProfileSyncService::StartSyncingWithServer, | 1182 base::Bind(&ProfileSyncService::StartSyncingWithServer, |
| 1184 base::Unretained(this)))); | 1183 base::Unretained(this)))); |
| 1185 } | 1184 } |
| 1186 | 1185 |
| 1187 const syncable::ModelTypeSet types = GetPreferredDataTypes(); | 1186 const syncer::ModelTypeSet types = GetPreferredDataTypes(); |
| 1188 if (IsPassphraseRequiredForDecryption()) { | 1187 if (IsPassphraseRequiredForDecryption()) { |
| 1189 // We need a passphrase still. We don't bother to attempt to configure | 1188 // We need a passphrase still. We don't bother to attempt to configure |
| 1190 // until we receive an OnPassphraseAccepted (which triggers a configure). | 1189 // until we receive an OnPassphraseAccepted (which triggers a configure). |
| 1191 DVLOG(1) << "ProfileSyncService::ConfigureDataTypeManager bailing out " | 1190 DVLOG(1) << "ProfileSyncService::ConfigureDataTypeManager bailing out " |
| 1192 << "because a passphrase required"; | 1191 << "because a passphrase required"; |
| 1193 NotifyObservers(); | 1192 NotifyObservers(); |
| 1194 return; | 1193 return; |
| 1195 } | 1194 } |
| 1196 syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; | 1195 syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; |
| 1197 if (!HasSyncSetupCompleted()) { | 1196 if (!HasSyncSetupCompleted()) { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1308 ModelSafeGroupToString(routing_info[type])); | 1307 ModelSafeGroupToString(routing_info[type])); |
| 1309 } else { | 1308 } else { |
| 1310 type_status->SetString("status", "warning"); | 1309 type_status->SetString("status", "warning"); |
| 1311 type_status->SetString("value", "Disabled by User"); | 1310 type_status->SetString("value", "Disabled by User"); |
| 1312 } | 1311 } |
| 1313 } | 1312 } |
| 1314 return result; | 1313 return result; |
| 1315 } | 1314 } |
| 1316 | 1315 |
| 1317 void ProfileSyncService::ActivateDataType( | 1316 void ProfileSyncService::ActivateDataType( |
| 1318 syncable::ModelType type, syncer::ModelSafeGroup group, | 1317 syncer::ModelType type, syncer::ModelSafeGroup group, |
| 1319 ChangeProcessor* change_processor) { | 1318 ChangeProcessor* change_processor) { |
| 1320 if (!backend_.get()) { | 1319 if (!backend_.get()) { |
| 1321 NOTREACHED(); | 1320 NOTREACHED(); |
| 1322 return; | 1321 return; |
| 1323 } | 1322 } |
| 1324 DCHECK(backend_initialized_); | 1323 DCHECK(backend_initialized_); |
| 1325 backend_->ActivateDataType(type, group, change_processor); | 1324 backend_->ActivateDataType(type, group, change_processor); |
| 1326 } | 1325 } |
| 1327 | 1326 |
| 1328 void ProfileSyncService::DeactivateDataType(syncable::ModelType type) { | 1327 void ProfileSyncService::DeactivateDataType(syncer::ModelType type) { |
| 1329 if (!backend_.get()) | 1328 if (!backend_.get()) |
| 1330 return; | 1329 return; |
| 1331 backend_->DeactivateDataType(type); | 1330 backend_->DeactivateDataType(type); |
| 1332 } | 1331 } |
| 1333 | 1332 |
| 1334 void ProfileSyncService::ConsumeCachedPassphraseIfPossible() { | 1333 void ProfileSyncService::ConsumeCachedPassphraseIfPossible() { |
| 1335 // If no cached passphrase, or sync backend hasn't started up yet, just exit. | 1334 // If no cached passphrase, or sync backend hasn't started up yet, just exit. |
| 1336 // If the backend isn't running yet, OnBackendInitialized() will call this | 1335 // If the backend isn't running yet, OnBackendInitialized() will call this |
| 1337 // method again after the backend starts up. | 1336 // method again after the backend starts up. |
| 1338 if (cached_passphrase_.empty() || !sync_initialized()) | 1337 if (cached_passphrase_.empty() || !sync_initialized()) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1412 // initialized (via IsEncryptedDatatypeEnabled and | 1411 // initialized (via IsEncryptedDatatypeEnabled and |
| 1413 // IsPassphraseRequiredForDecryption). | 1412 // IsPassphraseRequiredForDecryption). |
| 1414 return encryption_pending_; | 1413 return encryption_pending_; |
| 1415 } | 1414 } |
| 1416 | 1415 |
| 1417 bool ProfileSyncService::EncryptEverythingEnabled() const { | 1416 bool ProfileSyncService::EncryptEverythingEnabled() const { |
| 1418 DCHECK(backend_initialized_); | 1417 DCHECK(backend_initialized_); |
| 1419 return encrypt_everything_ || encryption_pending_; | 1418 return encrypt_everything_ || encryption_pending_; |
| 1420 } | 1419 } |
| 1421 | 1420 |
| 1422 syncable::ModelTypeSet ProfileSyncService::GetEncryptedDataTypes() const { | 1421 syncer::ModelTypeSet ProfileSyncService::GetEncryptedDataTypes() const { |
| 1423 DCHECK(encrypted_types_.Has(syncable::PASSWORDS)); | 1422 DCHECK(encrypted_types_.Has(syncer::PASSWORDS)); |
| 1424 // We may be called during the setup process before we're | 1423 // We may be called during the setup process before we're |
| 1425 // initialized. In this case, we default to the sensitive types. | 1424 // initialized. In this case, we default to the sensitive types. |
| 1426 return encrypted_types_; | 1425 return encrypted_types_; |
| 1427 } | 1426 } |
| 1428 | 1427 |
| 1429 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { | 1428 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { |
| 1430 NotifyObservers(); | 1429 NotifyObservers(); |
| 1431 if (is_sync_managed) { | 1430 if (is_sync_managed) { |
| 1432 DisableForUser(); | 1431 DisableForUser(); |
| 1433 } else if (HasSyncSetupCompleted() && | 1432 } else if (HasSyncSetupCompleted() && |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1486 configure_status_ != DataTypeManager::PARTIAL_SUCCESS) { | 1485 configure_status_ != DataTypeManager::PARTIAL_SUCCESS) { |
| 1487 // Something catastrophic had happened. We should only have one | 1486 // Something catastrophic had happened. We should only have one |
| 1488 // error representing it. | 1487 // error representing it. |
| 1489 DCHECK_EQ(result->failed_data_types.size(), | 1488 DCHECK_EQ(result->failed_data_types.size(), |
| 1490 static_cast<unsigned int>(1)); | 1489 static_cast<unsigned int>(1)); |
| 1491 syncer::SyncError error = result->failed_data_types.front(); | 1490 syncer::SyncError error = result->failed_data_types.front(); |
| 1492 DCHECK(error.IsSet()); | 1491 DCHECK(error.IsSet()); |
| 1493 std::string message = | 1492 std::string message = |
| 1494 "Sync configuration failed with status " + | 1493 "Sync configuration failed with status " + |
| 1495 DataTypeManager::ConfigureStatusToString(configure_status_) + | 1494 DataTypeManager::ConfigureStatusToString(configure_status_) + |
| 1496 " during " + syncable::ModelTypeToString(error.type()) + | 1495 " during " + syncer::ModelTypeToString(error.type()) + |
| 1497 ": " + error.message(); | 1496 ": " + error.message(); |
| 1498 LOG(ERROR) << "ProfileSyncService error: " | 1497 LOG(ERROR) << "ProfileSyncService error: " |
| 1499 << message; | 1498 << message; |
| 1500 OnInternalUnrecoverableError(error.location(), | 1499 OnInternalUnrecoverableError(error.location(), |
| 1501 message, | 1500 message, |
| 1502 true, | 1501 true, |
| 1503 ERROR_REASON_CONFIGURATION_FAILURE); | 1502 ERROR_REASON_CONFIGURATION_FAILURE); |
| 1504 return; | 1503 return; |
| 1505 } | 1504 } |
| 1506 | 1505 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1723 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine
d-behaviour-after-directly-calling-the-destru. | 1722 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine
d-behaviour-after-directly-calling-the-destru. |
| 1724 ProfileSyncService* old_this = this; | 1723 ProfileSyncService* old_this = this; |
| 1725 this->~ProfileSyncService(); | 1724 this->~ProfileSyncService(); |
| 1726 new(old_this) ProfileSyncService( | 1725 new(old_this) ProfileSyncService( |
| 1727 new ProfileSyncComponentsFactoryImpl(profile, | 1726 new ProfileSyncComponentsFactoryImpl(profile, |
| 1728 CommandLine::ForCurrentProcess()), | 1727 CommandLine::ForCurrentProcess()), |
| 1729 profile, | 1728 profile, |
| 1730 signin, | 1729 signin, |
| 1731 behavior); | 1730 behavior); |
| 1732 } | 1731 } |
| OLD | NEW |