OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include <iomanip> | 9 #include <iomanip> |
10 #include <list> | 10 #include <list> |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "chrome/browser/sync/engine/syncer.h" | 33 #include "chrome/browser/sync/engine/syncer.h" |
34 #include "chrome/browser/sync/engine/syncer_thread.h" | 34 #include "chrome/browser/sync/engine/syncer_thread.h" |
35 #include "chrome/browser/sync/notifier/server_notifier_thread.h" | 35 #include "chrome/browser/sync/notifier/server_notifier_thread.h" |
36 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 36 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
37 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 37 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
38 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | 38 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
39 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" | 39 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" |
40 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 40 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
41 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" | 41 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" |
42 #include "chrome/browser/sync/protocol/service_constants.h" | 42 #include "chrome/browser/sync/protocol/service_constants.h" |
| 43 #include "chrome/browser/sync/protocol/sync.pb.h" |
43 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" | 44 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" |
44 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" | 45 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" |
45 #include "chrome/browser/sync/sessions/sync_session_context.h" | 46 #include "chrome/browser/sync/sessions/sync_session_context.h" |
46 #include "chrome/browser/sync/syncable/directory_manager.h" | 47 #include "chrome/browser/sync/syncable/directory_manager.h" |
47 #include "chrome/browser/sync/syncable/syncable.h" | 48 #include "chrome/browser/sync/syncable/syncable.h" |
48 #include "chrome/browser/sync/util/character_set_converters.h" | 49 #include "chrome/browser/sync/util/character_set_converters.h" |
49 #include "chrome/browser/sync/util/closure.h" | 50 #include "chrome/browser/sync/util/closure.h" |
50 #include "chrome/browser/sync/util/crypto_helpers.h" | 51 #include "chrome/browser/sync/util/crypto_helpers.h" |
51 #include "chrome/browser/sync/util/path_helpers.h" | 52 #include "chrome/browser/sync/util/path_helpers.h" |
52 #include "chrome/browser/sync/util/user_settings.h" | 53 #include "chrome/browser/sync/util/user_settings.h" |
53 #include "chrome/common/chrome_switches.h" | 54 #include "chrome/common/chrome_switches.h" |
54 #include "chrome/common/deprecated/event_sys.h" | 55 #include "chrome/common/deprecated/event_sys.h" |
55 #include "chrome/common/net/gaia/gaia_authenticator.h" | 56 #include "chrome/common/net/gaia/gaia_authenticator.h" |
56 #include "chrome/common/net/network_change_notifier_proxy.h" | 57 #include "chrome/common/net/network_change_notifier_proxy.h" |
57 #include "chrome/common/net/notifier/listener/mediator_thread_impl.h" | 58 #include "chrome/common/net/notifier/listener/mediator_thread_impl.h" |
58 #include "chrome/common/net/notifier/listener/notification_constants.h" | 59 #include "chrome/common/net/notifier/listener/notification_constants.h" |
59 #include "chrome/common/net/notifier/listener/talk_mediator.h" | 60 #include "chrome/common/net/notifier/listener/talk_mediator.h" |
60 #include "chrome/common/net/notifier/listener/talk_mediator_impl.h" | 61 #include "chrome/common/net/notifier/listener/talk_mediator_impl.h" |
61 #include "net/base/network_change_notifier.h" | 62 #include "net/base/network_change_notifier.h" |
62 | 63 |
63 using browser_sync::AllStatus; | 64 using browser_sync::AllStatus; |
64 using browser_sync::AllStatusEvent; | 65 using browser_sync::AllStatusEvent; |
65 using browser_sync::AuthWatcher; | 66 using browser_sync::AuthWatcher; |
66 using browser_sync::AuthWatcherEvent; | 67 using browser_sync::AuthWatcherEvent; |
| 68 using browser_sync::Cryptographer; |
| 69 using browser_sync::KeyParams; |
67 using browser_sync::ModelSafeRoutingInfo; | 70 using browser_sync::ModelSafeRoutingInfo; |
68 using browser_sync::ModelSafeWorker; | 71 using browser_sync::ModelSafeWorker; |
69 using browser_sync::ModelSafeWorkerRegistrar; | 72 using browser_sync::ModelSafeWorkerRegistrar; |
70 using browser_sync::Syncer; | 73 using browser_sync::Syncer; |
71 using browser_sync::SyncerEvent; | 74 using browser_sync::SyncerEvent; |
72 using browser_sync::SyncerThread; | 75 using browser_sync::SyncerThread; |
73 using browser_sync::UserSettings; | 76 using browser_sync::UserSettings; |
| 77 using browser_sync::kNigoriTag; |
74 using browser_sync::sessions::SyncSessionContext; | 78 using browser_sync::sessions::SyncSessionContext; |
75 using notifier::TalkMediator; | 79 using notifier::TalkMediator; |
76 using notifier::TalkMediatorImpl; | 80 using notifier::TalkMediatorImpl; |
77 using std::list; | 81 using std::list; |
78 using std::hex; | 82 using std::hex; |
79 using std::string; | 83 using std::string; |
80 using std::vector; | 84 using std::vector; |
81 using syncable::Directory; | 85 using syncable::Directory; |
82 using syncable::DirectoryManager; | 86 using syncable::DirectoryManager; |
| 87 using syncable::Entry; |
83 using syncable::SPECIFICS; | 88 using syncable::SPECIFICS; |
84 | 89 |
85 typedef GoogleServiceAuthError AuthError; | 90 typedef GoogleServiceAuthError AuthError; |
86 | 91 |
87 static const int kThreadExitTimeoutMsec = 60000; | 92 static const int kThreadExitTimeoutMsec = 60000; |
88 static const int kSSLPort = 443; | 93 static const int kSSLPort = 443; |
89 | 94 |
90 // We manage the lifetime of sync_api::SyncManager::SyncInternal ourselves. | 95 // We manage the lifetime of sync_api::SyncManager::SyncInternal ourselves. |
91 DISABLE_RUNNABLE_METHOD_REFCOUNT(sync_api::SyncManager::SyncInternal); | 96 DISABLE_RUNNABLE_METHOD_REFCOUNT(sync_api::SyncManager::SyncInternal); |
92 | 97 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 syncable::AddDefaultExtensionValue(model_type, &serialized_type); | 172 syncable::AddDefaultExtensionValue(model_type, &serialized_type); |
168 std::string hash_input; | 173 std::string hash_input; |
169 serialized_type.AppendToString(&hash_input); | 174 serialized_type.AppendToString(&hash_input); |
170 hash_input.append(client_tag); | 175 hash_input.append(client_tag); |
171 | 176 |
172 std::string encode_output; | 177 std::string encode_output; |
173 CHECK(base::Base64Encode(base::SHA1HashString(hash_input), &encode_output)); | 178 CHECK(base::Base64Encode(base::SHA1HashString(hash_input), &encode_output)); |
174 return encode_output; | 179 return encode_output; |
175 } | 180 } |
176 | 181 |
| 182 bool BaseNode::DecryptIfNecessary(Entry* entry) { |
| 183 if (GetIsFolder()) return true; // Ignore the top-level password folder. |
| 184 const sync_pb::EntitySpecifics& specifics = |
| 185 entry->Get(syncable::SPECIFICS); |
| 186 if (specifics.HasExtension(sync_pb::password)) { |
| 187 const sync_pb::EncryptedData& encrypted = |
| 188 specifics.GetExtension(sync_pb::password).encrypted(); |
| 189 scoped_ptr<sync_pb::PasswordSpecificsData> data( |
| 190 new sync_pb::PasswordSpecificsData); |
| 191 if (!GetTransaction()->GetCryptographer()->Decrypt(encrypted, |
| 192 data.get())) |
| 193 return false; |
| 194 password_data_.swap(data); |
| 195 } |
| 196 return true; |
| 197 } |
| 198 |
177 int64 BaseNode::GetParentId() const { | 199 int64 BaseNode::GetParentId() const { |
178 return IdToMetahandle(GetTransaction()->GetWrappedTrans(), | 200 return IdToMetahandle(GetTransaction()->GetWrappedTrans(), |
179 GetEntry()->Get(syncable::PARENT_ID)); | 201 GetEntry()->Get(syncable::PARENT_ID)); |
180 } | 202 } |
181 | 203 |
182 int64 BaseNode::GetId() const { | 204 int64 BaseNode::GetId() const { |
183 return GetEntry()->Get(syncable::META_HANDLE); | 205 return GetEntry()->Get(syncable::META_HANDLE); |
184 } | 206 } |
185 | 207 |
186 bool BaseNode::GetIsFolder() const { | 208 bool BaseNode::GetIsFolder() const { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 const sync_pb::BookmarkSpecifics& BaseNode::GetBookmarkSpecifics() const { | 264 const sync_pb::BookmarkSpecifics& BaseNode::GetBookmarkSpecifics() const { |
243 DCHECK(GetModelType() == syncable::BOOKMARKS); | 265 DCHECK(GetModelType() == syncable::BOOKMARKS); |
244 return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::bookmark); | 266 return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::bookmark); |
245 } | 267 } |
246 | 268 |
247 const sync_pb::NigoriSpecifics& BaseNode::GetNigoriSpecifics() const { | 269 const sync_pb::NigoriSpecifics& BaseNode::GetNigoriSpecifics() const { |
248 DCHECK(GetModelType() == syncable::NIGORI); | 270 DCHECK(GetModelType() == syncable::NIGORI); |
249 return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::nigori); | 271 return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::nigori); |
250 } | 272 } |
251 | 273 |
252 bool BaseNode::GetPasswordSpecifics(sync_pb::PasswordSpecificsData* data) | 274 const sync_pb::PasswordSpecificsData& BaseNode::GetPasswordSpecifics() const { |
253 const { | |
254 DCHECK(GetModelType() == syncable::PASSWORDS); | 275 DCHECK(GetModelType() == syncable::PASSWORDS); |
255 DCHECK(data); | 276 DCHECK(password_data_.get()); |
256 const sync_pb::PasswordSpecifics& specifics = | 277 return *password_data_; |
257 GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::password); | |
258 return data->ParseFromString(specifics.blob()); | |
259 } | 278 } |
260 | 279 |
261 const sync_pb::PreferenceSpecifics& BaseNode::GetPreferenceSpecifics() const { | 280 const sync_pb::PreferenceSpecifics& BaseNode::GetPreferenceSpecifics() const { |
262 DCHECK(GetModelType() == syncable::PREFERENCES); | 281 DCHECK(GetModelType() == syncable::PREFERENCES); |
263 return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::preference); | 282 return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::preference); |
264 } | 283 } |
265 | 284 |
266 const sync_pb::ThemeSpecifics& BaseNode::GetThemeSpecifics() const { | 285 const sync_pb::ThemeSpecifics& BaseNode::GetThemeSpecifics() const { |
267 DCHECK(GetModelType() == syncable::THEMES); | 286 DCHECK(GetModelType() == syncable::THEMES); |
268 return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::theme); | 287 return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::theme); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 entity_specifics.MutableExtension(sync_pb::nigori)->CopyFrom(new_value); | 368 entity_specifics.MutableExtension(sync_pb::nigori)->CopyFrom(new_value); |
350 PutSpecificsAndMarkForSyncing(entity_specifics); | 369 PutSpecificsAndMarkForSyncing(entity_specifics); |
351 } | 370 } |
352 | 371 |
353 void WriteNode::SetPasswordSpecifics( | 372 void WriteNode::SetPasswordSpecifics( |
354 const sync_pb::PasswordSpecificsData& data) { | 373 const sync_pb::PasswordSpecificsData& data) { |
355 DCHECK(GetModelType() == syncable::PASSWORDS); | 374 DCHECK(GetModelType() == syncable::PASSWORDS); |
356 std::string serialized_data; | 375 std::string serialized_data; |
357 data.SerializeToString(&serialized_data); | 376 data.SerializeToString(&serialized_data); |
358 sync_pb::PasswordSpecifics new_value; | 377 sync_pb::PasswordSpecifics new_value; |
359 new_value.set_blob(serialized_data); | 378 if (!GetTransaction()->GetCryptographer()->Encrypt( |
| 379 data, |
| 380 new_value.mutable_encrypted())) |
| 381 NOTREACHED(); |
| 382 |
360 PutPasswordSpecificsAndMarkForSyncing(new_value); | 383 PutPasswordSpecificsAndMarkForSyncing(new_value); |
361 } | 384 } |
362 | 385 |
363 void WriteNode::SetPreferenceSpecifics( | 386 void WriteNode::SetPreferenceSpecifics( |
364 const sync_pb::PreferenceSpecifics& new_value) { | 387 const sync_pb::PreferenceSpecifics& new_value) { |
365 DCHECK(GetModelType() == syncable::PREFERENCES); | 388 DCHECK(GetModelType() == syncable::PREFERENCES); |
366 PutPreferenceSpecificsAndMarkForSyncing(new_value); | 389 PutPreferenceSpecificsAndMarkForSyncing(new_value); |
367 } | 390 } |
368 | 391 |
369 void WriteNode::SetThemeSpecifics( | 392 void WriteNode::SetThemeSpecifics( |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 delete entry_; | 467 delete entry_; |
445 } | 468 } |
446 | 469 |
447 // Find an existing node matching the ID |id|, and bind this WriteNode to it. | 470 // Find an existing node matching the ID |id|, and bind this WriteNode to it. |
448 // Return true on success. | 471 // Return true on success. |
449 bool WriteNode::InitByIdLookup(int64 id) { | 472 bool WriteNode::InitByIdLookup(int64 id) { |
450 DCHECK(!entry_) << "Init called twice"; | 473 DCHECK(!entry_) << "Init called twice"; |
451 DCHECK_NE(id, kInvalidId); | 474 DCHECK_NE(id, kInvalidId); |
452 entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), | 475 entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), |
453 syncable::GET_BY_HANDLE, id); | 476 syncable::GET_BY_HANDLE, id); |
454 return (entry_->good() && !entry_->Get(syncable::IS_DEL)); | 477 return (entry_->good() && !entry_->Get(syncable::IS_DEL) && |
| 478 DecryptIfNecessary(entry_)); |
455 } | 479 } |
456 | 480 |
457 // Find a node by client tag, and bind this WriteNode to it. | 481 // Find a node by client tag, and bind this WriteNode to it. |
458 // Return true if the write node was found, and was not deleted. | 482 // Return true if the write node was found, and was not deleted. |
459 // Undeleting a deleted node is possible by ClientTag. | 483 // Undeleting a deleted node is possible by ClientTag. |
460 bool WriteNode::InitByClientTagLookup(syncable::ModelType model_type, | 484 bool WriteNode::InitByClientTagLookup(syncable::ModelType model_type, |
461 const std::string& tag) { | 485 const std::string& tag) { |
462 DCHECK(!entry_) << "Init called twice"; | 486 DCHECK(!entry_) << "Init called twice"; |
463 if (tag.empty()) | 487 if (tag.empty()) |
464 return false; | 488 return false; |
465 | 489 |
466 const std::string hash = GenerateSyncableHash(model_type, tag); | 490 const std::string hash = GenerateSyncableHash(model_type, tag); |
467 | 491 |
468 entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), | 492 entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), |
469 syncable::GET_BY_CLIENT_TAG, hash); | 493 syncable::GET_BY_CLIENT_TAG, hash); |
470 return (entry_->good() && !entry_->Get(syncable::IS_DEL)); | 494 return (entry_->good() && !entry_->Get(syncable::IS_DEL) && |
| 495 DecryptIfNecessary(entry_)); |
471 } | 496 } |
472 | 497 |
473 bool WriteNode::InitByTagLookup(const std::string& tag) { | 498 bool WriteNode::InitByTagLookup(const std::string& tag) { |
474 DCHECK(!entry_) << "Init called twice"; | 499 DCHECK(!entry_) << "Init called twice"; |
475 if (tag.empty()) | 500 if (tag.empty()) |
476 return false; | 501 return false; |
477 entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), | 502 entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), |
478 syncable::GET_BY_SERVER_TAG, tag); | 503 syncable::GET_BY_SERVER_TAG, tag); |
479 if (!entry_->good()) | 504 if (!entry_->good()) |
480 return false; | 505 return false; |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 syncable::BaseTransaction* trans = transaction_->GetWrappedTrans(); | 721 syncable::BaseTransaction* trans = transaction_->GetWrappedTrans(); |
697 entry_ = new syncable::Entry(trans, syncable::GET_BY_HANDLE, id); | 722 entry_ = new syncable::Entry(trans, syncable::GET_BY_HANDLE, id); |
698 if (!entry_->good()) | 723 if (!entry_->good()) |
699 return false; | 724 return false; |
700 if (entry_->Get(syncable::IS_DEL)) | 725 if (entry_->Get(syncable::IS_DEL)) |
701 return false; | 726 return false; |
702 syncable::ModelType model_type = GetModelType(); | 727 syncable::ModelType model_type = GetModelType(); |
703 LOG_IF(WARNING, model_type == syncable::UNSPECIFIED || | 728 LOG_IF(WARNING, model_type == syncable::UNSPECIFIED || |
704 model_type == syncable::TOP_LEVEL_FOLDER) | 729 model_type == syncable::TOP_LEVEL_FOLDER) |
705 << "SyncAPI InitByIdLookup referencing unusual object."; | 730 << "SyncAPI InitByIdLookup referencing unusual object."; |
706 return true; | 731 return DecryptIfNecessary(entry_); |
707 } | 732 } |
708 | 733 |
709 bool ReadNode::InitByClientTagLookup(syncable::ModelType model_type, | 734 bool ReadNode::InitByClientTagLookup(syncable::ModelType model_type, |
710 const std::string& tag) { | 735 const std::string& tag) { |
711 DCHECK(!entry_) << "Init called twice"; | 736 DCHECK(!entry_) << "Init called twice"; |
712 if (tag.empty()) | 737 if (tag.empty()) |
713 return false; | 738 return false; |
714 | 739 |
715 const std::string hash = GenerateSyncableHash(model_type, tag); | 740 const std::string hash = GenerateSyncableHash(model_type, tag); |
716 | 741 |
717 entry_ = new syncable::Entry(transaction_->GetWrappedTrans(), | 742 entry_ = new syncable::Entry(transaction_->GetWrappedTrans(), |
718 syncable::GET_BY_CLIENT_TAG, hash); | 743 syncable::GET_BY_CLIENT_TAG, hash); |
719 return (entry_->good() && !entry_->Get(syncable::IS_DEL)); | 744 return (entry_->good() && !entry_->Get(syncable::IS_DEL) && |
| 745 DecryptIfNecessary(entry_)); |
720 } | 746 } |
721 | 747 |
722 const syncable::Entry* ReadNode::GetEntry() const { | 748 const syncable::Entry* ReadNode::GetEntry() const { |
723 return entry_; | 749 return entry_; |
724 } | 750 } |
725 | 751 |
726 const BaseTransaction* ReadNode::GetTransaction() const { | 752 const BaseTransaction* ReadNode::GetTransaction() const { |
727 return transaction_; | 753 return transaction_; |
728 } | 754 } |
729 | 755 |
730 bool ReadNode::InitByTagLookup(const std::string& tag) { | 756 bool ReadNode::InitByTagLookup(const std::string& tag) { |
731 DCHECK(!entry_) << "Init called twice"; | 757 DCHECK(!entry_) << "Init called twice"; |
732 if (tag.empty()) | 758 if (tag.empty()) |
733 return false; | 759 return false; |
734 syncable::BaseTransaction* trans = transaction_->GetWrappedTrans(); | 760 syncable::BaseTransaction* trans = transaction_->GetWrappedTrans(); |
735 entry_ = new syncable::Entry(trans, syncable::GET_BY_SERVER_TAG, tag); | 761 entry_ = new syncable::Entry(trans, syncable::GET_BY_SERVER_TAG, tag); |
736 if (!entry_->good()) | 762 if (!entry_->good()) |
737 return false; | 763 return false; |
738 if (entry_->Get(syncable::IS_DEL)) | 764 if (entry_->Get(syncable::IS_DEL)) |
739 return false; | 765 return false; |
740 syncable::ModelType model_type = GetModelType(); | 766 syncable::ModelType model_type = GetModelType(); |
741 LOG_IF(WARNING, model_type == syncable::UNSPECIFIED || | 767 LOG_IF(WARNING, model_type == syncable::UNSPECIFIED || |
742 model_type == syncable::TOP_LEVEL_FOLDER) | 768 model_type == syncable::TOP_LEVEL_FOLDER) |
743 << "SyncAPI InitByTagLookup referencing unusually typed object."; | 769 << "SyncAPI InitByTagLookup referencing unusually typed object."; |
744 return true; | 770 return DecryptIfNecessary(entry_); |
745 } | 771 } |
746 | 772 |
747 ////////////////////////////////////////////////////////////////////////// | 773 ////////////////////////////////////////////////////////////////////////// |
748 // ReadTransaction member definitions | 774 // ReadTransaction member definitions |
749 ReadTransaction::ReadTransaction(UserShare* share) | 775 ReadTransaction::ReadTransaction(UserShare* share) |
750 : BaseTransaction(share), | 776 : BaseTransaction(share), |
751 transaction_(NULL) { | 777 transaction_(NULL) { |
752 transaction_ = new syncable::ReadTransaction(GetLookup(), __FILE__, __LINE__); | 778 transaction_ = new syncable::ReadTransaction(GetLookup(), __FILE__, __LINE__); |
753 } | 779 } |
754 | 780 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 // If authentication fails, an event will be broadcast all the way up to | 910 // If authentication fails, an event will be broadcast all the way up to |
885 // the SyncManager::Observer. It may, in turn, decide to try again with new | 911 // the SyncManager::Observer. It may, in turn, decide to try again with new |
886 // credentials. Calling this method again is the appropriate course of action | 912 // credentials. Calling this method again is the appropriate course of action |
887 // to "retry". | 913 // to "retry". |
888 void Authenticate(const std::string& username, const std::string& password, | 914 void Authenticate(const std::string& username, const std::string& password, |
889 const std::string& captcha); | 915 const std::string& captcha); |
890 | 916 |
891 // Tell the sync engine to start the syncing process. | 917 // Tell the sync engine to start the syncing process. |
892 void StartSyncing(); | 918 void StartSyncing(); |
893 | 919 |
| 920 void SetPassphrase(const std::string& passphrase); |
| 921 |
894 // Call periodically from a database-safe thread to persist recent changes | 922 // Call periodically from a database-safe thread to persist recent changes |
895 // to the syncapi model. | 923 // to the syncapi model. |
896 void SaveChanges(); | 924 void SaveChanges(); |
897 | 925 |
898 // This listener is called upon completion of a syncable transaction, and | 926 // This listener is called upon completion of a syncable transaction, and |
899 // builds the list of sync-engine initiated changes that will be forwarded to | 927 // builds the list of sync-engine initiated changes that will be forwarded to |
900 // the SyncManager's Observers. | 928 // the SyncManager's Observers. |
901 virtual void HandleChannelEvent(const syncable::DirectoryChangeEvent& event); | 929 virtual void HandleChannelEvent(const syncable::DirectoryChangeEvent& event); |
902 void HandleTransactionCompleteChangeEvent( | 930 void HandleTransactionCompleteChangeEvent( |
903 const syncable::DirectoryChangeEvent& event); | 931 const syncable::DirectoryChangeEvent& event); |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 void SyncManager::Authenticate(const char* username, const char* password, | 1236 void SyncManager::Authenticate(const char* username, const char* password, |
1209 const char* captcha) { | 1237 const char* captcha) { |
1210 data_->Authenticate(std::string(username), std::string(password), | 1238 data_->Authenticate(std::string(username), std::string(password), |
1211 std::string(captcha)); | 1239 std::string(captcha)); |
1212 } | 1240 } |
1213 | 1241 |
1214 void SyncManager::StartSyncing() { | 1242 void SyncManager::StartSyncing() { |
1215 data_->StartSyncing(); | 1243 data_->StartSyncing(); |
1216 } | 1244 } |
1217 | 1245 |
| 1246 void SyncManager::SetPassphrase(const std::string& passphrase) { |
| 1247 data_->SetPassphrase(passphrase); |
| 1248 } |
| 1249 |
1218 bool SyncManager::RequestPause() { | 1250 bool SyncManager::RequestPause() { |
1219 return data_->syncer_thread()->RequestPause(); | 1251 return data_->syncer_thread()->RequestPause(); |
1220 } | 1252 } |
1221 | 1253 |
1222 bool SyncManager::RequestResume() { | 1254 bool SyncManager::RequestResume() { |
1223 return data_->syncer_thread()->RequestResume(); | 1255 return data_->syncer_thread()->RequestResume(); |
1224 } | 1256 } |
1225 | 1257 |
1226 void SyncManager::RequestNudge() { | 1258 void SyncManager::RequestNudge() { |
1227 data_->syncer_thread()->NudgeSyncer(0, SyncerThread::kLocal); | 1259 data_->syncer_thread()->NudgeSyncer(0, SyncerThread::kLocal); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1475 auth_watcher()->AuthenticateWithToken(username, auth_token); | 1507 auth_watcher()->AuthenticateWithToken(username, auth_token); |
1476 return true; | 1508 return true; |
1477 } | 1509 } |
1478 | 1510 |
1479 void SyncManager::SyncInternal::RaiseAuthNeededEvent() { | 1511 void SyncManager::SyncInternal::RaiseAuthNeededEvent() { |
1480 auth_problem_ = AuthError::INVALID_GAIA_CREDENTIALS; | 1512 auth_problem_ = AuthError::INVALID_GAIA_CREDENTIALS; |
1481 if (observer_) | 1513 if (observer_) |
1482 observer_->OnAuthError(AuthError(auth_problem_)); | 1514 observer_->OnAuthError(AuthError(auth_problem_)); |
1483 } | 1515 } |
1484 | 1516 |
| 1517 void SyncManager::SyncInternal::SetPassphrase( |
| 1518 const std::string& passphrase) { |
| 1519 Cryptographer* cryptographer = dir_manager()->cryptographer(); |
| 1520 KeyParams params = {"localhost", "dummy", passphrase}; |
| 1521 if (cryptographer->has_pending_keys()) { |
| 1522 if (!cryptographer->DecryptPendingKeys(params)) { |
| 1523 observer_->OnPassphraseRequired(); |
| 1524 return; |
| 1525 } |
| 1526 // Nudge the syncer so that passwords updates that were waiting for this |
| 1527 // passphrase get applied as soon as possible. |
| 1528 sync_manager_->RequestNudge(); |
| 1529 } else { |
| 1530 cryptographer->AddKey(params); |
| 1531 // TODO(albertb): Update the Nigori node on the server with the new keys. |
| 1532 } |
| 1533 observer_->OnPassphraseAccepted(); |
| 1534 } |
| 1535 |
1485 SyncManager::~SyncManager() { | 1536 SyncManager::~SyncManager() { |
1486 delete data_; | 1537 delete data_; |
1487 } | 1538 } |
1488 | 1539 |
1489 void SyncManager::SetObserver(Observer* observer) { | 1540 void SyncManager::SetObserver(Observer* observer) { |
1490 data_->set_observer(observer); | 1541 data_->set_observer(observer); |
1491 } | 1542 } |
1492 | 1543 |
1493 void SyncManager::RemoveObserver() { | 1544 void SyncManager::RemoveObserver() { |
1494 data_->set_observer(NULL); | 1545 data_->set_observer(NULL); |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1760 allstatus_.status().max_consecutive_errors}; | 1811 allstatus_.status().max_consecutive_errors}; |
1761 return return_status; | 1812 return return_status; |
1762 } | 1813 } |
1763 | 1814 |
1764 void SyncManager::SyncInternal::HandleChannelEvent(const SyncerEvent& event) { | 1815 void SyncManager::SyncInternal::HandleChannelEvent(const SyncerEvent& event) { |
1765 if (!initialized()) { | 1816 if (!initialized()) { |
1766 // This could be the first time that the syncer has completed a full | 1817 // This could be the first time that the syncer has completed a full |
1767 // download; if so, we should signal that initialization is complete. | 1818 // download; if so, we should signal that initialization is complete. |
1768 if (event.snapshot->is_share_usable) | 1819 if (event.snapshot->is_share_usable) |
1769 MarkAndNotifyInitializationComplete(); | 1820 MarkAndNotifyInitializationComplete(); |
1770 return; | |
1771 } | 1821 } |
1772 | 1822 |
1773 if (!observer_) | 1823 if (!observer_) |
1774 return; | 1824 return; |
1775 | 1825 |
1776 // Only send an event if this is due to a cycle ending and this cycle | 1826 // Only send an event if this is due to a cycle ending and this cycle |
1777 // concludes a canonical "sync" process; that is, based on what is known | 1827 // concludes a canonical "sync" process; that is, based on what is known |
1778 // locally we are "all happy" and up-to-date. There may be new changes on | 1828 // locally we are "all happy" and up-to-date. There may be new changes on |
1779 // the server, but we'll get them on a subsequent sync. | 1829 // the server, but we'll get them on a subsequent sync. |
1780 // | 1830 // |
1781 // Notifications are sent at the end of every sync cycle, regardless of | 1831 // Notifications are sent at the end of every sync cycle, regardless of |
1782 // whether we should sync again. | 1832 // whether we should sync again. |
1783 if (event.what_happened == SyncerEvent::SYNC_CYCLE_ENDED) { | 1833 if (event.what_happened == SyncerEvent::SYNC_CYCLE_ENDED) { |
| 1834 |
| 1835 ModelSafeRoutingInfo enabled_types; |
| 1836 registrar_->GetModelSafeRoutingInfo(&enabled_types); |
| 1837 if (enabled_types.count(syncable::PASSWORDS) > 0) { |
| 1838 Cryptographer* cryptographer = |
| 1839 GetUserShare()->dir_manager->cryptographer(); |
| 1840 if (!cryptographer->is_ready() && !cryptographer->has_pending_keys()) { |
| 1841 sync_api::ReadTransaction trans(GetUserShare()); |
| 1842 sync_api::ReadNode node(&trans); |
| 1843 if (!node.InitByTagLookup(kNigoriTag)) { |
| 1844 NOTREACHED(); |
| 1845 return; |
| 1846 } |
| 1847 const sync_pb::NigoriSpecifics& nigori = node.GetNigoriSpecifics(); |
| 1848 if (!nigori.encrypted().blob().empty()) { |
| 1849 if (cryptographer->CanDecrypt(nigori.encrypted())) { |
| 1850 cryptographer->SetKeys(nigori.encrypted()); |
| 1851 } else { |
| 1852 cryptographer->SetPendingKeys(nigori.encrypted()); |
| 1853 } |
| 1854 } |
| 1855 } |
| 1856 // If we've completed a sync cycle and the cryptographer isn't ready yet, |
| 1857 // prompt the user for a passphrase. |
| 1858 if (!cryptographer->is_ready()) { |
| 1859 observer_->OnPassphraseRequired(); |
| 1860 } |
| 1861 } |
| 1862 |
| 1863 if (!initialized()) |
| 1864 return; |
| 1865 |
1784 if (!event.snapshot->has_more_to_sync) { | 1866 if (!event.snapshot->has_more_to_sync) { |
1785 observer_->OnSyncCycleCompleted(event.snapshot); | 1867 observer_->OnSyncCycleCompleted(event.snapshot); |
1786 } | 1868 } |
1787 | 1869 |
1788 if (notification_method_ != browser_sync::NOTIFICATION_SERVER) { | 1870 if (notification_method_ != browser_sync::NOTIFICATION_SERVER) { |
1789 // TODO(chron): Consider changing this back to track has_more_to_sync | 1871 // TODO(chron): Consider changing this back to track has_more_to_sync |
1790 // only notify peers if a successful commit has occurred. | 1872 // only notify peers if a successful commit has occurred. |
1791 bool new_pending_notification = | 1873 bool new_pending_notification = |
1792 (event.snapshot->syncer_status.num_successful_commits > 0); | 1874 (event.snapshot->syncer_status.num_successful_commits > 0); |
1793 core_message_loop_->PostTask( | 1875 core_message_loop_->PostTask( |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2019 } | 2101 } |
2020 MarkAndNotifyInitializationComplete(); | 2102 MarkAndNotifyInitializationComplete(); |
2021 } | 2103 } |
2022 | 2104 |
2023 ////////////////////////////////////////////////////////////////////////// | 2105 ////////////////////////////////////////////////////////////////////////// |
2024 // BaseTransaction member definitions | 2106 // BaseTransaction member definitions |
2025 BaseTransaction::BaseTransaction(UserShare* share) | 2107 BaseTransaction::BaseTransaction(UserShare* share) |
2026 : lookup_(NULL) { | 2108 : lookup_(NULL) { |
2027 DCHECK(share && share->dir_manager.get()); | 2109 DCHECK(share && share->dir_manager.get()); |
2028 lookup_ = new syncable::ScopedDirLookup(share->dir_manager.get(), | 2110 lookup_ = new syncable::ScopedDirLookup(share->dir_manager.get(), |
2029 share->authenticated_name); | 2111 share->authenticated_name); |
| 2112 cryptographer_ = share->dir_manager->cryptographer(); |
2030 if (!(lookup_->good())) | 2113 if (!(lookup_->good())) |
2031 DCHECK(false) << "ScopedDirLookup failed on valid DirManager."; | 2114 DCHECK(false) << "ScopedDirLookup failed on valid DirManager."; |
2032 } | 2115 } |
2033 BaseTransaction::~BaseTransaction() { | 2116 BaseTransaction::~BaseTransaction() { |
2034 delete lookup_; | 2117 delete lookup_; |
2035 } | 2118 } |
2036 | 2119 |
2037 UserShare* SyncManager::GetUserShare() const { | 2120 UserShare* SyncManager::GetUserShare() const { |
2038 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; | 2121 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; |
2039 return data_->GetUserShare(); | 2122 return data_->GetUserShare(); |
2040 } | 2123 } |
2041 | 2124 |
2042 SyncManager::ExtraAutofillChangeRecordData::~ExtraAutofillChangeRecordData() { | 2125 SyncManager::ExtraAutofillChangeRecordData::~ExtraAutofillChangeRecordData() { |
2043 delete pre_deletion_data; | 2126 delete pre_deletion_data; |
2044 } | 2127 } |
2045 | 2128 |
2046 } // namespace sync_api | 2129 } // namespace sync_api |
OLD | NEW |