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

Side by Side Diff: trunk/src/sync/engine/syncer_util.cc

Issue 270543005: Revert 270308 "sync: Improve handling of bad UniquePositions" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 7 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 | « trunk/src/sync/engine/syncer_util.h ('k') | trunk/src/sync/engine/syncer_util_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 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/syncer_util.h" 5 #include "sync/engine/syncer_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/base64.h" 12 #include "base/base64.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/rand_util.h"
16 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
17 #include "sync/engine/conflict_resolver.h" 16 #include "sync/engine/conflict_resolver.h"
18 #include "sync/engine/syncer_proto_util.h" 17 #include "sync/engine/syncer_proto_util.h"
19 #include "sync/engine/syncer_types.h" 18 #include "sync/engine/syncer_types.h"
20 #include "sync/internal_api/public/base/model_type.h" 19 #include "sync/internal_api/public/base/model_type.h"
21 #include "sync/internal_api/public/base/unique_position.h" 20 #include "sync/internal_api/public/base/unique_position.h"
22 #include "sync/protocol/bookmark_specifics.pb.h" 21 #include "sync/protocol/bookmark_specifics.pb.h"
23 #include "sync/protocol/password_specifics.pb.h" 22 #include "sync/protocol/password_specifics.pb.h"
24 #include "sync/protocol/sync.pb.h" 23 #include "sync/protocol/sync.pb.h"
25 #include "sync/syncable/directory.h" 24 #include "sync/syncable/directory.h"
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 } 271 }
273 272
274 UpdateLocalDataFromServerData(trans, entry); 273 UpdateLocalDataFromServerData(trans, entry);
275 274
276 return SUCCESS; 275 return SUCCESS;
277 } 276 }
278 277
279 std::string GetUniqueBookmarkTagFromUpdate(const sync_pb::SyncEntity& update) { 278 std::string GetUniqueBookmarkTagFromUpdate(const sync_pb::SyncEntity& update) {
280 if (!update.has_originator_cache_guid() || 279 if (!update.has_originator_cache_guid() ||
281 !update.has_originator_client_item_id()) { 280 !update.has_originator_client_item_id()) {
282 LOG(ERROR) << "Update is missing requirements for bookmark position." 281 return std::string();
283 << " This is a server bug.";
284 return UniquePosition::RandomSuffix();
285 } 282 }
286 283
287 return syncable::GenerateSyncableBookmarkHash( 284 return syncable::GenerateSyncableBookmarkHash(
288 update.originator_cache_guid(), update.originator_client_item_id()); 285 update.originator_cache_guid(), update.originator_client_item_id());
289 } 286 }
290 287
291 UniquePosition GetUpdatePosition(const sync_pb::SyncEntity& update, 288 UniquePosition GetUpdatePosition(const sync_pb::SyncEntity& update,
292 const std::string& suffix) { 289 const std::string& suffix) {
293 DCHECK(UniquePosition::IsValidSuffix(suffix)); 290 DCHECK(UniquePosition::IsValidSuffix(suffix));
294 if (!(SyncerProtoUtil::ShouldMaintainPosition(update))) { 291 if (!(SyncerProtoUtil::ShouldMaintainPosition(update))) {
295 return UniquePosition::CreateInvalid(); 292 return UniquePosition::CreateInvalid();
296 } else if (update.has_unique_position()) { 293 } else if (update.has_unique_position()) {
297 return UniquePosition::FromProto(update.unique_position()); 294 return UniquePosition::FromProto(update.unique_position());
298 } else if (update.has_position_in_parent()) { 295 } else if (update.has_position_in_parent()) {
299 return UniquePosition::FromInt64(update.position_in_parent(), suffix); 296 return UniquePosition::FromInt64(update.position_in_parent(), suffix);
300 } else { 297 } else {
301 LOG(ERROR) << "No position information in update. This is a server bug."; 298 return UniquePosition::CreateInvalid();
302 return UniquePosition::FromInt64(0, suffix);
303 } 299 }
304 } 300 }
305 301
306 namespace { 302 namespace {
307 303
308 // Helper to synthesize a new-style sync_pb::EntitySpecifics for use locally, 304 // Helper to synthesize a new-style sync_pb::EntitySpecifics for use locally,
309 // when the server speaks only the old sync_pb::SyncEntity_BookmarkData-based 305 // when the server speaks only the old sync_pb::SyncEntity_BookmarkData-based
310 // protocol. 306 // protocol.
311 void UpdateBookmarkSpecifics(const std::string& singleton_tag, 307 void UpdateBookmarkSpecifics(const std::string& singleton_tag,
312 const std::string& url, 308 const std::string& url,
(...skipping 25 matching lines...) Expand all
338 std::string bookmark_tag = GetUniqueBookmarkTagFromUpdate(update); 334 std::string bookmark_tag = GetUniqueBookmarkTagFromUpdate(update);
339 if (UniquePosition::IsValidSuffix(bookmark_tag)) { 335 if (UniquePosition::IsValidSuffix(bookmark_tag)) {
340 local_entry->PutUniqueBookmarkTag(bookmark_tag); 336 local_entry->PutUniqueBookmarkTag(bookmark_tag);
341 } 337 }
342 338
343 // Update our position. 339 // Update our position.
344 UniquePosition update_pos = 340 UniquePosition update_pos =
345 GetUpdatePosition(update, local_entry->GetUniqueBookmarkTag()); 341 GetUpdatePosition(update, local_entry->GetUniqueBookmarkTag());
346 if (update_pos.IsValid()) { 342 if (update_pos.IsValid()) {
347 local_entry->PutServerUniquePosition(update_pos); 343 local_entry->PutServerUniquePosition(update_pos);
344 } else {
345 // TODO(sync): This and other cases of unexpected input should be handled
346 // better.
347 NOTREACHED();
348 } 348 }
349 } 349 }
350 350
351 } // namespace 351 } // namespace
352 352
353 void UpdateServerFieldsFromUpdate( 353 void UpdateServerFieldsFromUpdate(
354 syncable::ModelNeutralMutableEntry* target, 354 syncable::ModelNeutralMutableEntry* target,
355 const sync_pb::SyncEntity& update, 355 const sync_pb::SyncEntity& update,
356 const std::string& name) { 356 const std::string& name) {
357 if (update.deleted()) { 357 if (update.deleted()) {
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 if (update.version() < target->GetServerVersion()) { 641 if (update.version() < target->GetServerVersion()) {
642 LOG(WARNING) << "Update older than current server version for " 642 LOG(WARNING) << "Update older than current server version for "
643 << *target << " Update:" 643 << *target << " Update:"
644 << SyncerProtoUtil::SyncEntityDebugString(update); 644 << SyncerProtoUtil::SyncEntityDebugString(update);
645 return VERIFY_SUCCESS; // Expected in new sync protocol. 645 return VERIFY_SUCCESS; // Expected in new sync protocol.
646 } 646 }
647 return VERIFY_UNDECIDED; 647 return VERIFY_UNDECIDED;
648 } 648 }
649 649
650 } // namespace syncer 650 } // namespace syncer
OLDNEW
« no previous file with comments | « trunk/src/sync/engine/syncer_util.h ('k') | trunk/src/sync/engine/syncer_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698