Chromium Code Reviews| 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 "sync/internal_api/sync_manager_impl.h" | 5 #include "sync/internal_api/sync_manager_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 #include "sync/internal_api/public/base/model_type_state_map.h" | 24 #include "sync/internal_api/public/base/model_type_state_map.h" |
| 25 #include "sync/internal_api/public/base_node.h" | 25 #include "sync/internal_api/public/base_node.h" |
| 26 #include "sync/internal_api/public/configure_reason.h" | 26 #include "sync/internal_api/public/configure_reason.h" |
| 27 #include "sync/internal_api/public/engine/polling_constants.h" | 27 #include "sync/internal_api/public/engine/polling_constants.h" |
| 28 #include "sync/internal_api/public/http_post_provider_factory.h" | 28 #include "sync/internal_api/public/http_post_provider_factory.h" |
| 29 #include "sync/internal_api/public/internal_components_factory.h" | 29 #include "sync/internal_api/public/internal_components_factory.h" |
| 30 #include "sync/internal_api/public/read_node.h" | 30 #include "sync/internal_api/public/read_node.h" |
| 31 #include "sync/internal_api/public/read_transaction.h" | 31 #include "sync/internal_api/public/read_transaction.h" |
| 32 #include "sync/internal_api/public/user_share.h" | 32 #include "sync/internal_api/public/user_share.h" |
| 33 #include "sync/internal_api/public/util/experiments.h" | 33 #include "sync/internal_api/public/util/experiments.h" |
| 34 #include "sync/internal_api/public/util/sync_string_conversions.h" | |
| 34 #include "sync/internal_api/public/write_node.h" | 35 #include "sync/internal_api/public/write_node.h" |
| 35 #include "sync/internal_api/public/write_transaction.h" | 36 #include "sync/internal_api/public/write_transaction.h" |
| 36 #include "sync/internal_api/syncapi_internal.h" | 37 #include "sync/internal_api/syncapi_internal.h" |
| 37 #include "sync/internal_api/syncapi_server_connection_manager.h" | 38 #include "sync/internal_api/syncapi_server_connection_manager.h" |
| 38 #include "sync/js/js_arg_list.h" | 39 #include "sync/js/js_arg_list.h" |
| 39 #include "sync/js/js_event_details.h" | 40 #include "sync/js/js_event_details.h" |
| 40 #include "sync/js/js_event_handler.h" | 41 #include "sync/js/js_event_handler.h" |
| 41 #include "sync/js/js_reply_handler.h" | 42 #include "sync/js/js_reply_handler.h" |
| 42 #include "sync/notifier/invalidation_util.h" | 43 #include "sync/notifier/invalidation_util.h" |
| 43 #include "sync/notifier/invalidator.h" | 44 #include "sync/notifier/invalidator.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 case CONFIGURE_REASON_NEW_CLIENT: | 81 case CONFIGURE_REASON_NEW_CLIENT: |
| 81 return GetUpdatesCallerInfo::NEW_CLIENT; | 82 return GetUpdatesCallerInfo::NEW_CLIENT; |
| 82 case CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE: | 83 case CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE: |
| 83 return GetUpdatesCallerInfo::NEWLY_SUPPORTED_DATATYPE; | 84 return GetUpdatesCallerInfo::NEWLY_SUPPORTED_DATATYPE; |
| 84 default: | 85 default: |
| 85 NOTREACHED(); | 86 NOTREACHED(); |
| 86 } | 87 } |
| 87 return GetUpdatesCallerInfo::UNKNOWN; | 88 return GetUpdatesCallerInfo::UNKNOWN; |
| 88 } | 89 } |
| 89 | 90 |
| 91 std::string GetKeystoreMigrationTimeStr(base::Time migration_time) { | |
| 92 std::string migration_time_str; | |
| 93 if (migration_time.is_null()) | |
| 94 migration_time_str = "Not Migrated"; | |
| 95 else | |
| 96 migration_time_str = GetTimeDebugString(migration_time); | |
| 97 return migration_time_str; | |
| 98 } | |
| 99 | |
| 90 } // namespace | 100 } // namespace |
| 91 | 101 |
| 92 // A class to calculate nudge delays for types. | 102 // A class to calculate nudge delays for types. |
| 93 class NudgeStrategy { | 103 class NudgeStrategy { |
| 94 public: | 104 public: |
| 95 static TimeDelta GetNudgeDelayTimeDelta(const ModelType& model_type, | 105 static TimeDelta GetNudgeDelayTimeDelta(const ModelType& model_type, |
| 96 SyncManagerImpl* core) { | 106 SyncManagerImpl* core) { |
| 97 NudgeDelayStrategy delay_type = GetNudgeDelayStrategy(model_type); | 107 NudgeDelayStrategy delay_type = GetNudgeDelayStrategy(model_type); |
| 98 return GetNudgeDelayTimeDeltaFromType(delay_type, | 108 return GetNudgeDelayTimeDeltaFromType(delay_type, |
| 99 model_type, | 109 model_type, |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 SetJsEventHandler(event_handler); | 386 SetJsEventHandler(event_handler); |
| 377 | 387 |
| 378 AddObserver(&debug_info_event_listener_); | 388 AddObserver(&debug_info_event_listener_); |
| 379 | 389 |
| 380 database_path_ = database_location.Append( | 390 database_path_ = database_location.Append( |
| 381 syncable::Directory::kSyncDatabaseFilename); | 391 syncable::Directory::kSyncDatabaseFilename); |
| 382 encryptor_ = encryptor; | 392 encryptor_ = encryptor; |
| 383 unrecoverable_error_handler_ = unrecoverable_error_handler; | 393 unrecoverable_error_handler_ = unrecoverable_error_handler; |
| 384 report_unrecoverable_error_function_ = report_unrecoverable_error_function; | 394 report_unrecoverable_error_function_ = report_unrecoverable_error_function; |
| 385 | 395 |
| 396 allstatus_.SetHasKeystoreKey( | |
| 397 !restored_keystore_key_for_bootstrapping.empty()); | |
| 386 sync_encryption_handler_.reset(new SyncEncryptionHandlerImpl( | 398 sync_encryption_handler_.reset(new SyncEncryptionHandlerImpl( |
| 387 &share_, | 399 &share_, |
| 388 encryptor, | 400 encryptor, |
| 389 restored_key_for_bootstrapping, | 401 restored_key_for_bootstrapping, |
| 390 restored_keystore_key_for_bootstrapping)); | 402 restored_keystore_key_for_bootstrapping)); |
| 391 sync_encryption_handler_->AddObserver(this); | 403 sync_encryption_handler_->AddObserver(this); |
| 392 sync_encryption_handler_->AddObserver(&debug_info_event_listener_); | 404 sync_encryption_handler_->AddObserver(&debug_info_event_listener_); |
| 393 sync_encryption_handler_->AddObserver(&js_sync_encryption_handler_observer_); | 405 sync_encryption_handler_->AddObserver(&js_sync_encryption_handler_observer_); |
| 394 | 406 |
| 395 FilePath absolute_db_path(database_path_); | 407 FilePath absolute_db_path(database_path_); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 527 // Does nothing. | 539 // Does nothing. |
| 528 } | 540 } |
| 529 | 541 |
| 530 void SyncManagerImpl::OnPassphraseAccepted() { | 542 void SyncManagerImpl::OnPassphraseAccepted() { |
| 531 // Does nothing. | 543 // Does nothing. |
| 532 } | 544 } |
| 533 | 545 |
| 534 void SyncManagerImpl::OnBootstrapTokenUpdated( | 546 void SyncManagerImpl::OnBootstrapTokenUpdated( |
| 535 const std::string& bootstrap_token, | 547 const std::string& bootstrap_token, |
| 536 BootstrapTokenType type) { | 548 BootstrapTokenType type) { |
| 537 // Does nothing. | 549 if (type == KEYSTORE_BOOTSTRAP_TOKEN) |
| 550 allstatus_.SetHasKeystoreKey(true); | |
|
akalin
2012/09/17 18:07:20
SetHasKeystoreKey(type == KEYSTORE_BOOKSTRAP_TOKEN
Nicolas Zea
2012/09/17 21:00:24
Can't, that will set the boolean to false if the n
| |
| 538 } | 551 } |
| 539 | 552 |
| 540 void SyncManagerImpl::OnEncryptedTypesChanged(ModelTypeSet encrypted_types, | 553 void SyncManagerImpl::OnEncryptedTypesChanged(ModelTypeSet encrypted_types, |
| 541 bool encrypt_everything) { | 554 bool encrypt_everything) { |
| 542 allstatus_.SetEncryptedTypes(encrypted_types); | 555 allstatus_.SetEncryptedTypes(encrypted_types); |
| 543 } | 556 } |
| 544 | 557 |
| 545 void SyncManagerImpl::OnEncryptionComplete() { | 558 void SyncManagerImpl::OnEncryptionComplete() { |
| 546 // Does nothing. | 559 // Does nothing. |
| 547 } | 560 } |
| 548 | 561 |
| 549 void SyncManagerImpl::OnCryptographerStateChanged( | 562 void SyncManagerImpl::OnCryptographerStateChanged( |
| 550 Cryptographer* cryptographer) { | 563 Cryptographer* cryptographer) { |
| 551 allstatus_.SetCryptographerReady(cryptographer->is_ready()); | 564 allstatus_.SetCryptographerReady(cryptographer->is_ready()); |
| 552 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); | 565 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); |
| 566 allstatus_.SetKeystoreMigrationTime( | |
| 567 GetKeystoreMigrationTimeStr( | |
| 568 sync_encryption_handler_->GetKeystoreMigrationTime())); | |
| 553 } | 569 } |
| 554 | 570 |
| 555 void SyncManagerImpl::OnPassphraseTypeChanged(PassphraseType type) { | 571 void SyncManagerImpl::OnPassphraseTypeChanged(PassphraseType type) { |
| 556 // Does nothing. | 572 allstatus_.SetPassphraseType(PassphraseTypeToString(type)); |
| 573 allstatus_.SetKeystoreMigrationTime( | |
| 574 GetKeystoreMigrationTimeStr( | |
| 575 sync_encryption_handler_->GetKeystoreMigrationTime())); | |
| 557 } | 576 } |
| 558 | 577 |
| 559 void SyncManagerImpl::StartSyncingNormally( | 578 void SyncManagerImpl::StartSyncingNormally( |
| 560 const ModelSafeRoutingInfo& routing_info) { | 579 const ModelSafeRoutingInfo& routing_info) { |
| 561 // Start the sync scheduler. | 580 // Start the sync scheduler. |
| 562 // TODO(sync): We always want the newest set of routes when we switch back | 581 // TODO(sync): We always want the newest set of routes when we switch back |
| 563 // to normal mode. Figure out how to enforce set_routing_info is always | 582 // to normal mode. Figure out how to enforce set_routing_info is always |
| 564 // appropriately set and that it's only modified when switching to normal | 583 // appropriately set and that it's only modified when switching to normal |
| 565 // mode. | 584 // mode. |
| 566 DCHECK(thread_checker_.CalledOnValidThread()); | 585 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1346 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1365 int SyncManagerImpl::GetDefaultNudgeDelay() { |
| 1347 return kDefaultNudgeDelayMilliseconds; | 1366 return kDefaultNudgeDelayMilliseconds; |
| 1348 } | 1367 } |
| 1349 | 1368 |
| 1350 // static. | 1369 // static. |
| 1351 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1370 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
| 1352 return kPreferencesNudgeDelayMilliseconds; | 1371 return kPreferencesNudgeDelayMilliseconds; |
| 1353 } | 1372 } |
| 1354 | 1373 |
| 1355 } // namespace syncer | 1374 } // namespace syncer |
| OLD | NEW |