| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/conflict_resolver.h" | 5 #include "sync/engine/conflict_resolver.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 namespace syncer { | 24 namespace syncer { |
| 25 | 25 |
| 26 using sessions::StatusController; | 26 using sessions::StatusController; |
| 27 using syncable::Directory; | 27 using syncable::Directory; |
| 28 using syncable::Entry; | 28 using syncable::Entry; |
| 29 using syncable::Id; | 29 using syncable::Id; |
| 30 using syncable::MutableEntry; | 30 using syncable::MutableEntry; |
| 31 using syncable::WriteTransaction; | 31 using syncable::WriteTransaction; |
| 32 | 32 |
| 33 namespace { |
| 34 |
| 35 // Returns true iff the set of attachment ids contained in attachment_metadata |
| 36 // matches the set of ids contained in server_attachment_metadata. |
| 37 bool AttachmentMetadataMatches(const MutableEntry& entity) { |
| 38 const sync_pb::AttachmentMetadata& local = entity.GetAttachmentMetadata(); |
| 39 const sync_pb::AttachmentMetadata& server = |
| 40 entity.GetServerAttachmentMetadata(); |
| 41 if (local.record_size() != server.record_size()) { |
| 42 return false; |
| 43 } |
| 44 |
| 45 // The order of records in local and server may be different so use a std::set |
| 46 // to determine if they are equivalent. |
| 47 std::set<std::string> local_ids; |
| 48 for (int i = 0; i < local.record_size(); ++i) { |
| 49 const sync_pb::AttachmentMetadataRecord& record = local.record(i); |
| 50 DCHECK(record.is_on_server()); |
| 51 local_ids.insert(record.id().SerializeAsString()); |
| 52 } |
| 53 for (int i = 0; i < server.record_size(); ++i) { |
| 54 const sync_pb::AttachmentMetadataRecord& record = server.record(i); |
| 55 DCHECK(record.is_on_server()); |
| 56 if (local_ids.find(record.id().SerializeAsString()) == local_ids.end()) { |
| 57 return false; |
| 58 } |
| 59 } |
| 60 |
| 61 return true; |
| 62 } |
| 63 |
| 64 } // namespace |
| 65 |
| 33 ConflictResolver::ConflictResolver() { | 66 ConflictResolver::ConflictResolver() { |
| 34 } | 67 } |
| 35 | 68 |
| 36 ConflictResolver::~ConflictResolver() { | 69 ConflictResolver::~ConflictResolver() { |
| 37 } | 70 } |
| 38 | 71 |
| 39 void ConflictResolver::ProcessSimpleConflict(WriteTransaction* trans, | 72 void ConflictResolver::ProcessSimpleConflict(WriteTransaction* trans, |
| 40 const Id& id, | 73 const Id& id, |
| 41 const Cryptographer* cryptographer, | 74 const Cryptographer* cryptographer, |
| 42 StatusController* status, | 75 StatusController* status, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 decrypted_base_server_specifics = | 174 decrypted_base_server_specifics = |
| 142 base_server_specifics.SerializeAsString(); | 175 base_server_specifics.SerializeAsString(); |
| 143 } else { | 176 } else { |
| 144 decrypted_base_server_specifics = cryptographer->DecryptToString( | 177 decrypted_base_server_specifics = cryptographer->DecryptToString( |
| 145 base_server_specifics.encrypted()); | 178 base_server_specifics.encrypted()); |
| 146 } | 179 } |
| 147 if (decrypted_server_specifics == decrypted_base_server_specifics) | 180 if (decrypted_server_specifics == decrypted_base_server_specifics) |
| 148 base_server_specifics_match = true; | 181 base_server_specifics_match = true; |
| 149 } | 182 } |
| 150 | 183 |
| 184 bool attachment_metadata_matches = AttachmentMetadataMatches(entry); |
| 151 if (!entry_deleted && name_matches && parent_matches && specifics_match && | 185 if (!entry_deleted && name_matches && parent_matches && specifics_match && |
| 152 position_matches) { | 186 position_matches && attachment_metadata_matches) { |
| 153 DVLOG(1) << "Resolving simple conflict, everything matches, ignoring " | 187 DVLOG(1) << "Resolving simple conflict, everything matches, ignoring " |
| 154 << "changes for: " << entry; | 188 << "changes for: " << entry; |
| 155 conflict_util::IgnoreConflict(&entry); | 189 conflict_util::IgnoreConflict(&entry); |
| 156 UMA_HISTOGRAM_ENUMERATION("Sync.ResolveSimpleConflict", | 190 UMA_HISTOGRAM_ENUMERATION("Sync.ResolveSimpleConflict", |
| 157 CHANGES_MATCH, | 191 CHANGES_MATCH, |
| 158 CONFLICT_RESOLUTION_SIZE); | 192 CONFLICT_RESOLUTION_SIZE); |
| 159 } else if (base_server_specifics_match) { | 193 } else if (base_server_specifics_match) { |
| 160 DVLOG(1) << "Resolving simple conflict, ignoring server encryption " | 194 DVLOG(1) << "Resolving simple conflict, ignoring server encryption " |
| 161 << " changes for: " << entry; | 195 << " changes for: " << entry; |
| 162 status->increment_num_server_overwrites(); | 196 status->increment_num_server_overwrites(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 GetModelTypeFromSpecifics(conflicting_node.GetSpecifics()))) { | 269 GetModelTypeFromSpecifics(conflicting_node.GetSpecifics()))) { |
| 236 continue; | 270 continue; |
| 237 } | 271 } |
| 238 | 272 |
| 239 ProcessSimpleConflict(trans, *it, cryptographer, status, counters); | 273 ProcessSimpleConflict(trans, *it, cryptographer, status, counters); |
| 240 } | 274 } |
| 241 return; | 275 return; |
| 242 } | 276 } |
| 243 | 277 |
| 244 } // namespace syncer | 278 } // namespace syncer |
| OLD | NEW |