| 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/internal_api/sync_manager.h" | 5 #include "chrome/browser/sync/internal_api/sync_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 112 } |
| 113 | 113 |
| 114 } // namespace | 114 } // namespace |
| 115 | 115 |
| 116 namespace sync_api { | 116 namespace sync_api { |
| 117 | 117 |
| 118 ////////////////////////////////////////////////////////////////////////// | 118 ////////////////////////////////////////////////////////////////////////// |
| 119 // SyncManager's implementation: SyncManager::SyncInternal | 119 // SyncManager's implementation: SyncManager::SyncInternal |
| 120 class SyncManager::SyncInternal | 120 class SyncManager::SyncInternal |
| 121 : public net::NetworkChangeNotifier::IPAddressObserver, | 121 : public net::NetworkChangeNotifier::IPAddressObserver, |
| 122 public browser_sync::Cryptographer::Observer, |
| 122 public sync_notifier::SyncNotifierObserver, | 123 public sync_notifier::SyncNotifierObserver, |
| 123 public JsBackend, | 124 public JsBackend, |
| 124 public SyncEngineEventListener, | 125 public SyncEngineEventListener, |
| 125 public ServerConnectionEventListener, | 126 public ServerConnectionEventListener, |
| 126 public syncable::DirectoryChangeDelegate { | 127 public syncable::DirectoryChangeDelegate { |
| 127 static const int kDefaultNudgeDelayMilliseconds; | 128 static const int kDefaultNudgeDelayMilliseconds; |
| 128 static const int kPreferencesNudgeDelayMilliseconds; | 129 static const int kPreferencesNudgeDelayMilliseconds; |
| 129 public: | 130 public: |
| 130 explicit SyncInternal(const std::string& name) | 131 explicit SyncInternal(const std::string& name) |
| 131 : name_(name), | 132 : name_(name), |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 217 |
| 217 // Whether or not the Nigori node is encrypted using an explicit passphrase. | 218 // Whether or not the Nigori node is encrypted using an explicit passphrase. |
| 218 bool IsUsingExplicitPassphrase(); | 219 bool IsUsingExplicitPassphrase(); |
| 219 | 220 |
| 220 // Update the Cryptographer from the current nigori node. | 221 // Update the Cryptographer from the current nigori node. |
| 221 // Note: opens a transaction and can trigger an ON_PASSPHRASE_REQUIRED, so | 222 // Note: opens a transaction and can trigger an ON_PASSPHRASE_REQUIRED, so |
| 222 // should only be called after syncapi is fully initialized. | 223 // should only be called after syncapi is fully initialized. |
| 223 // Returns true if cryptographer is ready, false otherwise. | 224 // Returns true if cryptographer is ready, false otherwise. |
| 224 bool UpdateCryptographerFromNigori(); | 225 bool UpdateCryptographerFromNigori(); |
| 225 | 226 |
| 226 // Set the datatypes we want to encrypt and encrypt any nodes as necessary. | 227 // Updates the nigori node with any new encrypted types and then |
| 227 // Note: |encrypted_types| will be unioned with the current set of encrypted | 228 // encrypts the nodes for those new data types as well as other |
| 228 // types, as we do not currently support decrypting datatypes. | 229 // nodes that should be encrypted but aren't. Triggers |
| 229 void EncryptDataTypes(const syncable::ModelTypeSet& encrypted_types); | 230 // OnPassphraseRequired if the cryptographer isn't ready. |
| 231 void RefreshEncryption(); |
| 230 | 232 |
| 231 // Try to set the current passphrase to |passphrase|, and record whether | 233 // Try to set the current passphrase to |passphrase|, and record whether |
| 232 // it is an explicit passphrase or implicitly using gaia in the Nigori | 234 // it is an explicit passphrase or implicitly using gaia in the Nigori |
| 233 // node. | 235 // node. |
| 234 void SetPassphrase(const std::string& passphrase, bool is_explicit); | 236 void SetPassphrase(const std::string& passphrase, bool is_explicit); |
| 235 | 237 |
| 236 // Call periodically from a database-safe thread to persist recent changes | 238 // Call periodically from a database-safe thread to persist recent changes |
| 237 // to the syncapi model. | 239 // to the syncapi model. |
| 238 void SaveChanges(); | 240 void SaveChanges(); |
| 239 | 241 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 252 virtual void HandleCalculateChangesChangeEventFromSyncer( | 254 virtual void HandleCalculateChangesChangeEventFromSyncer( |
| 253 const ImmutableWriteTransactionInfo& write_transaction_info, | 255 const ImmutableWriteTransactionInfo& write_transaction_info, |
| 254 syncable::BaseTransaction* trans) OVERRIDE; | 256 syncable::BaseTransaction* trans) OVERRIDE; |
| 255 | 257 |
| 256 // Listens for notifications from the ServerConnectionManager | 258 // Listens for notifications from the ServerConnectionManager |
| 257 void HandleServerConnectionEvent(const ServerConnectionEvent& event); | 259 void HandleServerConnectionEvent(const ServerConnectionEvent& event); |
| 258 | 260 |
| 259 // Open the directory named with username_for_share | 261 // Open the directory named with username_for_share |
| 260 bool OpenDirectory(); | 262 bool OpenDirectory(); |
| 261 | 263 |
| 264 // Cryptographer::Observer implementation. |
| 265 virtual void OnEncryptedTypesChanged( |
| 266 const syncable::ModelTypeSet& encrypted_types, |
| 267 bool encrypt_everything) OVERRIDE; |
| 268 |
| 262 // SyncNotifierObserver implementation. | 269 // SyncNotifierObserver implementation. |
| 263 virtual void OnNotificationStateChange( | 270 virtual void OnNotificationStateChange( |
| 264 bool notifications_enabled) OVERRIDE; | 271 bool notifications_enabled) OVERRIDE; |
| 265 | 272 |
| 266 virtual void OnIncomingNotification( | 273 virtual void OnIncomingNotification( |
| 267 const syncable::ModelTypePayloadMap& type_payloads) OVERRIDE; | 274 const syncable::ModelTypePayloadMap& type_payloads) OVERRIDE; |
| 268 | 275 |
| 269 virtual void StoreState(const std::string& cookie) OVERRIDE; | 276 virtual void StoreState(const std::string& cookie) OVERRIDE; |
| 270 | 277 |
| 271 void AddChangeObserver(SyncManager::ChangeObserver* observer); | 278 void AddChangeObserver(SyncManager::ChangeObserver* observer); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 bool ChangeBuffersAreEmpty() { | 439 bool ChangeBuffersAreEmpty() { |
| 433 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { | 440 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 434 if (!change_buffers_[i].IsEmpty()) | 441 if (!change_buffers_[i].IsEmpty()) |
| 435 return false; | 442 return false; |
| 436 } | 443 } |
| 437 return true; | 444 return true; |
| 438 } | 445 } |
| 439 | 446 |
| 440 void ReEncryptEverything(WriteTransaction* trans); | 447 void ReEncryptEverything(WriteTransaction* trans); |
| 441 | 448 |
| 442 // Initializes (bootstraps) the Cryptographer if NIGORI has finished | |
| 443 // initial sync so that it can immediately start encrypting / decrypting. | |
| 444 // If the restored key is incompatible with the current version of the NIGORI | |
| 445 // node (which could happen if a restart occurred just after an update to | |
| 446 // NIGORI was downloaded and the user must enter a new passphrase to decrypt) | |
| 447 // then we will raise OnPassphraseRequired and set pending keys for | |
| 448 // decryption. Otherwise, the cryptographer is made ready (is_ready()). | |
| 449 void BootstrapEncryption(const std::string& restored_key_for_bootstrapping); | |
| 450 | |
| 451 // Called for every notification. This updates the notification statistics | 449 // Called for every notification. This updates the notification statistics |
| 452 // to be displayed in about:sync. | 450 // to be displayed in about:sync. |
| 453 void UpdateNotificationInfo( | 451 void UpdateNotificationInfo( |
| 454 const syncable::ModelTypePayloadMap& type_payloads); | 452 const syncable::ModelTypePayloadMap& type_payloads); |
| 455 | 453 |
| 456 // Checks for server reachabilty and requests a nudge. | 454 // Checks for server reachabilty and requests a nudge. |
| 457 void OnIPAddressChangedImpl(); | 455 void OnIPAddressChangedImpl(); |
| 458 | 456 |
| 459 // Helper function used only by the constructor. | 457 // Helper function used only by the constructor. |
| 460 void BindJsMessageHandler( | 458 void BindJsMessageHandler( |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 { | 673 { |
| 676 // Update the cryptographer to know we're now encrypting everything. | 674 // Update the cryptographer to know we're now encrypting everything. |
| 677 WriteTransaction trans(FROM_HERE, GetUserShare()); | 675 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 678 Cryptographer* cryptographer = trans.GetCryptographer(); | 676 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 679 // Only set encrypt everything if we know we can encrypt. This allows the | 677 // Only set encrypt everything if we know we can encrypt. This allows the |
| 680 // user to cancel encryption if they have forgotten their passphrase. | 678 // user to cancel encryption if they have forgotten their passphrase. |
| 681 if (cryptographer->is_ready()) | 679 if (cryptographer->is_ready()) |
| 682 cryptographer->set_encrypt_everything(); | 680 cryptographer->set_encrypt_everything(); |
| 683 } | 681 } |
| 684 | 682 |
| 685 // Call with empty set. Reads from cryptographer so will automatically encrypt | 683 // Reads from cryptographer so will automatically encrypt all |
| 686 // all datatypes and update the nigori node as necessary. Will trigger | 684 // datatypes and update the nigori node as necessary. Will trigger |
| 687 // OnPassphraseRequired if necessary. | 685 // OnPassphraseRequired if necessary. |
| 688 data_->EncryptDataTypes(syncable::ModelTypeSet()); | 686 data_->RefreshEncryption(); |
| 689 } | 687 } |
| 690 | 688 |
| 691 bool SyncManager::EncryptEverythingEnabled() const { | 689 bool SyncManager::EncryptEverythingEnabledForTest() const { |
| 692 ReadTransaction trans(FROM_HERE, GetUserShare()); | 690 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 693 return trans.GetCryptographer()->encrypt_everything(); | 691 return trans.GetCryptographer()->encrypt_everything(); |
| 694 } | 692 } |
| 695 | 693 |
| 696 bool SyncManager::IsUsingExplicitPassphrase() { | 694 bool SyncManager::IsUsingExplicitPassphrase() { |
| 697 return data_ && data_->IsUsingExplicitPassphrase(); | 695 return data_ && data_->IsUsingExplicitPassphrase(); |
| 698 } | 696 } |
| 699 | 697 |
| 700 void SyncManager::RequestCleanupDisabledTypes() { | 698 void SyncManager::RequestCleanupDisabledTypes() { |
| 701 DCHECK(thread_checker_.CalledOnValidThread()); | 699 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 bool signed_in = SignIn(credentials); | 801 bool signed_in = SignIn(credentials); |
| 804 | 802 |
| 805 if (signed_in || setup_for_test_mode_) { | 803 if (signed_in || setup_for_test_mode_) { |
| 806 if (scheduler()) { | 804 if (scheduler()) { |
| 807 scheduler()->Start( | 805 scheduler()->Start( |
| 808 browser_sync::SyncScheduler::CONFIGURATION_MODE, base::Closure()); | 806 browser_sync::SyncScheduler::CONFIGURATION_MODE, base::Closure()); |
| 809 } | 807 } |
| 810 | 808 |
| 811 initialized_ = true; | 809 initialized_ = true; |
| 812 | 810 |
| 813 // The following calls check that initialized_ is true. | 811 // Cryptographer should only be accessed while holding a |
| 814 BootstrapEncryption(restored_key_for_bootstrapping); | 812 // transaction. Grabbing the user share for the transaction |
| 813 // checks the initialization state, so this must come after |
| 814 // |initialized_| is set to true. |
| 815 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 816 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping); |
| 817 trans.GetCryptographer()->AddObserver(this); |
| 815 } | 818 } |
| 816 | 819 |
| 817 // Notify that initialization is complete. Note: This should be the last to | 820 // Notify that initialization is complete. Note: This should be the last to |
| 818 // execute if |signed_in| is false. Reason being in that case we would | 821 // execute if |signed_in| is false. Reason being in that case we would |
| 819 // post a task to shutdown sync. But if this function posts any other tasks | 822 // post a task to shutdown sync. But if this function posts any other tasks |
| 820 // on the UI thread and if shutdown wins then that tasks would execute on | 823 // on the UI thread and if shutdown wins then that tasks would execute on |
| 821 // a freed pointer. This is because UI thread is not shut down. | 824 // a freed pointer. This is because UI thread is not shut down. |
| 822 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 825 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 823 OnInitializationComplete( | 826 OnInitializationComplete( |
| 824 WeakHandle<JsBackend>(weak_ptr_factory_.GetWeakPtr()), | 827 WeakHandle<JsBackend>(weak_ptr_factory_.GetWeakPtr()), |
| 825 signed_in)); | 828 signed_in)); |
| 826 | 829 |
| 827 if (!signed_in && !setup_for_test_mode_) | 830 if (!signed_in && !setup_for_test_mode_) |
| 828 return false; | 831 return false; |
| 829 | 832 |
| 830 sync_notifier_->AddObserver(this); | 833 sync_notifier_->AddObserver(this); |
| 831 | 834 |
| 832 return signed_in; | 835 return signed_in; |
| 833 } | 836 } |
| 834 | 837 |
| 835 void SyncManager::SyncInternal::BootstrapEncryption( | |
| 836 const std::string& restored_key_for_bootstrapping) { | |
| 837 // Cryptographer should only be accessed while holding a transaction. | |
| 838 ReadTransaction trans(FROM_HERE, GetUserShare()); | |
| 839 Cryptographer* cryptographer = trans.GetCryptographer(); | |
| 840 | |
| 841 // Set the bootstrap token before bailing out if nigori node is not there. | |
| 842 // This could happen if server asked us to migrate nigri. | |
| 843 cryptographer->Bootstrap(restored_key_for_bootstrapping); | |
| 844 } | |
| 845 | |
| 846 bool SyncManager::SyncInternal::UpdateCryptographerFromNigori() { | 838 bool SyncManager::SyncInternal::UpdateCryptographerFromNigori() { |
| 847 DCHECK(initialized_); | 839 DCHECK(initialized_); |
| 848 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); | 840 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); |
| 849 if (!lookup.good()) { | 841 if (!lookup.good()) { |
| 850 NOTREACHED() << "BootstrapEncryption: lookup not good so bailing out"; | 842 NOTREACHED() |
| 843 << "UpdateCryptographerFromNigori: lookup not good so bailing out"; |
| 851 return false; | 844 return false; |
| 852 } | 845 } |
| 853 if (!lookup->initial_sync_ended_for_type(syncable::NIGORI)) | 846 if (!lookup->initial_sync_ended_for_type(syncable::NIGORI)) |
| 854 return false; // Should only happen during first time sync. | 847 return false; // Should only happen during first time sync. |
| 855 | 848 |
| 856 WriteTransaction trans(FROM_HERE, GetUserShare()); | 849 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 857 Cryptographer* cryptographer = trans.GetCryptographer(); | 850 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 858 | 851 |
| 859 WriteNode node(&trans); | 852 WriteNode node(&trans); |
| 860 if (!node.InitByTagLookup(kNigoriTag)) { | 853 if (!node.InitByTagLookup(kNigoriTag)) { |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 ReadNode node(&trans); | 1086 ReadNode node(&trans); |
| 1094 if (!node.InitByTagLookup(kNigoriTag)) { | 1087 if (!node.InitByTagLookup(kNigoriTag)) { |
| 1095 // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. | 1088 // TODO(albertb): Plumb an UnrecoverableError all the way back to the PSS. |
| 1096 NOTREACHED(); | 1089 NOTREACHED(); |
| 1097 return false; | 1090 return false; |
| 1098 } | 1091 } |
| 1099 | 1092 |
| 1100 return node.GetNigoriSpecifics().using_explicit_passphrase(); | 1093 return node.GetNigoriSpecifics().using_explicit_passphrase(); |
| 1101 } | 1094 } |
| 1102 | 1095 |
| 1103 void SyncManager::SyncInternal::EncryptDataTypes( | 1096 void SyncManager::SyncInternal::RefreshEncryption() { |
| 1104 const syncable::ModelTypeSet& encrypted_types) { | |
| 1105 DCHECK(initialized_); | 1097 DCHECK(initialized_); |
| 1106 VLOG(1) << "Attempting to encrypt datatypes " | |
| 1107 << syncable::ModelTypeSetToString(encrypted_types); | |
| 1108 | 1098 |
| 1109 WriteTransaction trans(FROM_HERE, GetUserShare()); | 1099 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 1110 WriteNode node(&trans); | 1100 WriteNode node(&trans); |
| 1111 if (!node.InitByTagLookup(kNigoriTag)) { | 1101 if (!node.InitByTagLookup(kNigoriTag)) { |
| 1112 NOTREACHED() << "Unable to set encrypted datatypes because Nigori node not " | 1102 NOTREACHED() << "Unable to set encrypted datatypes because Nigori node not " |
| 1113 << "found."; | 1103 << "found."; |
| 1114 return; | 1104 return; |
| 1115 } | 1105 } |
| 1116 | 1106 |
| 1117 Cryptographer* cryptographer = trans.GetCryptographer(); | 1107 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1118 | 1108 |
| 1119 if (!cryptographer->is_ready()) { | 1109 if (!cryptographer->is_ready()) { |
| 1120 VLOG(1) << "Attempting to encrypt datatypes when cryptographer not " | 1110 VLOG(1) << "Attempting to encrypt datatypes when cryptographer not " |
| 1121 << "initialized, prompting for passphrase."; | 1111 << "initialized, prompting for passphrase."; |
| 1122 // TODO(zea): this isn't really decryption, but that's the only way we have | 1112 // TODO(zea): this isn't really decryption, but that's the only way we have |
| 1123 // to prompt the user for a passsphrase. See http://crbug.com/91379. | 1113 // to prompt the user for a passsphrase. See http://crbug.com/91379. |
| 1124 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1114 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1125 OnPassphraseRequired(sync_api::REASON_DECRYPTION)); | 1115 OnPassphraseRequired(sync_api::REASON_DECRYPTION)); |
| 1126 return; | 1116 return; |
| 1127 } | 1117 } |
| 1128 | 1118 |
| 1129 // Update the Nigori node's set of encrypted datatypes. | 1119 // Update the Nigori node's set of encrypted datatypes. |
| 1130 // Note, we merge the current encrypted types with those requested. Once a | 1120 // Note, we merge the current encrypted types with those requested. Once a |
| 1131 // datatypes is marked as needing encryption, it is never unmarked. | 1121 // datatypes is marked as needing encryption, it is never unmarked. |
| 1132 cryptographer->SetEncryptedTypes(encrypted_types); | |
| 1133 sync_pb::NigoriSpecifics nigori; | 1122 sync_pb::NigoriSpecifics nigori; |
| 1134 nigori.CopyFrom(node.GetNigoriSpecifics()); | 1123 nigori.CopyFrom(node.GetNigoriSpecifics()); |
| 1135 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori); | 1124 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori); |
| 1136 node.SetNigoriSpecifics(nigori); | 1125 node.SetNigoriSpecifics(nigori); |
| 1137 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); | 1126 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); |
| 1138 | 1127 |
| 1139 // We reencrypt everything regardless of whether the set of encrypted | 1128 // We reencrypt everything regardless of whether the set of encrypted |
| 1140 // types changed to ensure that any stray unencrypted entries are overwritten. | 1129 // types changed to ensure that any stray unencrypted entries are overwritten. |
| 1141 ReEncryptEverything(&trans); | 1130 ReEncryptEverything(&trans); |
| 1142 return; | |
| 1143 } | 1131 } |
| 1144 | 1132 |
| 1145 // TODO(zea): Add unit tests that ensure no sync changes are made when not | 1133 // TODO(zea): Add unit tests that ensure no sync changes are made when not |
| 1146 // needed. | 1134 // needed. |
| 1147 void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) { | 1135 void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) { |
| 1148 Cryptographer* cryptographer = trans->GetCryptographer(); | 1136 Cryptographer* cryptographer = trans->GetCryptographer(); |
| 1149 if (!cryptographer || !cryptographer->is_ready()) | 1137 if (!cryptographer || !cryptographer->is_ready()) |
| 1150 return; | 1138 return; |
| 1151 syncable::ModelTypeSet encrypted_types = GetEncryptedTypes(trans); | 1139 syncable::ModelTypeSet encrypted_types = GetEncryptedTypes(trans); |
| 1152 ModelSafeRoutingInfo routes; | 1140 ModelSafeRoutingInfo routes; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1209 if (!child.InitByIdLookup(child_id)) { | 1197 if (!child.InitByIdLookup(child_id)) { |
| 1210 NOTREACHED(); | 1198 NOTREACHED(); |
| 1211 return; | 1199 return; |
| 1212 } | 1200 } |
| 1213 child.SetPasswordSpecifics(child.GetPasswordSpecifics()); | 1201 child.SetPasswordSpecifics(child.GetPasswordSpecifics()); |
| 1214 child_id = child.GetSuccessorId(); | 1202 child_id = child.GetSuccessorId(); |
| 1215 } | 1203 } |
| 1216 } | 1204 } |
| 1217 } | 1205 } |
| 1218 | 1206 |
| 1219 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1207 // NOTE: We notify from within a transaction. |
| 1220 OnEncryptionComplete(encrypted_types)); | 1208 FOR_EACH_OBSERVER( |
| 1209 SyncManager::Observer, observers_, OnEncryptionComplete()); |
| 1221 } | 1210 } |
| 1222 | 1211 |
| 1223 SyncManager::~SyncManager() { | 1212 SyncManager::~SyncManager() { |
| 1224 DCHECK(thread_checker_.CalledOnValidThread()); | 1213 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1225 delete data_; | 1214 delete data_; |
| 1226 } | 1215 } |
| 1227 | 1216 |
| 1228 void SyncManager::AddChangeObserver(ChangeObserver* observer) { | 1217 void SyncManager::AddChangeObserver(ChangeObserver* observer) { |
| 1229 DCHECK(thread_checker_.CalledOnValidThread()); | 1218 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1230 data_->AddChangeObserver(observer); | 1219 data_->AddChangeObserver(observer); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1287 | 1276 |
| 1288 if (connection_manager_.get()) { | 1277 if (connection_manager_.get()) { |
| 1289 connection_manager_->RemoveListener(this); | 1278 connection_manager_->RemoveListener(this); |
| 1290 } | 1279 } |
| 1291 connection_manager_.reset(); | 1280 connection_manager_.reset(); |
| 1292 | 1281 |
| 1293 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 1282 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 1294 observing_ip_address_changes_ = false; | 1283 observing_ip_address_changes_ = false; |
| 1295 | 1284 |
| 1296 if (dir_manager()) { | 1285 if (dir_manager()) { |
| 1297 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); | 1286 { |
| 1298 if (lookup.good()) { | 1287 // Cryptographer should only be accessed while holding a |
| 1299 lookup->RemoveTransactionObserver(&js_mutation_event_observer_); | 1288 // transaction. |
| 1289 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 1290 trans.GetCryptographer()->RemoveObserver(this); |
| 1291 trans.GetLookup()-> |
| 1292 RemoveTransactionObserver(&js_mutation_event_observer_); |
| 1300 RemoveChangeObserver(&js_mutation_event_observer_); | 1293 RemoveChangeObserver(&js_mutation_event_observer_); |
| 1301 } else { | |
| 1302 NOTREACHED(); | |
| 1303 } | 1294 } |
| 1304 dir_manager()->FinalSaveChangesForAll(); | 1295 dir_manager()->FinalSaveChangesForAll(); |
| 1305 dir_manager()->Close(username_for_share()); | 1296 dir_manager()->Close(username_for_share()); |
| 1306 } | 1297 } |
| 1307 | 1298 |
| 1308 // Reset the DirectoryManager and UserSettings so they relinquish sqlite | 1299 // Reset the DirectoryManager and UserSettings so they relinquish sqlite |
| 1309 // handles to backing files. | 1300 // handles to backing files. |
| 1310 share_.dir_manager.reset(); | 1301 share_.dir_manager.reset(); |
| 1311 | 1302 |
| 1312 setup_for_test_mode_ = false; | 1303 setup_for_test_mode_ = false; |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1615 event.snapshot->initial_sync_ended.test(syncable::NIGORI)) { | 1606 event.snapshot->initial_sync_ended.test(syncable::NIGORI)) { |
| 1616 VLOG(1) << "OnPassphraseRequired sent because cryptographer is not " | 1607 VLOG(1) << "OnPassphraseRequired sent because cryptographer is not " |
| 1617 << "ready"; | 1608 << "ready"; |
| 1618 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1609 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1619 OnPassphraseRequired(sync_api::REASON_ENCRYPTION)); | 1610 OnPassphraseRequired(sync_api::REASON_ENCRYPTION)); |
| 1620 } | 1611 } |
| 1621 | 1612 |
| 1622 allstatus_.SetCryptographerReady(cryptographer->is_ready()); | 1613 allstatus_.SetCryptographerReady(cryptographer->is_ready()); |
| 1623 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); | 1614 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); |
| 1624 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); | 1615 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); |
| 1625 | |
| 1626 // If everything is in order(we have the passphrase) then there is no | |
| 1627 // need to inform the listeners. They will just wait for sync | |
| 1628 // completion event and if no errors have been raised it means | |
| 1629 // encryption was succesful. | |
| 1630 } | 1616 } |
| 1631 | 1617 |
| 1632 if (!initialized_) { | 1618 if (!initialized_) { |
| 1633 LOG(INFO) << "OnSyncCycleCompleted not sent because sync api is not " | 1619 LOG(INFO) << "OnSyncCycleCompleted not sent because sync api is not " |
| 1634 << "initialized"; | 1620 << "initialized"; |
| 1635 return; | 1621 return; |
| 1636 } | 1622 } |
| 1637 | 1623 |
| 1638 if (!event.snapshot->has_more_to_sync) { | 1624 if (!event.snapshot->has_more_to_sync) { |
| 1639 VLOG(1) << "OnSyncCycleCompleted sent"; | 1625 VLOG(1) << "Sending OnSyncCycleCompleted"; |
| 1640 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1626 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 1641 OnSyncCycleCompleted(event.snapshot)); | 1627 OnSyncCycleCompleted(event.snapshot)); |
| 1642 } | 1628 } |
| 1643 | 1629 |
| 1644 // This is here for tests, which are still using p2p notifications. | 1630 // This is here for tests, which are still using p2p notifications. |
| 1645 // | 1631 // |
| 1646 // TODO(chron): Consider changing this back to track has_more_to_sync | 1632 // TODO(chron): Consider changing this back to track has_more_to_sync |
| 1647 // only notify peers if a successful commit has occurred. | 1633 // only notify peers if a successful commit has occurred. |
| 1648 bool is_notifiable_commit = | 1634 bool is_notifiable_commit = |
| 1649 (event.snapshot->syncer_status.num_successful_commits > 0); | 1635 (event.snapshot->syncer_status.num_successful_commits > 0); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1869 entry_kernels.begin(); it != entry_kernels.end(); ++it) { | 1855 entry_kernels.begin(); it != entry_kernels.end(); ++it) { |
| 1870 if ((*it)->ContainsString(lowercase_query)) { | 1856 if ((*it)->ContainsString(lowercase_query)) { |
| 1871 result->Append(new StringValue(base::Int64ToString( | 1857 result->Append(new StringValue(base::Int64ToString( |
| 1872 (*it)->ref(syncable::META_HANDLE)))); | 1858 (*it)->ref(syncable::META_HANDLE)))); |
| 1873 } | 1859 } |
| 1874 } | 1860 } |
| 1875 | 1861 |
| 1876 return JsArgList(&return_args); | 1862 return JsArgList(&return_args); |
| 1877 } | 1863 } |
| 1878 | 1864 |
| 1865 void SyncManager::SyncInternal::OnEncryptedTypesChanged( |
| 1866 const syncable::ModelTypeSet& encrypted_types, |
| 1867 bool encrypt_everything) { |
| 1868 // NOTE: We're in a transaction. |
| 1869 FOR_EACH_OBSERVER( |
| 1870 SyncManager::Observer, observers_, |
| 1871 OnEncryptedTypesChanged(encrypted_types, encrypt_everything)); |
| 1872 } |
| 1873 |
| 1879 void SyncManager::SyncInternal::OnNotificationStateChange( | 1874 void SyncManager::SyncInternal::OnNotificationStateChange( |
| 1880 bool notifications_enabled) { | 1875 bool notifications_enabled) { |
| 1881 VLOG(1) << "P2P: Notifications enabled = " | 1876 VLOG(1) << "P2P: Notifications enabled = " |
| 1882 << (notifications_enabled ? "true" : "false"); | 1877 << (notifications_enabled ? "true" : "false"); |
| 1883 allstatus_.SetNotificationsEnabled(notifications_enabled); | 1878 allstatus_.SetNotificationsEnabled(notifications_enabled); |
| 1884 if (scheduler()) { | 1879 if (scheduler()) { |
| 1885 scheduler()->set_notifications_enabled(notifications_enabled); | 1880 scheduler()->set_notifications_enabled(notifications_enabled); |
| 1886 } | 1881 } |
| 1887 if (js_event_handler_.IsInitialized()) { | 1882 if (js_event_handler_.IsInitialized()) { |
| 1888 DictionaryValue details; | 1883 DictionaryValue details; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1997 lookup->SaveChanges(); | 1992 lookup->SaveChanges(); |
| 1998 } | 1993 } |
| 1999 | 1994 |
| 2000 UserShare* SyncManager::GetUserShare() const { | 1995 UserShare* SyncManager::GetUserShare() const { |
| 2001 return data_->GetUserShare(); | 1996 return data_->GetUserShare(); |
| 2002 } | 1997 } |
| 2003 | 1998 |
| 2004 void SyncManager::RefreshEncryption() { | 1999 void SyncManager::RefreshEncryption() { |
| 2005 DCHECK(thread_checker_.CalledOnValidThread()); | 2000 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2006 if (data_->UpdateCryptographerFromNigori()) | 2001 if (data_->UpdateCryptographerFromNigori()) |
| 2007 data_->EncryptDataTypes(syncable::ModelTypeSet()); | 2002 data_->RefreshEncryption(); |
| 2008 } | 2003 } |
| 2009 | 2004 |
| 2010 syncable::ModelTypeSet SyncManager::GetEncryptedDataTypes() const { | 2005 syncable::ModelTypeSet SyncManager::GetEncryptedDataTypesForTest() const { |
| 2011 ReadTransaction trans(FROM_HERE, GetUserShare()); | 2006 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 2012 return GetEncryptedTypes(&trans); | 2007 return GetEncryptedTypes(&trans); |
| 2013 } | 2008 } |
| 2014 | 2009 |
| 2015 bool SyncManager::ReceivedExperimentalTypes(syncable::ModelTypeSet* to_add) | 2010 bool SyncManager::ReceivedExperimentalTypes(syncable::ModelTypeSet* to_add) |
| 2016 const { | 2011 const { |
| 2017 ReadTransaction trans(FROM_HERE, GetUserShare()); | 2012 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 2018 ReadNode node(&trans); | 2013 ReadNode node(&trans); |
| 2019 if (!node.InitByTagLookup(kNigoriTag)) { | 2014 if (!node.InitByTagLookup(kNigoriTag)) { |
| 2020 VLOG(1) << "Couldn't find Nigori node."; | 2015 VLOG(1) << "Couldn't find Nigori node."; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2078 | 2073 |
| 2079 for (syncable::ModelTypeSet::const_iterator i = types.begin(); | 2074 for (syncable::ModelTypeSet::const_iterator i = types.begin(); |
| 2080 i != types.end(); ++i) { | 2075 i != types.end(); ++i) { |
| 2081 if (!lookup->initial_sync_ended_for_type(*i)) | 2076 if (!lookup->initial_sync_ended_for_type(*i)) |
| 2082 return false; | 2077 return false; |
| 2083 } | 2078 } |
| 2084 return true; | 2079 return true; |
| 2085 } | 2080 } |
| 2086 | 2081 |
| 2087 } // namespace sync_api | 2082 } // namespace sync_api |
| OLD | NEW |