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" | |
13 #include "chrome/browser/sync/protocol/service_constants.h" | 12 #include "chrome/browser/sync/protocol/service_constants.h" |
14 #include "chrome/browser/sync/protocol/sync.pb.h" | 13 #include "chrome/browser/sync/protocol/sync.pb.h" |
15 #include "chrome/browser/sync/protocol/sync_protocol_error.h" | 14 #include "chrome/browser/sync/protocol/sync_protocol_error.h" |
16 #include "chrome/browser/sync/sessions/sync_session.h" | 15 #include "chrome/browser/sync/sessions/sync_session.h" |
17 #include "chrome/browser/sync/syncable/directory_manager.h" | 16 #include "chrome/browser/sync/syncable/directory_manager.h" |
18 #include "chrome/browser/sync/syncable/model_type.h" | 17 #include "chrome/browser/sync/syncable/model_type.h" |
19 #include "chrome/browser/sync/syncable/syncable-inl.h" | 18 #include "chrome/browser/sync/syncable/syncable-inl.h" |
20 #include "chrome/browser/sync/syncable/syncable.h" | 19 #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 (!ClientAndServerTimeMatch(local_entry.Get(CTIME), server_entry.ctime())) { | 367 if (local_entry.Get(CTIME) != ProtoTimeToTime(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 !ClientAndServerTimeMatch(local_entry.Get(MTIME), | 392 (local_entry.Get(MTIME) != ProtoTimeToTime(server_entry.mtime()))) { |
393 server_entry.mtime())) { | |
394 LOG(WARNING) << "mtime mismatch"; | 393 LOG(WARNING) << "mtime mismatch"; |
395 return false; | 394 return false; |
396 } | 395 } |
397 | 396 |
398 return true; | 397 return true; |
399 } | 398 } |
400 | 399 |
401 // static | 400 // static |
402 void SyncerProtoUtil::CopyProtoBytesIntoBlob(const std::string& proto_bytes, | 401 void SyncerProtoUtil::CopyProtoBytesIntoBlob(const std::string& proto_bytes, |
403 syncable::Blob* blob) { | 402 syncable::Blob* blob) { |
(...skipping 27 matching lines...) Expand all Loading... |
431 // static | 430 // static |
432 const std::string& SyncerProtoUtil::NameFromCommitEntryResponse( | 431 const std::string& SyncerProtoUtil::NameFromCommitEntryResponse( |
433 const CommitResponse_EntryResponse& entry) { | 432 const CommitResponse_EntryResponse& entry) { |
434 if (entry.has_non_unique_name()) | 433 if (entry.has_non_unique_name()) |
435 return entry.non_unique_name(); | 434 return entry.non_unique_name(); |
436 return entry.name(); | 435 return entry.name(); |
437 } | 436 } |
438 | 437 |
439 std::string SyncerProtoUtil::SyncEntityDebugString( | 438 std::string SyncerProtoUtil::SyncEntityDebugString( |
440 const sync_pb::SyncEntity& entry) { | 439 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())); |
441 return base::StringPrintf( | 444 return base::StringPrintf( |
442 "id: %s, parent_id: %s, " | 445 "id: %s, parent_id: %s, " |
443 "version: %"PRId64"d, " | 446 "version: %"PRId64"d, " |
444 "mtime: %" PRId64"d (client: %" PRId64"d), " | 447 "mtime: %" PRId64"d (%s), " |
445 "ctime: %" PRId64"d (client: %" PRId64"d), " | 448 "ctime: %" PRId64"d (%s), " |
446 "name: %s, sync_timestamp: %" PRId64"d, " | 449 "name: %s, sync_timestamp: %" PRId64"d, " |
447 "%s ", | 450 "%s ", |
448 entry.id_string().c_str(), | 451 entry.id_string().c_str(), |
449 entry.parent_id_string().c_str(), | 452 entry.parent_id_string().c_str(), |
450 entry.version(), | 453 entry.version(), |
451 entry.mtime(), ServerTimeToClientTime(entry.mtime()), | 454 entry.mtime(), mtime_str.c_str(), |
452 entry.ctime(), ServerTimeToClientTime(entry.ctime()), | 455 entry.ctime(), ctime_str.c_str(), |
453 entry.name().c_str(), entry.sync_timestamp(), | 456 entry.name().c_str(), entry.sync_timestamp(), |
454 entry.deleted() ? "deleted, ":""); | 457 entry.deleted() ? "deleted, ":""); |
455 } | 458 } |
456 | 459 |
457 namespace { | 460 namespace { |
458 std::string GetUpdatesResponseString( | 461 std::string GetUpdatesResponseString( |
459 const sync_pb::GetUpdatesResponse& response) { | 462 const sync_pb::GetUpdatesResponse& response) { |
460 std::string output; | 463 std::string output; |
461 output.append("GetUpdatesResponse:\n"); | 464 output.append("GetUpdatesResponse:\n"); |
462 for (int i = 0; i < response.entries_size(); i++) { | 465 for (int i = 0; i < response.entries_size(); i++) { |
463 output.append(SyncerProtoUtil::SyncEntityDebugString(response.entries(i))); | 466 output.append(SyncerProtoUtil::SyncEntityDebugString(response.entries(i))); |
464 output.append("\n"); | 467 output.append("\n"); |
465 } | 468 } |
466 return output; | 469 return output; |
467 } | 470 } |
468 } // namespace | 471 } // namespace |
469 | 472 |
470 std::string SyncerProtoUtil::ClientToServerResponseDebugString( | 473 std::string SyncerProtoUtil::ClientToServerResponseDebugString( |
471 const sync_pb::ClientToServerResponse& response) { | 474 const sync_pb::ClientToServerResponse& response) { |
472 // Add more handlers as needed. | 475 // Add more handlers as needed. |
473 std::string output; | 476 std::string output; |
474 if (response.has_get_updates()) | 477 if (response.has_get_updates()) |
475 output.append(GetUpdatesResponseString(response.get_updates())); | 478 output.append(GetUpdatesResponseString(response.get_updates())); |
476 return output; | 479 return output; |
477 } | 480 } |
478 | 481 |
479 } // namespace browser_sync | 482 } // namespace browser_sync |
OLD | NEW |