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

Side by Side Diff: chrome/browser/sync/engine/syncer_util.cc

Issue 7981006: [Sync] use base::Time in sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix win compile error Created 9 years, 3 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
OLDNEW
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_util.h" 5 #include "chrome/browser/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/tracked.h" 12 #include "base/tracked.h"
13 #include "chrome/browser/sync/engine/conflict_resolver.h" 13 #include "chrome/browser/sync/engine/conflict_resolver.h"
14 #include "chrome/browser/sync/engine/nigori_util.h" 14 #include "chrome/browser/sync/engine/nigori_util.h"
15 #include "chrome/browser/sync/engine/syncer_proto_util.h" 15 #include "chrome/browser/sync/engine/syncer_proto_util.h"
16 #include "chrome/browser/sync/engine/syncer_types.h" 16 #include "chrome/browser/sync/engine/syncer_types.h"
17 #include "chrome/browser/sync/engine/syncproto.h" 17 #include "chrome/browser/sync/engine/syncproto.h"
18 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" 18 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h"
19 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" 19 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h"
20 #include "chrome/browser/sync/protocol/password_specifics.pb.h" 20 #include "chrome/browser/sync/protocol/password_specifics.pb.h"
21 #include "chrome/browser/sync/protocol/sync.pb.h" 21 #include "chrome/browser/sync/protocol/sync.pb.h"
22 #include "chrome/browser/sync/syncable/directory_manager.h" 22 #include "chrome/browser/sync/syncable/directory_manager.h"
23 #include "chrome/browser/sync/syncable/model_type.h" 23 #include "chrome/browser/sync/syncable/model_type.h"
24 #include "chrome/browser/sync/syncable/syncable.h" 24 #include "chrome/browser/sync/syncable/syncable.h"
25 #include "chrome/browser/sync/syncable/syncable_changes_version.h" 25 #include "chrome/browser/sync/syncable/syncable_changes_version.h"
26 #include "chrome/browser/sync/util/time.h"
26 27
27 using syncable::BASE_VERSION; 28 using syncable::BASE_VERSION;
28 using syncable::Blob; 29 using syncable::Blob;
29 using syncable::CHANGES_VERSION; 30 using syncable::CHANGES_VERSION;
30 using syncable::CREATE; 31 using syncable::CREATE;
31 using syncable::CREATE_NEW_UPDATE_ITEM; 32 using syncable::CREATE_NEW_UPDATE_ITEM;
32 using syncable::CTIME; 33 using syncable::CTIME;
33 using syncable::Directory; 34 using syncable::Directory;
34 using syncable::Entry; 35 using syncable::Entry;
35 using syncable::GET_BY_HANDLE; 36 using syncable::GET_BY_HANDLE;
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 } 419 }
419 target->Put(IS_UNAPPLIED_UPDATE, true); 420 target->Put(IS_UNAPPLIED_UPDATE, true);
420 return; 421 return;
421 } 422 }
422 423
423 DCHECK(target->Get(ID) == update.id()) 424 DCHECK(target->Get(ID) == update.id())
424 << "ID Changing not supported here"; 425 << "ID Changing not supported here";
425 target->Put(SERVER_PARENT_ID, update.parent_id()); 426 target->Put(SERVER_PARENT_ID, update.parent_id());
426 target->Put(SERVER_NON_UNIQUE_NAME, name); 427 target->Put(SERVER_NON_UNIQUE_NAME, name);
427 target->Put(SERVER_VERSION, update.version()); 428 target->Put(SERVER_VERSION, update.version());
428 target->Put(SERVER_CTIME, 429 target->Put(SERVER_CTIME, browser_sync::ProtoTimeToTime(update.ctime()));
Nicolas Zea 2011/09/21 18:09:12 I believe you can remove the browser_sync namespac
akalin 2011/09/21 19:37:35 Done.
429 ServerTimeToClientTime(update.ctime())); 430 target->Put(SERVER_MTIME, browser_sync::ProtoTimeToTime(update.mtime()));
430 target->Put(SERVER_MTIME,
431 ServerTimeToClientTime(update.mtime()));
432 target->Put(SERVER_IS_DIR, update.IsFolder()); 431 target->Put(SERVER_IS_DIR, update.IsFolder());
433 if (update.has_server_defined_unique_tag()) { 432 if (update.has_server_defined_unique_tag()) {
434 const std::string& tag = update.server_defined_unique_tag(); 433 const std::string& tag = update.server_defined_unique_tag();
435 target->Put(UNIQUE_SERVER_TAG, tag); 434 target->Put(UNIQUE_SERVER_TAG, tag);
436 } 435 }
437 if (update.has_client_defined_unique_tag()) { 436 if (update.has_client_defined_unique_tag()) {
438 const std::string& tag = update.client_defined_unique_tag(); 437 const std::string& tag = update.client_defined_unique_tag();
439 target->Put(UNIQUE_CLIENT_TAG, tag); 438 target->Put(UNIQUE_CLIENT_TAG, tag);
440 } 439 }
441 // Store the datatype-specific part as a protobuf. 440 // Store the datatype-specific part as a protobuf.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 } 487 }
489 488
490 // Now find the closest up-to-date sibling in the server order. 489 // Now find the closest up-to-date sibling in the server order.
491 syncable::Id server_up_to_date_predecessor = 490 syncable::Id server_up_to_date_predecessor =
492 entry->ComputePrevIdFromServerPosition(entry->Get(SERVER_PARENT_ID)); 491 entry->ComputePrevIdFromServerPosition(entry->Get(SERVER_PARENT_ID));
493 return server_up_to_date_predecessor == local_up_to_date_predecessor; 492 return server_up_to_date_predecessor == local_up_to_date_predecessor;
494 } 493 }
495 494
496 // static 495 // static
497 bool SyncerUtil::ServerAndLocalEntriesMatch(syncable::Entry* entry) { 496 bool SyncerUtil::ServerAndLocalEntriesMatch(syncable::Entry* entry) {
498 if (!ClientAndServerTimeMatch( 497 if (entry->Get(CTIME) != entry->Get(SERVER_CTIME)) {
499 entry->Get(CTIME), ClientTimeToServerTime(entry->Get(SERVER_CTIME)))) {
500 LOG(WARNING) << "Client and server time mismatch"; 498 LOG(WARNING) << "Client and server time mismatch";
501 return false; 499 return false;
502 } 500 }
503 if (entry->Get(IS_DEL) && entry->Get(SERVER_IS_DEL)) 501 if (entry->Get(IS_DEL) && entry->Get(SERVER_IS_DEL))
504 return true; 502 return true;
505 // Name should exactly match here. 503 // Name should exactly match here.
506 if (!(entry->Get(NON_UNIQUE_NAME) == entry->Get(SERVER_NON_UNIQUE_NAME))) { 504 if (!(entry->Get(NON_UNIQUE_NAME) == entry->Get(SERVER_NON_UNIQUE_NAME))) {
507 LOG(WARNING) << "Unsanitized name mismatch"; 505 LOG(WARNING) << "Unsanitized name mismatch";
508 return false; 506 return false;
509 } 507 }
(...skipping 13 matching lines...) Expand all
523 // TODO(ncarter): This is unfortunately heavyweight. Can we do better? 521 // TODO(ncarter): This is unfortunately heavyweight. Can we do better?
524 if (entry->Get(SPECIFICS).SerializeAsString() != 522 if (entry->Get(SPECIFICS).SerializeAsString() !=
525 entry->Get(SERVER_SPECIFICS).SerializeAsString()) { 523 entry->Get(SERVER_SPECIFICS).SerializeAsString()) {
526 LOG(WARNING) << "Specifics mismatch"; 524 LOG(WARNING) << "Specifics mismatch";
527 return false; 525 return false;
528 } 526 }
529 if (entry->Get(IS_DIR)) 527 if (entry->Get(IS_DIR))
530 return true; 528 return true;
531 // For historical reasons, a folder's MTIME changes when its contents change. 529 // For historical reasons, a folder's MTIME changes when its contents change.
532 // TODO(ncarter): Remove the special casing of MTIME. 530 // TODO(ncarter): Remove the special casing of MTIME.
533 bool time_match = ClientAndServerTimeMatch(entry->Get(MTIME), 531 if (entry->Get(MTIME) != entry->Get(SERVER_MTIME)) {
534 ClientTimeToServerTime(entry->Get(SERVER_MTIME)));
535 if (!time_match) {
536 LOG(WARNING) << "Time mismatch"; 532 LOG(WARNING) << "Time mismatch";
533 return false;
537 } 534 }
538 return time_match; 535 return true;
539 } 536 }
540 537
541 // static 538 // static
542 void SyncerUtil::SplitServerInformationIntoNewEntry( 539 void SyncerUtil::SplitServerInformationIntoNewEntry(
543 syncable::WriteTransaction* trans, 540 syncable::WriteTransaction* trans,
544 syncable::MutableEntry* entry) { 541 syncable::MutableEntry* entry) {
545 syncable::Id id = entry->Get(ID); 542 syncable::Id id = entry->Get(ID);
546 ChangeEntryIDAndUpdateChildren(trans, entry, trans->directory()->NextId()); 543 ChangeEntryIDAndUpdateChildren(trans, entry, trans->directory()->NextId());
547 entry->Put(BASE_VERSION, 0); 544 entry->Put(BASE_VERSION, 0);
548 545
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 if (update.version() < target->Get(SERVER_VERSION)) { 826 if (update.version() < target->Get(SERVER_VERSION)) {
830 LOG(WARNING) << "Update older than current server version for " 827 LOG(WARNING) << "Update older than current server version for "
831 << *target << " Update:" 828 << *target << " Update:"
832 << SyncerProtoUtil::SyncEntityDebugString(update); 829 << SyncerProtoUtil::SyncEntityDebugString(update);
833 return VERIFY_SUCCESS; // Expected in new sync protocol. 830 return VERIFY_SUCCESS; // Expected in new sync protocol.
834 } 831 }
835 return VERIFY_UNDECIDED; 832 return VERIFY_UNDECIDED;
836 } 833 }
837 834
838 } // namespace browser_sync 835 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698