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/engine/process_updates_command.h" | 5 #include "sync/engine/process_updates_command.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "sync/engine/syncer.h" | 11 #include "sync/engine/syncer.h" |
12 #include "sync/engine/syncer_proto_util.h" | 12 #include "sync/engine/syncer_proto_util.h" |
13 #include "sync/engine/syncer_util.h" | 13 #include "sync/engine/syncer_util.h" |
14 #include "sync/engine/syncproto.h" | |
15 #include "sync/sessions/sync_session.h" | 14 #include "sync/sessions/sync_session.h" |
16 #include "sync/syncable/directory.h" | 15 #include "sync/syncable/directory.h" |
17 #include "sync/syncable/mutable_entry.h" | 16 #include "sync/syncable/mutable_entry.h" |
17 #include "sync/syncable/syncable_proto_util.h" | |
18 #include "sync/syncable/syncable_util.h" | 18 #include "sync/syncable/syncable_util.h" |
19 #include "sync/syncable/write_transaction.h" | 19 #include "sync/syncable/write_transaction.h" |
20 #include "sync/util/cryptographer.h" | 20 #include "sync/util/cryptographer.h" |
21 | 21 |
22 using std::vector; | 22 using std::vector; |
23 | 23 |
24 namespace syncer { | 24 namespace syncer { |
25 | 25 |
26 using sessions::SyncSession; | 26 using sessions::SyncSession; |
27 using sessions::StatusController; | 27 using sessions::StatusController; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 StatusController* status = session->mutable_status_controller(); | 68 StatusController* status = session->mutable_status_controller(); |
69 status->mutable_update_progress()->ClearVerifiedUpdates(); | 69 status->mutable_update_progress()->ClearVerifiedUpdates(); |
70 return SYNCER_OK; | 70 return SYNCER_OK; |
71 } | 71 } |
72 | 72 |
73 namespace { | 73 namespace { |
74 // Returns true if the entry is still ok to process. | 74 // Returns true if the entry is still ok to process. |
75 bool ReverifyEntry(syncable::WriteTransaction* trans, const SyncEntity& entry, | 75 bool ReverifyEntry(syncable::WriteTransaction* trans, |
76 const sync_pb::SyncEntity& entry, | |
76 syncable::MutableEntry* same_id) { | 77 syncable::MutableEntry* same_id) { |
77 | 78 |
78 const bool deleted = entry.has_deleted() && entry.deleted(); | 79 const bool deleted = entry.has_deleted() && entry.deleted(); |
79 const bool is_directory = entry.IsFolder(); | 80 const bool is_directory = IsFolder(entry); |
80 const syncer::ModelType model_type = entry.GetModelType(); | 81 const syncer::ModelType model_type = GetModelType(entry); |
81 | 82 |
82 return VERIFY_SUCCESS == VerifyUpdateConsistency(trans, | 83 return VERIFY_SUCCESS == VerifyUpdateConsistency(trans, |
83 entry, | 84 entry, |
84 same_id, | 85 same_id, |
85 deleted, | 86 deleted, |
86 is_directory, | 87 is_directory, |
87 model_type); | 88 model_type); |
88 } | 89 } |
89 } // namespace | 90 } // namespace |
90 | 91 |
91 // Process a single update. Will avoid touching global state. | 92 // Process a single update. Will avoid touching global state. |
92 ServerUpdateProcessingResult ProcessUpdatesCommand::ProcessUpdate( | 93 ServerUpdateProcessingResult ProcessUpdatesCommand::ProcessUpdate( |
93 const sync_pb::SyncEntity& proto_update, | 94 const sync_pb::SyncEntity& proto_update, |
94 const Cryptographer* cryptographer, | 95 const Cryptographer* cryptographer, |
95 syncable::WriteTransaction* const trans) { | 96 syncable::WriteTransaction* const trans) { |
96 | 97 |
97 const SyncEntity& update = *static_cast<const SyncEntity*>(&proto_update); | 98 const sync_pb::SyncEntity& update = |
98 syncable::Id server_id = update.id(); | 99 *static_cast<const sync_pb::SyncEntity*>(&proto_update); |
akalin
2012/07/11 01:42:22
static cast
rlarocque
2012/07/11 19:22:16
Done.
| |
100 syncable::Id server_id = SyncableIdFromProto(update.id_string()); | |
99 const std::string name = SyncerProtoUtil::NameFromSyncEntity(update); | 101 const std::string name = SyncerProtoUtil::NameFromSyncEntity(update); |
100 | 102 |
101 // Look to see if there's a local item that should recieve this update, | 103 // Look to see if there's a local item that should recieve this update, |
102 // maybe due to a duplicate client tag or a lost commit response. | 104 // maybe due to a duplicate client tag or a lost commit response. |
103 syncable::Id local_id = FindLocalIdToUpdate(trans, update); | 105 syncable::Id local_id = FindLocalIdToUpdate(trans, update); |
104 | 106 |
105 // FindLocalEntryToUpdate has veto power. | 107 // FindLocalEntryToUpdate has veto power. |
106 if (local_id.IsNull()) { | 108 if (local_id.IsNull()) { |
107 return SUCCESS_PROCESSED; // The entry has become irrelevant. | 109 return SUCCESS_PROCESSED; // The entry has become irrelevant. |
108 } | 110 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 // Force application of this update, no matter what. | 145 // Force application of this update, no matter what. |
144 target_entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); | 146 target_entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); |
145 } | 147 } |
146 | 148 |
147 // If this is a newly received undecryptable update, and the only thing that | 149 // If this is a newly received undecryptable update, and the only thing that |
148 // has changed are the specifics, store the original decryptable specifics, | 150 // has changed are the specifics, store the original decryptable specifics, |
149 // (on which any current or future local changes are based) before we | 151 // (on which any current or future local changes are based) before we |
150 // overwrite SERVER_SPECIFICS. | 152 // overwrite SERVER_SPECIFICS. |
151 // MTIME, CTIME, and NON_UNIQUE_NAME are not enforced. | 153 // MTIME, CTIME, and NON_UNIQUE_NAME are not enforced. |
152 if (!update.deleted() && !target_entry.Get(syncable::SERVER_IS_DEL) && | 154 if (!update.deleted() && !target_entry.Get(syncable::SERVER_IS_DEL) && |
153 (update.parent_id() == target_entry.Get(syncable::SERVER_PARENT_ID)) && | 155 (SyncableIdFromProto(update.parent_id_string()) == |
156 target_entry.Get(syncable::SERVER_PARENT_ID)) && | |
154 (update.position_in_parent() == | 157 (update.position_in_parent() == |
155 target_entry.Get(syncable::SERVER_POSITION_IN_PARENT)) && | 158 target_entry.Get(syncable::SERVER_POSITION_IN_PARENT)) && |
156 update.has_specifics() && update.specifics().has_encrypted() && | 159 update.has_specifics() && update.specifics().has_encrypted() && |
157 !cryptographer->CanDecrypt(update.specifics().encrypted())) { | 160 !cryptographer->CanDecrypt(update.specifics().encrypted())) { |
158 sync_pb::EntitySpecifics prev_specifics = | 161 sync_pb::EntitySpecifics prev_specifics = |
159 target_entry.Get(syncable::SERVER_SPECIFICS); | 162 target_entry.Get(syncable::SERVER_SPECIFICS); |
160 // We only store the old specifics if they were decryptable and applied and | 163 // We only store the old specifics if they were decryptable and applied and |
161 // there is no BASE_SERVER_SPECIFICS already. Else do nothing. | 164 // there is no BASE_SERVER_SPECIFICS already. Else do nothing. |
162 if (!target_entry.Get(syncable::IS_UNAPPLIED_UPDATE) && | 165 if (!target_entry.Get(syncable::IS_UNAPPLIED_UPDATE) && |
163 !syncer::IsRealDataType(syncer::GetModelTypeFromSpecifics( | 166 !syncer::IsRealDataType(syncer::GetModelTypeFromSpecifics( |
(...skipping 12 matching lines...) Expand all Loading... | |
176 target_entry.Put(syncable::BASE_SERVER_SPECIFICS, | 179 target_entry.Put(syncable::BASE_SERVER_SPECIFICS, |
177 sync_pb::EntitySpecifics()); | 180 sync_pb::EntitySpecifics()); |
178 } | 181 } |
179 | 182 |
180 UpdateServerFieldsFromUpdate(&target_entry, update, name); | 183 UpdateServerFieldsFromUpdate(&target_entry, update, name); |
181 | 184 |
182 return SUCCESS_PROCESSED; | 185 return SUCCESS_PROCESSED; |
183 } | 186 } |
184 | 187 |
185 } // namespace syncer | 188 } // namespace syncer |
OLD | NEW |