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/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" |
15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
16 #include "sync/engine/conflict_resolver.h" | 17 #include "sync/engine/conflict_resolver.h" |
17 #include "sync/engine/syncer_proto_util.h" | 18 #include "sync/engine/syncer_proto_util.h" |
18 #include "sync/engine/syncer_types.h" | 19 #include "sync/engine/syncer_types.h" |
19 #include "sync/internal_api/public/base/model_type.h" | 20 #include "sync/internal_api/public/base/model_type.h" |
20 #include "sync/internal_api/public/base/unique_position.h" | 21 #include "sync/internal_api/public/base/unique_position.h" |
21 #include "sync/protocol/bookmark_specifics.pb.h" | 22 #include "sync/protocol/bookmark_specifics.pb.h" |
22 #include "sync/protocol/password_specifics.pb.h" | 23 #include "sync/protocol/password_specifics.pb.h" |
23 #include "sync/protocol/sync.pb.h" | 24 #include "sync/protocol/sync.pb.h" |
24 #include "sync/syncable/directory.h" | 25 #include "sync/syncable/directory.h" |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 } | 272 } |
272 | 273 |
273 UpdateLocalDataFromServerData(trans, entry); | 274 UpdateLocalDataFromServerData(trans, entry); |
274 | 275 |
275 return SUCCESS; | 276 return SUCCESS; |
276 } | 277 } |
277 | 278 |
278 std::string GetUniqueBookmarkTagFromUpdate(const sync_pb::SyncEntity& update) { | 279 std::string GetUniqueBookmarkTagFromUpdate(const sync_pb::SyncEntity& update) { |
279 if (!update.has_originator_cache_guid() || | 280 if (!update.has_originator_cache_guid() || |
280 !update.has_originator_client_item_id()) { | 281 !update.has_originator_client_item_id()) { |
281 return std::string(); | 282 LOG(ERROR) << "Update is missing requirements for bookmark position." |
| 283 << " This is a server bug."; |
| 284 return UniquePosition::RandomSuffix(); |
282 } | 285 } |
283 | 286 |
284 return syncable::GenerateSyncableBookmarkHash( | 287 return syncable::GenerateSyncableBookmarkHash( |
285 update.originator_cache_guid(), update.originator_client_item_id()); | 288 update.originator_cache_guid(), update.originator_client_item_id()); |
286 } | 289 } |
287 | 290 |
288 UniquePosition GetUpdatePosition(const sync_pb::SyncEntity& update, | 291 UniquePosition GetUpdatePosition(const sync_pb::SyncEntity& update, |
289 const std::string& suffix) { | 292 const std::string& suffix) { |
290 DCHECK(UniquePosition::IsValidSuffix(suffix)); | 293 DCHECK(UniquePosition::IsValidSuffix(suffix)); |
291 if (!(SyncerProtoUtil::ShouldMaintainPosition(update))) { | 294 if (!(SyncerProtoUtil::ShouldMaintainPosition(update))) { |
292 return UniquePosition::CreateInvalid(); | 295 return UniquePosition::CreateInvalid(); |
293 } else if (update.has_unique_position()) { | 296 } else if (update.has_unique_position()) { |
294 return UniquePosition::FromProto(update.unique_position()); | 297 return UniquePosition::FromProto(update.unique_position()); |
295 } else if (update.has_position_in_parent()) { | 298 } else if (update.has_position_in_parent()) { |
296 return UniquePosition::FromInt64(update.position_in_parent(), suffix); | 299 return UniquePosition::FromInt64(update.position_in_parent(), suffix); |
297 } else { | 300 } else { |
298 return UniquePosition::CreateInvalid(); | 301 LOG(ERROR) << "No position information in update. This is a server bug."; |
| 302 return UniquePosition::FromInt64(0, suffix); |
299 } | 303 } |
300 } | 304 } |
301 | 305 |
302 namespace { | 306 namespace { |
303 | 307 |
304 // Helper to synthesize a new-style sync_pb::EntitySpecifics for use locally, | 308 // Helper to synthesize a new-style sync_pb::EntitySpecifics for use locally, |
305 // when the server speaks only the old sync_pb::SyncEntity_BookmarkData-based | 309 // when the server speaks only the old sync_pb::SyncEntity_BookmarkData-based |
306 // protocol. | 310 // protocol. |
307 void UpdateBookmarkSpecifics(const std::string& singleton_tag, | 311 void UpdateBookmarkSpecifics(const std::string& singleton_tag, |
308 const std::string& url, | 312 const std::string& url, |
(...skipping 25 matching lines...) Expand all Loading... |
334 std::string bookmark_tag = GetUniqueBookmarkTagFromUpdate(update); | 338 std::string bookmark_tag = GetUniqueBookmarkTagFromUpdate(update); |
335 if (UniquePosition::IsValidSuffix(bookmark_tag)) { | 339 if (UniquePosition::IsValidSuffix(bookmark_tag)) { |
336 local_entry->PutUniqueBookmarkTag(bookmark_tag); | 340 local_entry->PutUniqueBookmarkTag(bookmark_tag); |
337 } | 341 } |
338 | 342 |
339 // Update our position. | 343 // Update our position. |
340 UniquePosition update_pos = | 344 UniquePosition update_pos = |
341 GetUpdatePosition(update, local_entry->GetUniqueBookmarkTag()); | 345 GetUpdatePosition(update, local_entry->GetUniqueBookmarkTag()); |
342 if (update_pos.IsValid()) { | 346 if (update_pos.IsValid()) { |
343 local_entry->PutServerUniquePosition(update_pos); | 347 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 Loading... |
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 |
OLD | NEW |