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