Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: sync/engine/verify_updates_command.cc

Issue 10735041: Remove syncproto.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address most comments Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/engine/verify_updates_command.h ('k') | sync/engine/verify_updates_command_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
15 #include "sync/internal_api/public/engine/model_safe_worker.h" 14 #include "sync/internal_api/public/engine/model_safe_worker.h"
16 #include "sync/protocol/bookmark_specifics.pb.h" 15 #include "sync/protocol/bookmark_specifics.pb.h"
16 #include "sync/protocol/sync.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/syncable_proto_util.h"
19 #include "sync/syncable/write_transaction.h" 20 #include "sync/syncable/write_transaction.h"
20 21
21 namespace syncer { 22 namespace syncer {
22 23
23 using syncable::GET_BY_ID; 24 using syncable::GET_BY_ID;
24 using syncer::ModelTypeSet; 25 using syncer::ModelTypeSet;
25 using syncable::SYNCER; 26 using syncable::SYNCER;
26 using syncable::WriteTransaction; 27 using syncable::WriteTransaction;
27 28
28 namespace { 29 namespace {
(...skipping 13 matching lines...) Expand all
42 // following the next restart, we will receive an update from the server that 43 // following the next restart, we will receive an update from the server that
43 // updates its local ID. 44 // updates its local ID.
44 // - When two attempts to create an item with identical UNIQUE_CLIENT_TAG values 45 // - When two attempts to create an item with identical UNIQUE_CLIENT_TAG values
45 // collide at the server. I have seen this in testing. When it happens, the 46 // collide at the server. I have seen this in testing. When it happens, the
46 // test server will send one of the clients a response to upate its local ID so 47 // test server will send one of the clients a response to upate its local ID so
47 // that both clients will refer to the item using the same ID going forward. In 48 // that both clients will refer to the item using the same ID going forward. In
48 // this case, we're right to assume that the update is not a reflection. 49 // this case, we're right to assume that the update is not a reflection.
49 // 50 //
50 // For more information, see FindLocalIdToUpdate(). 51 // For more information, see FindLocalIdToUpdate().
51 bool UpdateContainsNewVersion(syncable::BaseTransaction *trans, 52 bool UpdateContainsNewVersion(syncable::BaseTransaction *trans,
52 const SyncEntity &update) { 53 const sync_pb::SyncEntity &update) {
53 int64 existing_version = -1; // The server always sends positive versions. 54 int64 existing_version = -1; // The server always sends positive versions.
54 syncable::Entry existing_entry(trans, GET_BY_ID, update.id()); 55 syncable::Entry existing_entry(trans, GET_BY_ID,
56 SyncableIdFromProto(update.id_string()));
55 if (existing_entry.good()) 57 if (existing_entry.good())
56 existing_version = existing_entry.Get(syncable::BASE_VERSION); 58 existing_version = existing_entry.Get(syncable::BASE_VERSION);
57 59
58 return existing_version < update.version(); 60 return existing_version < update.version();
59 } 61 }
60 62
61 // In the event that IDs match, but tags differ AttemptReuniteClient tag 63 // In the event that IDs match, but tags differ AttemptReuniteClient tag
62 // will have refused to unify the update. 64 // will have refused to unify the update.
63 // We should not attempt to apply it at all since it violates consistency 65 // We should not attempt to apply it at all since it violates consistency
64 // rules. 66 // rules.
65 VerifyResult VerifyTagConsistency(const SyncEntity& entry, 67 VerifyResult VerifyTagConsistency(const sync_pb::SyncEntity& entry,
66 const syncable::MutableEntry& same_id) { 68 const syncable::MutableEntry& same_id) {
67 if (entry.has_client_defined_unique_tag() && 69 if (entry.has_client_defined_unique_tag() &&
68 entry.client_defined_unique_tag() != 70 entry.client_defined_unique_tag() !=
69 same_id.Get(syncable::UNIQUE_CLIENT_TAG)) { 71 same_id.Get(syncable::UNIQUE_CLIENT_TAG)) {
70 return VERIFY_FAIL; 72 return VERIFY_FAIL;
71 } 73 }
72 return VERIFY_UNDECIDED; 74 return VERIFY_UNDECIDED;
73 } 75 }
74 } // namespace 76 } // namespace
75 77
76 VerifyUpdatesCommand::VerifyUpdatesCommand() {} 78 VerifyUpdatesCommand::VerifyUpdatesCommand() {}
77 VerifyUpdatesCommand::~VerifyUpdatesCommand() {} 79 VerifyUpdatesCommand::~VerifyUpdatesCommand() {}
78 80
79 std::set<ModelSafeGroup> VerifyUpdatesCommand::GetGroupsToChange( 81 std::set<ModelSafeGroup> VerifyUpdatesCommand::GetGroupsToChange(
80 const sessions::SyncSession& session) const { 82 const sessions::SyncSession& session) const {
81 std::set<ModelSafeGroup> groups_with_updates; 83 std::set<ModelSafeGroup> groups_with_updates;
82 84
83 const GetUpdatesResponse& updates = 85 const sync_pb::GetUpdatesResponse& updates =
84 session.status_controller().updates_response().get_updates(); 86 session.status_controller().updates_response().get_updates();
85 for (int i = 0; i < updates.entries().size(); i++) { 87 for (int i = 0; i < updates.entries().size(); i++) {
86 groups_with_updates.insert( 88 groups_with_updates.insert(
87 GetGroupForModelType(syncer::GetModelType(updates.entries(i)), 89 GetGroupForModelType(syncer::GetModelType(updates.entries(i)),
88 session.routing_info())); 90 session.routing_info()));
89 } 91 }
90 92
91 return groups_with_updates; 93 return groups_with_updates;
92 } 94 }
93 95
94 SyncerError VerifyUpdatesCommand::ModelChangingExecuteImpl( 96 SyncerError VerifyUpdatesCommand::ModelChangingExecuteImpl(
95 sessions::SyncSession* session) { 97 sessions::SyncSession* session) {
96 DVLOG(1) << "Beginning Update Verification"; 98 DVLOG(1) << "Beginning Update Verification";
97 syncable::Directory* dir = session->context()->directory(); 99 syncable::Directory* dir = session->context()->directory();
98 WriteTransaction trans(FROM_HERE, SYNCER, dir); 100 WriteTransaction trans(FROM_HERE, SYNCER, dir);
99 sessions::StatusController* status = session->mutable_status_controller(); 101 sessions::StatusController* status = session->mutable_status_controller();
100 const GetUpdatesResponse& updates = status->updates_response().get_updates(); 102 const sync_pb::GetUpdatesResponse& updates =
103 status->updates_response().get_updates();
101 int update_count = updates.entries().size(); 104 int update_count = updates.entries().size();
102 105
103 ModelTypeSet requested_types = syncer::GetRoutingInfoTypes( 106 ModelTypeSet requested_types = syncer::GetRoutingInfoTypes(
104 session->routing_info()); 107 session->routing_info());
105 108
106 DVLOG(1) << update_count << " entries to verify"; 109 DVLOG(1) << update_count << " entries to verify";
107 for (int i = 0; i < update_count; i++) { 110 for (int i = 0; i < update_count; i++) {
108 const SyncEntity& update = 111 const sync_pb::SyncEntity& update = updates.entries(i);
109 *reinterpret_cast<const SyncEntity *>(&(updates.entries(i))); 112 ModelSafeGroup g = GetGroupForModelType(GetModelType(update),
110 ModelSafeGroup g = GetGroupForModelType(update.GetModelType(),
111 session->routing_info()); 113 session->routing_info());
112 if (g != status->group_restriction()) 114 if (g != status->group_restriction())
113 continue; 115 continue;
114 116
115 VerifyUpdateResult result = VerifyUpdate(&trans, update, 117 VerifyUpdateResult result = VerifyUpdate(&trans, update,
116 requested_types, 118 requested_types,
117 session->routing_info()); 119 session->routing_info());
118 status->mutable_update_progress()->AddVerifyResult(result.value, update); 120 status->mutable_update_progress()->AddVerifyResult(result.value, update);
119 status->increment_num_updates_downloaded_by(1); 121 status->increment_num_updates_downloaded_by(1);
120 if (!UpdateContainsNewVersion(&trans, update)) 122 if (!UpdateContainsNewVersion(&trans, update))
121 status->increment_num_reflected_updates_downloaded_by(1); 123 status->increment_num_reflected_updates_downloaded_by(1);
122 if (update.deleted()) 124 if (update.deleted())
123 status->increment_num_tombstone_updates_downloaded_by(1); 125 status->increment_num_tombstone_updates_downloaded_by(1);
124 } 126 }
125 127
126 return SYNCER_OK; 128 return SYNCER_OK;
127 } 129 }
128 130
129 VerifyUpdatesCommand::VerifyUpdateResult VerifyUpdatesCommand::VerifyUpdate( 131 VerifyUpdatesCommand::VerifyUpdateResult VerifyUpdatesCommand::VerifyUpdate(
130 syncable::WriteTransaction* trans, const SyncEntity& entry, 132 syncable::WriteTransaction* trans, const sync_pb::SyncEntity& entry,
131 const ModelTypeSet& requested_types, 133 const ModelTypeSet& requested_types,
132 const ModelSafeRoutingInfo& routes) { 134 const ModelSafeRoutingInfo& routes) {
133 syncable::Id id = entry.id(); 135 syncable::Id id = SyncableIdFromProto(entry.id_string());
134 VerifyUpdateResult result = {VERIFY_FAIL, GROUP_PASSIVE}; 136 VerifyUpdateResult result = {VERIFY_FAIL, GROUP_PASSIVE};
135 137
136 const bool deleted = entry.has_deleted() && entry.deleted(); 138 const bool deleted = entry.has_deleted() && entry.deleted();
137 const bool is_directory = entry.IsFolder(); 139 const bool is_directory = IsFolder(entry);
138 const syncer::ModelType model_type = entry.GetModelType(); 140 const syncer::ModelType model_type = GetModelType(entry);
139 141
140 if (!id.ServerKnows()) { 142 if (!id.ServerKnows()) {
141 LOG(ERROR) << "Illegal negative id in received updates"; 143 LOG(ERROR) << "Illegal negative id in received updates";
142 return result; 144 return result;
143 } 145 }
144 { 146 {
145 const std::string name = SyncerProtoUtil::NameFromSyncEntity(entry); 147 const std::string name = SyncerProtoUtil::NameFromSyncEntity(entry);
146 if (name.empty() && !deleted) { 148 if (name.empty() && !deleted) {
147 LOG(ERROR) << "Zero length name in non-deleted update"; 149 LOG(ERROR) << "Zero length name in non-deleted update";
148 return result; 150 return result;
149 } 151 }
150 } 152 }
151 153
152 syncable::MutableEntry same_id(trans, GET_BY_ID, id); 154 syncable::MutableEntry same_id(trans, GET_BY_ID, id);
153 result.value = VerifyNewEntry(entry, &same_id, deleted); 155 result.value = VerifyNewEntry(entry, &same_id, deleted);
154 156
155 syncer::ModelType placement_type = !deleted ? entry.GetModelType() 157 syncer::ModelType placement_type = !deleted ? GetModelType(entry)
156 : same_id.good() ? same_id.GetModelType() : syncer::UNSPECIFIED; 158 : same_id.good() ? same_id.GetModelType() : syncer::UNSPECIFIED;
157 result.placement = GetGroupForModelType(placement_type, routes); 159 result.placement = GetGroupForModelType(placement_type, routes);
158 160
159 if (VERIFY_UNDECIDED == result.value) { 161 if (VERIFY_UNDECIDED == result.value) {
160 result.value = VerifyTagConsistency(entry, same_id); 162 result.value = VerifyTagConsistency(entry, same_id);
161 } 163 }
162 164
163 if (VERIFY_UNDECIDED == result.value) { 165 if (VERIFY_UNDECIDED == result.value) {
164 if (deleted) { 166 if (deleted) {
165 // For deletes the server could send tombostones for items that 167 // For deletes the server could send tombostones for items that
(...skipping 14 matching lines...) Expand all
180 deleted, is_directory, model_type); 182 deleted, is_directory, model_type);
181 } 183 }
182 184
183 if (VERIFY_UNDECIDED == result.value) 185 if (VERIFY_UNDECIDED == result.value)
184 result.value = VERIFY_SUCCESS; // No news is good news. 186 result.value = VERIFY_SUCCESS; // No news is good news.
185 187
186 return result; // This might be VERIFY_SUCCESS as well 188 return result; // This might be VERIFY_SUCCESS as well
187 } 189 }
188 190
189 } // namespace syncer 191 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/verify_updates_command.h ('k') | sync/engine/verify_updates_command_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698