| 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 int port, | 369 int port, |
| 370 bool use_ssl, | 370 bool use_ssl, |
| 371 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 371 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
| 372 scoped_ptr<HttpPostProviderFactory> post_factory, | 372 scoped_ptr<HttpPostProviderFactory> post_factory, |
| 373 const std::vector<ModelSafeWorker*>& workers, | 373 const std::vector<ModelSafeWorker*>& workers, |
| 374 ExtensionsActivityMonitor* extensions_activity_monitor, | 374 ExtensionsActivityMonitor* extensions_activity_monitor, |
| 375 SyncManager::ChangeDelegate* change_delegate, | 375 SyncManager::ChangeDelegate* change_delegate, |
| 376 const SyncCredentials& credentials, | 376 const SyncCredentials& credentials, |
| 377 scoped_ptr<SyncNotifier> sync_notifier, | 377 scoped_ptr<SyncNotifier> sync_notifier, |
| 378 const std::string& restored_key_for_bootstrapping, | 378 const std::string& restored_key_for_bootstrapping, |
| 379 const std::string& restored_keystore_key_for_bootstrapping, |
| 379 bool keystore_encryption_enabled, | 380 bool keystore_encryption_enabled, |
| 380 scoped_ptr<InternalComponentsFactory> internal_components_factory, | 381 scoped_ptr<InternalComponentsFactory> internal_components_factory, |
| 381 Encryptor* encryptor, | 382 Encryptor* encryptor, |
| 382 UnrecoverableErrorHandler* unrecoverable_error_handler, | 383 UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 383 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { | 384 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { |
| 384 CHECK(!initialized_); | 385 CHECK(!initialized_); |
| 385 DCHECK(thread_checker_.CalledOnValidThread()); | 386 DCHECK(thread_checker_.CalledOnValidThread()); |
| 386 DCHECK(post_factory.get()); | 387 DCHECK(post_factory.get()); |
| 387 DCHECK(!credentials.email.empty()); | 388 DCHECK(!credentials.email.empty()); |
| 388 DCHECK(!credentials.sync_token.empty()); | 389 DCHECK(!credentials.sync_token.empty()); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 observing_ip_address_changes_ = true; | 479 observing_ip_address_changes_ = true; |
| 479 | 480 |
| 480 UpdateCredentials(credentials); | 481 UpdateCredentials(credentials); |
| 481 | 482 |
| 482 // Cryptographer should only be accessed while holding a | 483 // Cryptographer should only be accessed while holding a |
| 483 // transaction. Grabbing the user share for the transaction | 484 // transaction. Grabbing the user share for the transaction |
| 484 // checks the initialization state, so this must come after | 485 // checks the initialization state, so this must come after |
| 485 // |initialized_| is set to true. | 486 // |initialized_| is set to true. |
| 486 ReadTransaction trans(FROM_HERE, GetUserShare()); | 487 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 487 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping); | 488 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping); |
| 489 trans.GetCryptographer()->BootstrapKeystoreKey( |
| 490 restored_keystore_key_for_bootstrapping); |
| 488 trans.GetCryptographer()->AddObserver(this); | 491 trans.GetCryptographer()->AddObserver(this); |
| 489 | 492 |
| 490 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 493 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 491 OnInitializationComplete( | 494 OnInitializationComplete( |
| 492 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), | 495 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), |
| 493 true, InitialSyncEndedTypes())); | 496 true, InitialSyncEndedTypes())); |
| 494 return true; | 497 return true; |
| 495 } | 498 } |
| 496 | 499 |
| 497 void SyncManagerImpl::RefreshNigori(const std::string& chrome_version, | 500 void SyncManagerImpl::RefreshNigori(const std::string& chrome_version, |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 ReadNode node(&trans); | 1058 ReadNode node(&trans); |
| 1056 if (node.InitByTagLookup(kNigoriTag) != BaseNode::INIT_OK) { | 1059 if (node.InitByTagLookup(kNigoriTag) != BaseNode::INIT_OK) { |
| 1057 // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. | 1060 // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. |
| 1058 NOTREACHED(); | 1061 NOTREACHED(); |
| 1059 return false; | 1062 return false; |
| 1060 } | 1063 } |
| 1061 | 1064 |
| 1062 return node.GetNigoriSpecifics().using_explicit_passphrase(); | 1065 return node.GetNigoriSpecifics().using_explicit_passphrase(); |
| 1063 } | 1066 } |
| 1064 | 1067 |
| 1068 bool SyncManagerImpl::GetKeystoreKeyBootstrapToken(std::string* token) { |
| 1069 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 1070 return trans.GetCryptographer()->GetKeystoreKeyBootstrapToken(token); |
| 1071 } |
| 1072 |
| 1065 void SyncManagerImpl::RefreshEncryption() { | 1073 void SyncManagerImpl::RefreshEncryption() { |
| 1066 DCHECK(initialized_); | 1074 DCHECK(initialized_); |
| 1067 | 1075 |
| 1068 WriteTransaction trans(FROM_HERE, GetUserShare()); | 1076 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 1069 WriteNode node(&trans); | 1077 WriteNode node(&trans); |
| 1070 if (node.InitByTagLookup(kNigoriTag) != BaseNode::INIT_OK) { | 1078 if (node.InitByTagLookup(kNigoriTag) != BaseNode::INIT_OK) { |
| 1071 NOTREACHED() << "Unable to set encrypted datatypes because Nigori node not " | 1079 NOTREACHED() << "Unable to set encrypted datatypes because Nigori node not " |
| 1072 << "found."; | 1080 << "found."; |
| 1073 return; | 1081 return; |
| 1074 } | 1082 } |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1498 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); | 1506 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); |
| 1499 } | 1507 } |
| 1500 | 1508 |
| 1501 if (!initialized_) { | 1509 if (!initialized_) { |
| 1502 LOG(INFO) << "OnSyncCycleCompleted not sent because sync api is not " | 1510 LOG(INFO) << "OnSyncCycleCompleted not sent because sync api is not " |
| 1503 << "initialized"; | 1511 << "initialized"; |
| 1504 return; | 1512 return; |
| 1505 } | 1513 } |
| 1506 | 1514 |
| 1507 if (!event.snapshot.has_more_to_sync()) { | 1515 if (!event.snapshot.has_more_to_sync()) { |
| 1508 // To account for a nigori node arriving with stale/bad data, we ensure | 1516 { |
| 1509 // that the nigori node is up to date at the end of each cycle. | 1517 // To account for a nigori node arriving with stale/bad data, we ensure |
| 1510 WriteTransaction trans(FROM_HERE, GetUserShare()); | 1518 // that the nigori node is up to date at the end of each cycle. |
| 1511 WriteNode nigori_node(&trans); | 1519 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 1512 if (nigori_node.InitByTagLookup(kNigoriTag) == BaseNode::INIT_OK) { | 1520 WriteNode nigori_node(&trans); |
| 1513 Cryptographer* cryptographer = trans.GetCryptographer(); | 1521 if (nigori_node.InitByTagLookup(kNigoriTag) == BaseNode::INIT_OK) { |
| 1514 UpdateNigoriEncryptionState(cryptographer, &nigori_node); | 1522 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1523 UpdateNigoriEncryptionState(cryptographer, &nigori_node); |
| 1524 } |
| 1515 } | 1525 } |
| 1516 | 1526 |
| 1517 DVLOG(1) << "Sending OnSyncCycleCompleted"; | 1527 DVLOG(1) << "Sending OnSyncCycleCompleted"; |
| 1518 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1528 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1519 OnSyncCycleCompleted(event.snapshot)); | 1529 OnSyncCycleCompleted(event.snapshot)); |
| 1520 } | 1530 } |
| 1521 | 1531 |
| 1522 // This is here for tests, which are still using p2p notifications. | 1532 // This is here for tests, which are still using p2p notifications. |
| 1523 // | 1533 // |
| 1524 // TODO(chron): Consider changing this back to track has_more_to_sync | 1534 // TODO(chron): Consider changing this back to track has_more_to_sync |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1869 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1879 int SyncManagerImpl::GetDefaultNudgeDelay() { |
| 1870 return kDefaultNudgeDelayMilliseconds; | 1880 return kDefaultNudgeDelayMilliseconds; |
| 1871 } | 1881 } |
| 1872 | 1882 |
| 1873 // static. | 1883 // static. |
| 1874 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1884 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
| 1875 return kPreferencesNudgeDelayMilliseconds; | 1885 return kPreferencesNudgeDelayMilliseconds; |
| 1876 } | 1886 } |
| 1877 | 1887 |
| 1878 } // namespace syncer | 1888 } // namespace syncer |
| OLD | NEW |