OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "sync/internal_api/sync_manager_impl.h" | 5 #include "sync/internal_api/sync_manager_impl.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include <string> | 10 #include <string> |
8 | 11 |
9 #include "base/base64.h" | 12 #include "base/base64.h" |
10 #include "base/bind.h" | 13 #include "base/bind.h" |
11 #include "base/callback.h" | 14 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
13 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
14 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
15 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
16 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 type, write_transaction_info.Get().id, it->second); | 676 type, write_transaction_info.Get().id, it->second); |
674 models_with_changes.Put(type); | 677 models_with_changes.Put(type); |
675 } | 678 } |
676 change_records_.clear(); | 679 change_records_.clear(); |
677 return models_with_changes; | 680 return models_with_changes; |
678 } | 681 } |
679 | 682 |
680 void SyncManagerImpl::HandleCalculateChangesChangeEventFromSyncApi( | 683 void SyncManagerImpl::HandleCalculateChangesChangeEventFromSyncApi( |
681 const ImmutableWriteTransactionInfo& write_transaction_info, | 684 const ImmutableWriteTransactionInfo& write_transaction_info, |
682 syncable::BaseTransaction* trans, | 685 syncable::BaseTransaction* trans, |
683 std::vector<int64>* entries_changed) { | 686 std::vector<int64_t>* entries_changed) { |
684 // We have been notified about a user action changing a sync model. | 687 // We have been notified about a user action changing a sync model. |
685 LOG_IF(WARNING, !change_records_.empty()) << | 688 LOG_IF(WARNING, !change_records_.empty()) << |
686 "CALCULATE_CHANGES called with unapplied old changes."; | 689 "CALCULATE_CHANGES called with unapplied old changes."; |
687 | 690 |
688 // The mutated model type, or UNSPECIFIED if nothing was mutated. | 691 // The mutated model type, or UNSPECIFIED if nothing was mutated. |
689 ModelTypeSet mutated_model_types; | 692 ModelTypeSet mutated_model_types; |
690 | 693 |
691 const syncable::ImmutableEntryKernelMutationMap& mutations = | 694 const syncable::ImmutableEntryKernelMutationMap& mutations = |
692 write_transaction_info.Get().mutations; | 695 write_transaction_info.Get().mutations; |
693 for (syncable::EntryKernelMutationMap::const_iterator it = | 696 for (syncable::EntryKernelMutationMap::const_iterator it = |
(...skipping 22 matching lines...) Expand all Loading... |
716 weak_handle_this_.Call(FROM_HERE, | 719 weak_handle_this_.Call(FROM_HERE, |
717 &SyncManagerImpl::RequestNudgeForDataTypes, | 720 &SyncManagerImpl::RequestNudgeForDataTypes, |
718 FROM_HERE, | 721 FROM_HERE, |
719 mutated_model_types); | 722 mutated_model_types); |
720 } else { | 723 } else { |
721 NOTREACHED(); | 724 NOTREACHED(); |
722 } | 725 } |
723 } | 726 } |
724 } | 727 } |
725 | 728 |
726 void SyncManagerImpl::SetExtraChangeRecordData(int64 id, | 729 void SyncManagerImpl::SetExtraChangeRecordData( |
727 ModelType type, ChangeReorderBuffer* buffer, | 730 int64_t id, |
728 Cryptographer* cryptographer, const syncable::EntryKernel& original, | 731 ModelType type, |
729 bool existed_before, bool exists_now) { | 732 ChangeReorderBuffer* buffer, |
| 733 Cryptographer* cryptographer, |
| 734 const syncable::EntryKernel& original, |
| 735 bool existed_before, |
| 736 bool exists_now) { |
730 // If this is a deletion and the datatype was encrypted, we need to decrypt it | 737 // If this is a deletion and the datatype was encrypted, we need to decrypt it |
731 // and attach it to the buffer. | 738 // and attach it to the buffer. |
732 if (!exists_now && existed_before) { | 739 if (!exists_now && existed_before) { |
733 sync_pb::EntitySpecifics original_specifics(original.ref(SPECIFICS)); | 740 sync_pb::EntitySpecifics original_specifics(original.ref(SPECIFICS)); |
734 if (type == PASSWORDS) { | 741 if (type == PASSWORDS) { |
735 // Passwords must use their own legacy ExtraPasswordChangeRecordData. | 742 // Passwords must use their own legacy ExtraPasswordChangeRecordData. |
736 scoped_ptr<sync_pb::PasswordSpecificsData> data( | 743 scoped_ptr<sync_pb::PasswordSpecificsData> data( |
737 DecryptPasswordSpecifics(original_specifics, cryptographer)); | 744 DecryptPasswordSpecifics(original_specifics, cryptographer)); |
738 if (!data) { | 745 if (!data) { |
739 NOTREACHED(); | 746 NOTREACHED(); |
740 return; | 747 return; |
741 } | 748 } |
742 buffer->SetExtraDataForId(id, new ExtraPasswordChangeRecordData(*data)); | 749 buffer->SetExtraDataForId(id, new ExtraPasswordChangeRecordData(*data)); |
743 } else if (original_specifics.has_encrypted()) { | 750 } else if (original_specifics.has_encrypted()) { |
744 // All other datatypes can just create a new unencrypted specifics and | 751 // All other datatypes can just create a new unencrypted specifics and |
745 // attach it. | 752 // attach it. |
746 const sync_pb::EncryptedData& encrypted = original_specifics.encrypted(); | 753 const sync_pb::EncryptedData& encrypted = original_specifics.encrypted(); |
747 if (!cryptographer->Decrypt(encrypted, &original_specifics)) { | 754 if (!cryptographer->Decrypt(encrypted, &original_specifics)) { |
748 NOTREACHED(); | 755 NOTREACHED(); |
749 return; | 756 return; |
750 } | 757 } |
751 } | 758 } |
752 buffer->SetSpecificsForId(id, original_specifics); | 759 buffer->SetSpecificsForId(id, original_specifics); |
753 } | 760 } |
754 } | 761 } |
755 | 762 |
756 void SyncManagerImpl::HandleCalculateChangesChangeEventFromSyncer( | 763 void SyncManagerImpl::HandleCalculateChangesChangeEventFromSyncer( |
757 const ImmutableWriteTransactionInfo& write_transaction_info, | 764 const ImmutableWriteTransactionInfo& write_transaction_info, |
758 syncable::BaseTransaction* trans, | 765 syncable::BaseTransaction* trans, |
759 std::vector<int64>* entries_changed) { | 766 std::vector<int64_t>* entries_changed) { |
760 // We only expect one notification per sync step, so change_buffers_ should | 767 // We only expect one notification per sync step, so change_buffers_ should |
761 // contain no pending entries. | 768 // contain no pending entries. |
762 LOG_IF(WARNING, !change_records_.empty()) << | 769 LOG_IF(WARNING, !change_records_.empty()) << |
763 "CALCULATE_CHANGES called with unapplied old changes."; | 770 "CALCULATE_CHANGES called with unapplied old changes."; |
764 | 771 |
765 ChangeReorderBuffer change_buffers[MODEL_TYPE_COUNT]; | 772 ChangeReorderBuffer change_buffers[MODEL_TYPE_COUNT]; |
766 | 773 |
767 Cryptographer* crypto = directory()->GetCryptographer(trans); | 774 Cryptographer* crypto = directory()->GetCryptographer(trans); |
768 const syncable::ImmutableEntryKernelMutationMap& mutations = | 775 const syncable::ImmutableEntryKernelMutationMap& mutations = |
769 write_transaction_info.Get().mutations; | 776 write_transaction_info.Get().mutations; |
770 for (syncable::EntryKernelMutationMap::const_iterator it = | 777 for (syncable::EntryKernelMutationMap::const_iterator it = |
771 mutations.Get().begin(); it != mutations.Get().end(); ++it) { | 778 mutations.Get().begin(); it != mutations.Get().end(); ++it) { |
772 bool existed_before = !it->second.original.ref(syncable::IS_DEL); | 779 bool existed_before = !it->second.original.ref(syncable::IS_DEL); |
773 bool exists_now = !it->second.mutated.ref(syncable::IS_DEL); | 780 bool exists_now = !it->second.mutated.ref(syncable::IS_DEL); |
774 | 781 |
775 // Omit items that aren't associated with a model. | 782 // Omit items that aren't associated with a model. |
776 ModelType type = | 783 ModelType type = |
777 GetModelTypeFromSpecifics(it->second.mutated.ref(SPECIFICS)); | 784 GetModelTypeFromSpecifics(it->second.mutated.ref(SPECIFICS)); |
778 if (type < FIRST_REAL_MODEL_TYPE) | 785 if (type < FIRST_REAL_MODEL_TYPE) |
779 continue; | 786 continue; |
780 | 787 |
781 int64 handle = it->first; | 788 int64_t handle = it->first; |
782 if (exists_now && !existed_before) | 789 if (exists_now && !existed_before) |
783 change_buffers[type].PushAddedItem(handle); | 790 change_buffers[type].PushAddedItem(handle); |
784 else if (!exists_now && existed_before) | 791 else if (!exists_now && existed_before) |
785 change_buffers[type].PushDeletedItem(handle); | 792 change_buffers[type].PushDeletedItem(handle); |
786 else if (exists_now && existed_before && | 793 else if (exists_now && existed_before && |
787 VisiblePropertiesDiffer(it->second, crypto)) | 794 VisiblePropertiesDiffer(it->second, crypto)) |
788 change_buffers[type].PushUpdatedItem(handle); | 795 change_buffers[type].PushUpdatedItem(handle); |
789 | 796 |
790 SetExtraChangeRecordData(handle, type, &change_buffers[type], crypto, | 797 SetExtraChangeRecordData(handle, type, &change_buffers[type], crypto, |
791 it->second.original, existed_before, exists_now); | 798 it->second.original, existed_before, exists_now); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 } | 1046 } |
1040 | 1047 |
1041 void SyncManagerImpl::ClearServerData(const ClearServerDataCallback& callback) { | 1048 void SyncManagerImpl::ClearServerData(const ClearServerDataCallback& callback) { |
1042 DCHECK(thread_checker_.CalledOnValidThread()); | 1049 DCHECK(thread_checker_.CalledOnValidThread()); |
1043 scheduler_->Start(SyncScheduler::CLEAR_SERVER_DATA_MODE, base::Time()); | 1050 scheduler_->Start(SyncScheduler::CLEAR_SERVER_DATA_MODE, base::Time()); |
1044 ClearParams params(callback); | 1051 ClearParams params(callback); |
1045 scheduler_->ScheduleClearServerData(params); | 1052 scheduler_->ScheduleClearServerData(params); |
1046 } | 1053 } |
1047 | 1054 |
1048 } // namespace syncer | 1055 } // namespace syncer |
OLD | NEW |