OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/engine/syncapi.h" | 5 #include "chrome/browser/sync/engine/syncapi.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <bitset> | 8 #include <bitset> |
9 #include <iomanip> | 9 #include <iomanip> |
10 #include <list> | 10 #include <list> |
(...skipping 1623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1634 JsTransactionObserver js_transaction_observer_; | 1634 JsTransactionObserver js_transaction_observer_; |
1635 }; | 1635 }; |
1636 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; | 1636 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; |
1637 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; | 1637 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; |
1638 | 1638 |
1639 SyncManager::Observer::~Observer() {} | 1639 SyncManager::Observer::~Observer() {} |
1640 | 1640 |
1641 SyncManager::SyncManager(const std::string& name) | 1641 SyncManager::SyncManager(const std::string& name) |
1642 : data_(new SyncInternal(name)) {} | 1642 : data_(new SyncInternal(name)) {} |
1643 | 1643 |
1644 SyncManager::Status::Status() | |
1645 : summary(INVALID) { | |
akalin
2011/08/04 01:14:48
All the vars are initialized by allstatus right?
Nicolas Zea
2011/08/04 01:27:52
Done.
| |
1646 } | |
1647 | |
1648 SyncManager::Status::~Status() { | |
1649 } | |
1650 | |
1644 bool SyncManager::Init( | 1651 bool SyncManager::Init( |
1645 const FilePath& database_location, | 1652 const FilePath& database_location, |
1646 const WeakHandle<JsEventHandler>& event_handler, | 1653 const WeakHandle<JsEventHandler>& event_handler, |
1647 const std::string& sync_server_and_path, | 1654 const std::string& sync_server_and_path, |
1648 int sync_server_port, | 1655 int sync_server_port, |
1649 bool use_ssl, | 1656 bool use_ssl, |
1650 HttpPostProviderFactory* post_factory, | 1657 HttpPostProviderFactory* post_factory, |
1651 ModelSafeWorkerRegistrar* registrar, | 1658 ModelSafeWorkerRegistrar* registrar, |
1652 const std::string& user_agent, | 1659 const std::string& user_agent, |
1653 const SyncCredentials& credentials, | 1660 const SyncCredentials& credentials, |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1858 } | 1865 } |
1859 Cryptographer::UpdateResult result = | 1866 Cryptographer::UpdateResult result = |
1860 cryptographer->Update(node.GetNigoriSpecifics()); | 1867 cryptographer->Update(node.GetNigoriSpecifics()); |
1861 if (result == Cryptographer::NEEDS_PASSPHRASE) { | 1868 if (result == Cryptographer::NEEDS_PASSPHRASE) { |
1862 ObserverList<SyncManager::Observer> temp_obs_list; | 1869 ObserverList<SyncManager::Observer> temp_obs_list; |
1863 CopyObservers(&temp_obs_list); | 1870 CopyObservers(&temp_obs_list); |
1864 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, | 1871 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, |
1865 OnPassphraseRequired(sync_api::REASON_DECRYPTION)); | 1872 OnPassphraseRequired(sync_api::REASON_DECRYPTION)); |
1866 } | 1873 } |
1867 | 1874 |
1875 allstatus_.SetCryptographerReady(cryptographer->is_ready()); | |
1876 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); | |
1877 | |
1868 return cryptographer->is_ready(); | 1878 return cryptographer->is_ready(); |
1869 } | 1879 } |
1870 | 1880 |
1871 void SyncManager::SyncInternal::StartSyncingNormally() { | 1881 void SyncManager::SyncInternal::StartSyncingNormally() { |
1872 // Start the sync scheduler. This won't actually result in any | 1882 // Start the sync scheduler. This won't actually result in any |
1873 // syncing until at least the DirectoryManager broadcasts the OPENED | 1883 // syncing until at least the DirectoryManager broadcasts the OPENED |
1874 // event, and a valid server connection is detected. | 1884 // event, and a valid server connection is detected. |
1875 if (scheduler()) // NULL during certain unittests. | 1885 if (scheduler()) // NULL during certain unittests. |
1876 scheduler()->Start(SyncScheduler::NORMAL_MODE, NULL); | 1886 scheduler()->Start(SyncScheduler::NORMAL_MODE, NULL); |
1877 } | 1887 } |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2095 // Note, we merge the current encrypted types with those requested. Once a | 2105 // Note, we merge the current encrypted types with those requested. Once a |
2096 // datatypes is marked as needing encryption, it is never unmarked. | 2106 // datatypes is marked as needing encryption, it is never unmarked. |
2097 sync_pb::NigoriSpecifics nigori; | 2107 sync_pb::NigoriSpecifics nigori; |
2098 nigori.CopyFrom(node.GetNigoriSpecifics()); | 2108 nigori.CopyFrom(node.GetNigoriSpecifics()); |
2099 syncable::ModelTypeSet current_encrypted_types = GetEncryptedTypes(&trans); | 2109 syncable::ModelTypeSet current_encrypted_types = GetEncryptedTypes(&trans); |
2100 syncable::ModelTypeSet newly_encrypted_types; | 2110 syncable::ModelTypeSet newly_encrypted_types; |
2101 std::set_union(current_encrypted_types.begin(), current_encrypted_types.end(), | 2111 std::set_union(current_encrypted_types.begin(), current_encrypted_types.end(), |
2102 encrypted_types.begin(), encrypted_types.end(), | 2112 encrypted_types.begin(), encrypted_types.end(), |
2103 std::inserter(newly_encrypted_types, | 2113 std::inserter(newly_encrypted_types, |
2104 newly_encrypted_types.begin())); | 2114 newly_encrypted_types.begin())); |
2115 allstatus_.SetEncryptedTypes(newly_encrypted_types); | |
2105 if (newly_encrypted_types == current_encrypted_types) | 2116 if (newly_encrypted_types == current_encrypted_types) |
2106 return; // Set of encrypted types did not change. | 2117 return; // Set of encrypted types did not change. |
2107 syncable::FillNigoriEncryptedTypes(newly_encrypted_types, &nigori); | 2118 syncable::FillNigoriEncryptedTypes(newly_encrypted_types, &nigori); |
2108 node.SetNigoriSpecifics(nigori); | 2119 node.SetNigoriSpecifics(nigori); |
2109 | 2120 |
2110 cryptographer->SetEncryptedTypes(nigori); | 2121 cryptographer->SetEncryptedTypes(nigori); |
2111 | 2122 |
2112 // TODO(zea): only reencrypt this datatype? ReEncrypting everything is a | 2123 // TODO(zea): only reencrypt this datatype? ReEncrypting everything is a |
2113 // safer approach, and should not impact anything that is already encrypted | 2124 // safer approach, and should not impact anything that is already encrypted |
2114 // (redundant changes are ignored). | 2125 // (redundant changes are ignored). |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2553 OnPassphraseRequired(sync_api::REASON_DECRYPTION)); | 2564 OnPassphraseRequired(sync_api::REASON_DECRYPTION)); |
2554 } else if (!cryptographer->is_ready() && | 2565 } else if (!cryptographer->is_ready() && |
2555 event.snapshot->initial_sync_ended.test(syncable::NIGORI)) { | 2566 event.snapshot->initial_sync_ended.test(syncable::NIGORI)) { |
2556 VLOG(1) << "OnPassphraseRequired sent because cryptographer is not " | 2567 VLOG(1) << "OnPassphraseRequired sent because cryptographer is not " |
2557 << "ready"; | 2568 << "ready"; |
2558 ObserverList<SyncManager::Observer> temp_obs_list; | 2569 ObserverList<SyncManager::Observer> temp_obs_list; |
2559 CopyObservers(&temp_obs_list); | 2570 CopyObservers(&temp_obs_list); |
2560 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, | 2571 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, |
2561 OnPassphraseRequired(sync_api::REASON_ENCRYPTION)); | 2572 OnPassphraseRequired(sync_api::REASON_ENCRYPTION)); |
2562 } | 2573 } |
2574 | |
2575 allstatus_.SetCryptographerReady(cryptographer->is_ready()); | |
2576 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); | |
2577 | |
2578 syncable::ModelTypeSet encrypted_types = | |
akalin
2011/08/04 01:14:48
seems clearer to inline the call to GetEncryptedTy
Nicolas Zea
2011/08/04 01:27:52
Done.
| |
2579 cryptographer->GetEncryptedTypes(); | |
2580 allstatus_.SetEncryptedTypes(encrypted_types); | |
2581 | |
2563 // If everything is in order(we have the passphrase) then there is no | 2582 // If everything is in order(we have the passphrase) then there is no |
2564 // need to inform the listeners. They will just wait for sync | 2583 // need to inform the listeners. They will just wait for sync |
2565 // completion event and if no errors have been raised it means | 2584 // completion event and if no errors have been raised it means |
2566 // encryption was succesful. | 2585 // encryption was succesful. |
2567 } | 2586 } |
2568 | 2587 |
2569 if (!initialized_) { | 2588 if (!initialized_) { |
2570 LOG(INFO) << "OnSyncCycleCompleted not sent because sync api is not " | 2589 LOG(INFO) << "OnSyncCycleCompleted not sent because sync api is not " |
2571 << "initialized"; | 2590 << "initialized"; |
2572 return; | 2591 return; |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3010 void SyncManager::TriggerOnIncomingNotificationForTest( | 3029 void SyncManager::TriggerOnIncomingNotificationForTest( |
3011 const syncable::ModelTypeBitSet& model_types) { | 3030 const syncable::ModelTypeBitSet& model_types) { |
3012 syncable::ModelTypePayloadMap model_types_with_payloads = | 3031 syncable::ModelTypePayloadMap model_types_with_payloads = |
3013 syncable::ModelTypePayloadMapFromBitSet(model_types, | 3032 syncable::ModelTypePayloadMapFromBitSet(model_types, |
3014 std::string()); | 3033 std::string()); |
3015 | 3034 |
3016 data_->OnIncomingNotification(model_types_with_payloads); | 3035 data_->OnIncomingNotification(model_types_with_payloads); |
3017 } | 3036 } |
3018 | 3037 |
3019 } // namespace sync_api | 3038 } // namespace sync_api |
OLD | NEW |