| 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/verify_updates_command.h" | 5 #include "sync/engine/verify_updates_command.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "sync/engine/syncer.h" | 10 #include "sync/engine/syncer.h" |
| 11 #include "sync/engine/syncer_proto_util.h" | 11 #include "sync/engine/syncer_proto_util.h" |
| 12 #include "sync/engine/syncer_types.h" | 12 #include "sync/engine/syncer_types.h" |
| 13 #include "sync/engine/syncer_util.h" | 13 #include "sync/engine/syncer_util.h" |
| 14 #include "sync/engine/syncproto.h" | 14 #include "sync/engine/syncproto.h" |
| 15 #include "sync/internal_api/public/engine/model_safe_worker.h" | 15 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| 16 #include "sync/protocol/bookmark_specifics.pb.h" | 16 #include "sync/protocol/bookmark_specifics.pb.h" |
| 17 #include "sync/syncable/entry.h" | 17 #include "sync/syncable/entry.h" |
| 18 #include "sync/syncable/mutable_entry.h" | 18 #include "sync/syncable/mutable_entry.h" |
| 19 #include "sync/syncable/write_transaction.h" | 19 #include "sync/syncable/write_transaction.h" |
| 20 | 20 |
| 21 namespace syncer { | 21 namespace syncer { |
| 22 | 22 |
| 23 using syncable::GET_BY_ID; | 23 using syncable::GET_BY_ID; |
| 24 using syncable::ModelTypeSet; | 24 using syncer::ModelTypeSet; |
| 25 using syncable::SYNCER; | 25 using syncable::SYNCER; |
| 26 using syncable::WriteTransaction; | 26 using syncable::WriteTransaction; |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // This function attempts to determine whether or not this update is genuinely | 30 // This function attempts to determine whether or not this update is genuinely |
| 31 // new, or if it is a reflection of one of our own commits. | 31 // new, or if it is a reflection of one of our own commits. |
| 32 // | 32 // |
| 33 // There is a known inaccuracy in its implementation. If this update ends up | 33 // There is a known inaccuracy in its implementation. If this update ends up |
| 34 // being applied to a local item with a different ID, we will count the change | 34 // being applied to a local item with a different ID, we will count the change |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 VerifyUpdatesCommand::~VerifyUpdatesCommand() {} | 77 VerifyUpdatesCommand::~VerifyUpdatesCommand() {} |
| 78 | 78 |
| 79 std::set<ModelSafeGroup> VerifyUpdatesCommand::GetGroupsToChange( | 79 std::set<ModelSafeGroup> VerifyUpdatesCommand::GetGroupsToChange( |
| 80 const sessions::SyncSession& session) const { | 80 const sessions::SyncSession& session) const { |
| 81 std::set<ModelSafeGroup> groups_with_updates; | 81 std::set<ModelSafeGroup> groups_with_updates; |
| 82 | 82 |
| 83 const GetUpdatesResponse& updates = | 83 const GetUpdatesResponse& updates = |
| 84 session.status_controller().updates_response().get_updates(); | 84 session.status_controller().updates_response().get_updates(); |
| 85 for (int i = 0; i < updates.entries().size(); i++) { | 85 for (int i = 0; i < updates.entries().size(); i++) { |
| 86 groups_with_updates.insert( | 86 groups_with_updates.insert( |
| 87 GetGroupForModelType(syncable::GetModelType(updates.entries(i)), | 87 GetGroupForModelType(syncer::GetModelType(updates.entries(i)), |
| 88 session.routing_info())); | 88 session.routing_info())); |
| 89 } | 89 } |
| 90 | 90 |
| 91 return groups_with_updates; | 91 return groups_with_updates; |
| 92 } | 92 } |
| 93 | 93 |
| 94 SyncerError VerifyUpdatesCommand::ModelChangingExecuteImpl( | 94 SyncerError VerifyUpdatesCommand::ModelChangingExecuteImpl( |
| 95 sessions::SyncSession* session) { | 95 sessions::SyncSession* session) { |
| 96 DVLOG(1) << "Beginning Update Verification"; | 96 DVLOG(1) << "Beginning Update Verification"; |
| 97 syncable::Directory* dir = session->context()->directory(); | 97 syncable::Directory* dir = session->context()->directory(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 128 | 128 |
| 129 VerifyUpdatesCommand::VerifyUpdateResult VerifyUpdatesCommand::VerifyUpdate( | 129 VerifyUpdatesCommand::VerifyUpdateResult VerifyUpdatesCommand::VerifyUpdate( |
| 130 syncable::WriteTransaction* trans, const SyncEntity& entry, | 130 syncable::WriteTransaction* trans, const SyncEntity& entry, |
| 131 const ModelTypeSet& requested_types, | 131 const ModelTypeSet& requested_types, |
| 132 const ModelSafeRoutingInfo& routes) { | 132 const ModelSafeRoutingInfo& routes) { |
| 133 syncable::Id id = entry.id(); | 133 syncable::Id id = entry.id(); |
| 134 VerifyUpdateResult result = {VERIFY_FAIL, GROUP_PASSIVE}; | 134 VerifyUpdateResult result = {VERIFY_FAIL, GROUP_PASSIVE}; |
| 135 | 135 |
| 136 const bool deleted = entry.has_deleted() && entry.deleted(); | 136 const bool deleted = entry.has_deleted() && entry.deleted(); |
| 137 const bool is_directory = entry.IsFolder(); | 137 const bool is_directory = entry.IsFolder(); |
| 138 const syncable::ModelType model_type = entry.GetModelType(); | 138 const syncer::ModelType model_type = entry.GetModelType(); |
| 139 | 139 |
| 140 if (!id.ServerKnows()) { | 140 if (!id.ServerKnows()) { |
| 141 LOG(ERROR) << "Illegal negative id in received updates"; | 141 LOG(ERROR) << "Illegal negative id in received updates"; |
| 142 return result; | 142 return result; |
| 143 } | 143 } |
| 144 { | 144 { |
| 145 const std::string name = SyncerProtoUtil::NameFromSyncEntity(entry); | 145 const std::string name = SyncerProtoUtil::NameFromSyncEntity(entry); |
| 146 if (name.empty() && !deleted) { | 146 if (name.empty() && !deleted) { |
| 147 LOG(ERROR) << "Zero length name in non-deleted update"; | 147 LOG(ERROR) << "Zero length name in non-deleted update"; |
| 148 return result; | 148 return result; |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 syncable::MutableEntry same_id(trans, GET_BY_ID, id); | 152 syncable::MutableEntry same_id(trans, GET_BY_ID, id); |
| 153 result.value = VerifyNewEntry(entry, &same_id, deleted); | 153 result.value = VerifyNewEntry(entry, &same_id, deleted); |
| 154 | 154 |
| 155 syncable::ModelType placement_type = !deleted ? entry.GetModelType() | 155 syncer::ModelType placement_type = !deleted ? entry.GetModelType() |
| 156 : same_id.good() ? same_id.GetModelType() : syncable::UNSPECIFIED; | 156 : same_id.good() ? same_id.GetModelType() : syncer::UNSPECIFIED; |
| 157 result.placement = GetGroupForModelType(placement_type, routes); | 157 result.placement = GetGroupForModelType(placement_type, routes); |
| 158 | 158 |
| 159 if (VERIFY_UNDECIDED == result.value) { | 159 if (VERIFY_UNDECIDED == result.value) { |
| 160 result.value = VerifyTagConsistency(entry, same_id); | 160 result.value = VerifyTagConsistency(entry, same_id); |
| 161 } | 161 } |
| 162 | 162 |
| 163 if (VERIFY_UNDECIDED == result.value) { | 163 if (VERIFY_UNDECIDED == result.value) { |
| 164 if (deleted) { | 164 if (deleted) { |
| 165 // For deletes the server could send tombostones for items that | 165 // For deletes the server could send tombostones for items that |
| 166 // the client did not request. If so ignore those items. | 166 // the client did not request. If so ignore those items. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 180 deleted, is_directory, model_type); | 180 deleted, is_directory, model_type); |
| 181 } | 181 } |
| 182 | 182 |
| 183 if (VERIFY_UNDECIDED == result.value) | 183 if (VERIFY_UNDECIDED == result.value) |
| 184 result.value = VERIFY_SUCCESS; // No news is good news. | 184 result.value = VERIFY_SUCCESS; // No news is good news. |
| 185 | 185 |
| 186 return result; // This might be VERIFY_SUCCESS as well | 186 return result; // This might be VERIFY_SUCCESS as well |
| 187 } | 187 } |
| 188 | 188 |
| 189 } // namespace syncer | 189 } // namespace syncer |
| OLD | NEW |