Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(441)

Side by Side Diff: chrome/browser/sync/internal_api/sync_manager.cc

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

Powered by Google App Engine
This is Rietveld 408576698