OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/engine/syncer_proto_util.h" | 5 #include "chrome/browser/sync/engine/syncer_proto_util.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 9 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
10 #include "chrome/browser/sync/engine/syncer.h" | 10 #include "chrome/browser/sync/engine/syncer.h" |
11 #include "chrome/browser/sync/engine/syncer_types.h" | 11 #include "chrome/browser/sync/engine/syncer_types.h" |
| 12 #include "chrome/browser/sync/engine/syncer_util.h" |
12 #include "chrome/browser/sync/protocol/service_constants.h" | 13 #include "chrome/browser/sync/protocol/service_constants.h" |
13 #include "chrome/browser/sync/protocol/sync.pb.h" | 14 #include "chrome/browser/sync/protocol/sync.pb.h" |
14 #include "chrome/browser/sync/protocol/sync_protocol_error.h" | 15 #include "chrome/browser/sync/protocol/sync_protocol_error.h" |
15 #include "chrome/browser/sync/sessions/sync_session.h" | 16 #include "chrome/browser/sync/sessions/sync_session.h" |
16 #include "chrome/browser/sync/syncable/directory_manager.h" | 17 #include "chrome/browser/sync/syncable/directory_manager.h" |
17 #include "chrome/browser/sync/syncable/model_type.h" | 18 #include "chrome/browser/sync/syncable/model_type.h" |
18 #include "chrome/browser/sync/syncable/syncable-inl.h" | 19 #include "chrome/browser/sync/syncable/syncable-inl.h" |
19 #include "chrome/browser/sync/syncable/syncable.h" | 20 #include "chrome/browser/sync/syncable/syncable.h" |
20 #include "chrome/browser/sync/util/time.h" | |
21 | 21 |
22 using browser_sync::SyncProtocolErrorType; | 22 using browser_sync::SyncProtocolErrorType; |
23 using std::string; | 23 using std::string; |
24 using std::stringstream; | 24 using std::stringstream; |
25 using syncable::BASE_VERSION; | 25 using syncable::BASE_VERSION; |
26 using syncable::CTIME; | 26 using syncable::CTIME; |
27 using syncable::ID; | 27 using syncable::ID; |
28 using syncable::IS_DEL; | 28 using syncable::IS_DEL; |
29 using syncable::IS_DIR; | 29 using syncable::IS_DIR; |
30 using syncable::IS_UNSYNCED; | 30 using syncable::IS_UNSYNCED; |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 | 357 |
358 CHECK(local_entry.Get(ID) == server_entry.id()) << | 358 CHECK(local_entry.Get(ID) == server_entry.id()) << |
359 " SyncerProtoUtil::Compare precondition not met."; | 359 " SyncerProtoUtil::Compare precondition not met."; |
360 CHECK(server_entry.version() == local_entry.Get(BASE_VERSION)) << | 360 CHECK(server_entry.version() == local_entry.Get(BASE_VERSION)) << |
361 " SyncerProtoUtil::Compare precondition not met."; | 361 " SyncerProtoUtil::Compare precondition not met."; |
362 CHECK(!local_entry.Get(IS_UNSYNCED)) << | 362 CHECK(!local_entry.Get(IS_UNSYNCED)) << |
363 " SyncerProtoUtil::Compare precondition not met."; | 363 " SyncerProtoUtil::Compare precondition not met."; |
364 | 364 |
365 if (local_entry.Get(IS_DEL) && server_entry.deleted()) | 365 if (local_entry.Get(IS_DEL) && server_entry.deleted()) |
366 return true; | 366 return true; |
367 if (local_entry.Get(CTIME) != ProtoTimeToTime(server_entry.ctime())) { | 367 if (!ClientAndServerTimeMatch(local_entry.Get(CTIME), server_entry.ctime())) { |
368 LOG(WARNING) << "ctime mismatch"; | 368 LOG(WARNING) << "ctime mismatch"; |
369 return false; | 369 return false; |
370 } | 370 } |
371 | 371 |
372 // These checks are somewhat prolix, but they're easier to debug than a big | 372 // These checks are somewhat prolix, but they're easier to debug than a big |
373 // boolean statement. | 373 // boolean statement. |
374 string client_name = local_entry.Get(syncable::NON_UNIQUE_NAME); | 374 string client_name = local_entry.Get(syncable::NON_UNIQUE_NAME); |
375 if (client_name != name) { | 375 if (client_name != name) { |
376 LOG(WARNING) << "Client name mismatch"; | 376 LOG(WARNING) << "Client name mismatch"; |
377 return false; | 377 return false; |
378 } | 378 } |
379 if (local_entry.Get(PARENT_ID) != server_entry.parent_id()) { | 379 if (local_entry.Get(PARENT_ID) != server_entry.parent_id()) { |
380 LOG(WARNING) << "Parent ID mismatch"; | 380 LOG(WARNING) << "Parent ID mismatch"; |
381 return false; | 381 return false; |
382 } | 382 } |
383 if (local_entry.Get(IS_DIR) != server_entry.IsFolder()) { | 383 if (local_entry.Get(IS_DIR) != server_entry.IsFolder()) { |
384 LOG(WARNING) << "Dir field mismatch"; | 384 LOG(WARNING) << "Dir field mismatch"; |
385 return false; | 385 return false; |
386 } | 386 } |
387 if (local_entry.Get(IS_DEL) != server_entry.deleted()) { | 387 if (local_entry.Get(IS_DEL) != server_entry.deleted()) { |
388 LOG(WARNING) << "Deletion mismatch"; | 388 LOG(WARNING) << "Deletion mismatch"; |
389 return false; | 389 return false; |
390 } | 390 } |
391 if (!local_entry.Get(IS_DIR) && | 391 if (!local_entry.Get(IS_DIR) && |
392 (local_entry.Get(MTIME) != ProtoTimeToTime(server_entry.mtime()))) { | 392 !ClientAndServerTimeMatch(local_entry.Get(MTIME), |
| 393 server_entry.mtime())) { |
393 LOG(WARNING) << "mtime mismatch"; | 394 LOG(WARNING) << "mtime mismatch"; |
394 return false; | 395 return false; |
395 } | 396 } |
396 | 397 |
397 return true; | 398 return true; |
398 } | 399 } |
399 | 400 |
400 // static | 401 // static |
401 void SyncerProtoUtil::CopyProtoBytesIntoBlob(const std::string& proto_bytes, | 402 void SyncerProtoUtil::CopyProtoBytesIntoBlob(const std::string& proto_bytes, |
402 syncable::Blob* blob) { | 403 syncable::Blob* blob) { |
(...skipping 27 matching lines...) Expand all Loading... |
430 // static | 431 // static |
431 const std::string& SyncerProtoUtil::NameFromCommitEntryResponse( | 432 const std::string& SyncerProtoUtil::NameFromCommitEntryResponse( |
432 const CommitResponse_EntryResponse& entry) { | 433 const CommitResponse_EntryResponse& entry) { |
433 if (entry.has_non_unique_name()) | 434 if (entry.has_non_unique_name()) |
434 return entry.non_unique_name(); | 435 return entry.non_unique_name(); |
435 return entry.name(); | 436 return entry.name(); |
436 } | 437 } |
437 | 438 |
438 std::string SyncerProtoUtil::SyncEntityDebugString( | 439 std::string SyncerProtoUtil::SyncEntityDebugString( |
439 const sync_pb::SyncEntity& entry) { | 440 const sync_pb::SyncEntity& entry) { |
440 const std::string& mtime_str = | |
441 GetTimeDebugString(ProtoTimeToTime(entry.mtime())); | |
442 const std::string& ctime_str = | |
443 GetTimeDebugString(ProtoTimeToTime(entry.ctime())); | |
444 return base::StringPrintf( | 441 return base::StringPrintf( |
445 "id: %s, parent_id: %s, " | 442 "id: %s, parent_id: %s, " |
446 "version: %"PRId64"d, " | 443 "version: %"PRId64"d, " |
447 "mtime: %" PRId64"d (%s), " | 444 "mtime: %" PRId64"d (client: %" PRId64"d), " |
448 "ctime: %" PRId64"d (%s), " | 445 "ctime: %" PRId64"d (client: %" PRId64"d), " |
449 "name: %s, sync_timestamp: %" PRId64"d, " | 446 "name: %s, sync_timestamp: %" PRId64"d, " |
450 "%s ", | 447 "%s ", |
451 entry.id_string().c_str(), | 448 entry.id_string().c_str(), |
452 entry.parent_id_string().c_str(), | 449 entry.parent_id_string().c_str(), |
453 entry.version(), | 450 entry.version(), |
454 entry.mtime(), mtime_str.c_str(), | 451 entry.mtime(), ServerTimeToClientTime(entry.mtime()), |
455 entry.ctime(), ctime_str.c_str(), | 452 entry.ctime(), ServerTimeToClientTime(entry.ctime()), |
456 entry.name().c_str(), entry.sync_timestamp(), | 453 entry.name().c_str(), entry.sync_timestamp(), |
457 entry.deleted() ? "deleted, ":""); | 454 entry.deleted() ? "deleted, ":""); |
458 } | 455 } |
459 | 456 |
460 namespace { | 457 namespace { |
461 std::string GetUpdatesResponseString( | 458 std::string GetUpdatesResponseString( |
462 const sync_pb::GetUpdatesResponse& response) { | 459 const sync_pb::GetUpdatesResponse& response) { |
463 std::string output; | 460 std::string output; |
464 output.append("GetUpdatesResponse:\n"); | 461 output.append("GetUpdatesResponse:\n"); |
465 for (int i = 0; i < response.entries_size(); i++) { | 462 for (int i = 0; i < response.entries_size(); i++) { |
466 output.append(SyncerProtoUtil::SyncEntityDebugString(response.entries(i))); | 463 output.append(SyncerProtoUtil::SyncEntityDebugString(response.entries(i))); |
467 output.append("\n"); | 464 output.append("\n"); |
468 } | 465 } |
469 return output; | 466 return output; |
470 } | 467 } |
471 } // namespace | 468 } // namespace |
472 | 469 |
473 std::string SyncerProtoUtil::ClientToServerResponseDebugString( | 470 std::string SyncerProtoUtil::ClientToServerResponseDebugString( |
474 const sync_pb::ClientToServerResponse& response) { | 471 const sync_pb::ClientToServerResponse& response) { |
475 // Add more handlers as needed. | 472 // Add more handlers as needed. |
476 std::string output; | 473 std::string output; |
477 if (response.has_get_updates()) | 474 if (response.has_get_updates()) |
478 output.append(GetUpdatesResponseString(response.get_updates())); | 475 output.append(GetUpdatesResponseString(response.get_updates())); |
479 return output; | 476 return output; |
480 } | 477 } |
481 | 478 |
482 } // namespace browser_sync | 479 } // namespace browser_sync |
OLD | NEW |