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 1860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1871 } | 1871 } |
1872 Cryptographer::UpdateResult result = | 1872 Cryptographer::UpdateResult result = |
1873 cryptographer->Update(node.GetNigoriSpecifics()); | 1873 cryptographer->Update(node.GetNigoriSpecifics()); |
1874 if (result == Cryptographer::NEEDS_PASSPHRASE) { | 1874 if (result == Cryptographer::NEEDS_PASSPHRASE) { |
1875 ObserverList<SyncManager::Observer> temp_obs_list; | 1875 ObserverList<SyncManager::Observer> temp_obs_list; |
1876 CopyObservers(&temp_obs_list); | 1876 CopyObservers(&temp_obs_list); |
1877 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, | 1877 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, |
1878 OnPassphraseRequired(sync_api::REASON_DECRYPTION)); | 1878 OnPassphraseRequired(sync_api::REASON_DECRYPTION)); |
1879 } | 1879 } |
1880 | 1880 |
1881 | |
1882 allstatus_.SetCryptographerReady(cryptographer->is_ready()); | |
1883 | |
1881 return cryptographer->is_ready(); | 1884 return cryptographer->is_ready(); |
1882 } | 1885 } |
1883 | 1886 |
1884 void SyncManager::SyncInternal::StartSyncingNormally() { | 1887 void SyncManager::SyncInternal::StartSyncingNormally() { |
1885 // Start the sync scheduler. This won't actually result in any | 1888 // Start the sync scheduler. This won't actually result in any |
1886 // syncing until at least the DirectoryManager broadcasts the OPENED | 1889 // syncing until at least the DirectoryManager broadcasts the OPENED |
1887 // event, and a valid server connection is detected. | 1890 // event, and a valid server connection is detected. |
1888 if (scheduler()) // NULL during certain unittests. | 1891 if (scheduler()) // NULL during certain unittests. |
1889 scheduler()->Start(SyncScheduler::NORMAL_MODE, NULL); | 1892 scheduler()->Start(SyncScheduler::NORMAL_MODE, NULL); |
1890 } | 1893 } |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2113 // Note, we merge the current encrypted types with those requested. Once a | 2116 // Note, we merge the current encrypted types with those requested. Once a |
2114 // datatypes is marked as needing encryption, it is never unmarked. | 2117 // datatypes is marked as needing encryption, it is never unmarked. |
2115 sync_pb::NigoriSpecifics nigori; | 2118 sync_pb::NigoriSpecifics nigori; |
2116 nigori.CopyFrom(node.GetNigoriSpecifics()); | 2119 nigori.CopyFrom(node.GetNigoriSpecifics()); |
2117 syncable::ModelTypeSet current_encrypted_types = GetEncryptedTypes(&trans); | 2120 syncable::ModelTypeSet current_encrypted_types = GetEncryptedTypes(&trans); |
2118 syncable::ModelTypeSet newly_encrypted_types; | 2121 syncable::ModelTypeSet newly_encrypted_types; |
2119 std::set_union(current_encrypted_types.begin(), current_encrypted_types.end(), | 2122 std::set_union(current_encrypted_types.begin(), current_encrypted_types.end(), |
2120 encrypted_types.begin(), encrypted_types.end(), | 2123 encrypted_types.begin(), encrypted_types.end(), |
2121 std::inserter(newly_encrypted_types, | 2124 std::inserter(newly_encrypted_types, |
2122 newly_encrypted_types.begin())); | 2125 newly_encrypted_types.begin())); |
2126 allstatus_.SetEncryptEverything(newly_encrypted_types.size() > | |
akalin
2011/08/03 19:10:02
Can we instead expose the list of encrypted types?
Nicolas Zea
2011/08/03 22:04:24
Done.
| |
2127 newly_encrypted_types.count(syncable::PASSWORDS)); | |
2123 if (newly_encrypted_types == current_encrypted_types) | 2128 if (newly_encrypted_types == current_encrypted_types) |
2124 return; // Set of encrypted types did not change. | 2129 return; // Set of encrypted types did not change. |
2125 syncable::FillNigoriEncryptedTypes(newly_encrypted_types, &nigori); | 2130 syncable::FillNigoriEncryptedTypes(newly_encrypted_types, &nigori); |
2126 node.SetNigoriSpecifics(nigori); | 2131 node.SetNigoriSpecifics(nigori); |
2127 | 2132 |
2128 cryptographer->SetEncryptedTypes(nigori); | 2133 cryptographer->SetEncryptedTypes(nigori); |
2129 | 2134 |
2130 // TODO(zea): only reencrypt this datatype? ReEncrypting everything is a | 2135 // TODO(zea): only reencrypt this datatype? ReEncrypting everything is a |
2131 // safer approach, and should not impact anything that is already encrypted | 2136 // safer approach, and should not impact anything that is already encrypted |
2132 // (redundant changes are ignored). | 2137 // (redundant changes are ignored). |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2554 registrar_->GetModelSafeRoutingInfo(&enabled_types); | 2559 registrar_->GetModelSafeRoutingInfo(&enabled_types); |
2555 { | 2560 { |
2556 // Check to see if we need to notify the frontend that we have newly | 2561 // Check to see if we need to notify the frontend that we have newly |
2557 // encrypted types or that we require a passphrase. | 2562 // encrypted types or that we require a passphrase. |
2558 sync_api::ReadTransaction trans(FROM_HERE, GetUserShare()); | 2563 sync_api::ReadTransaction trans(FROM_HERE, GetUserShare()); |
2559 Cryptographer* cryptographer = trans.GetCryptographer(); | 2564 Cryptographer* cryptographer = trans.GetCryptographer(); |
2560 // If we've completed a sync cycle and the cryptographer isn't ready | 2565 // If we've completed a sync cycle and the cryptographer isn't ready |
2561 // yet, prompt the user for a passphrase. | 2566 // yet, prompt the user for a passphrase. |
2562 if (cryptographer->has_pending_keys()) { | 2567 if (cryptographer->has_pending_keys()) { |
2563 VLOG(1) << "OnPassPhraseRequired Sent"; | 2568 VLOG(1) << "OnPassPhraseRequired Sent"; |
2569 allstatus_.SetCryptographerReady(false); | |
akalin
2011/08/03 19:10:02
seems less brittle to, e.g. set cryptographerready
Nicolas Zea
2011/08/03 22:04:24
Done.
| |
2564 ObserverList<SyncManager::Observer> temp_obs_list; | 2570 ObserverList<SyncManager::Observer> temp_obs_list; |
2565 CopyObservers(&temp_obs_list); | 2571 CopyObservers(&temp_obs_list); |
2566 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, | 2572 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, |
2567 OnPassphraseRequired(sync_api::REASON_DECRYPTION)); | 2573 OnPassphraseRequired(sync_api::REASON_DECRYPTION)); |
2568 } else if (!cryptographer->is_ready() && | 2574 } else if (!cryptographer->is_ready() && |
2569 event.snapshot->initial_sync_ended.test(syncable::NIGORI)) { | 2575 event.snapshot->initial_sync_ended.test(syncable::NIGORI)) { |
2576 allstatus_.SetCryptographerReady(false); | |
2570 VLOG(1) << "OnPassphraseRequired sent because cryptographer is not " | 2577 VLOG(1) << "OnPassphraseRequired sent because cryptographer is not " |
2571 << "ready"; | 2578 << "ready"; |
2572 ObserverList<SyncManager::Observer> temp_obs_list; | 2579 ObserverList<SyncManager::Observer> temp_obs_list; |
2573 CopyObservers(&temp_obs_list); | 2580 CopyObservers(&temp_obs_list); |
2574 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, | 2581 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, |
2575 OnPassphraseRequired(sync_api::REASON_ENCRYPTION)); | 2582 OnPassphraseRequired(sync_api::REASON_ENCRYPTION)); |
2583 } else { | |
2584 allstatus_.SetCryptographerReady(true); | |
2576 } | 2585 } |
2586 | |
2587 syncable::ModelTypeSet encrypted_types = | |
2588 cryptographer->GetEncryptedTypes(); | |
2589 allstatus_.SetEncryptEverything(encrypted_types.size() > | |
2590 encrypted_types.count(syncable::PASSWORDS)); | |
2591 | |
2577 // If everything is in order(we have the passphrase) then there is no | 2592 // If everything is in order(we have the passphrase) then there is no |
2578 // need to inform the listeners. They will just wait for sync | 2593 // need to inform the listeners. They will just wait for sync |
2579 // completion event and if no errors have been raised it means | 2594 // completion event and if no errors have been raised it means |
2580 // encryption was succesful. | 2595 // encryption was succesful. |
2581 } | 2596 } |
2582 | 2597 |
2583 if (!initialized_) { | 2598 if (!initialized_) { |
2584 LOG(INFO) << "OnSyncCycleCompleted not sent because sync api is not " | 2599 LOG(INFO) << "OnSyncCycleCompleted not sent because sync api is not " |
2585 << "initialized"; | 2600 << "initialized"; |
2586 return; | 2601 return; |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3074 void SyncManager::TriggerOnIncomingNotificationForTest( | 3089 void SyncManager::TriggerOnIncomingNotificationForTest( |
3075 const syncable::ModelTypeBitSet& model_types) { | 3090 const syncable::ModelTypeBitSet& model_types) { |
3076 syncable::ModelTypePayloadMap model_types_with_payloads = | 3091 syncable::ModelTypePayloadMap model_types_with_payloads = |
3077 syncable::ModelTypePayloadMapFromBitSet(model_types, | 3092 syncable::ModelTypePayloadMapFromBitSet(model_types, |
3078 std::string()); | 3093 std::string()); |
3079 | 3094 |
3080 data_->OnIncomingNotification(model_types_with_payloads); | 3095 data_->OnIncomingNotification(model_types_with_payloads); |
3081 } | 3096 } |
3082 | 3097 |
3083 } // namespace sync_api | 3098 } // namespace sync_api |
OLD | NEW |