| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/syncable/syncable.h" | 5 #include "chrome/browser/sync/syncable/syncable.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #if defined(OS_POSIX) | 10 #if defined(OS_POSIX) |
| (...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 CHECK(parent.Get(IS_DIR)) << parent << e; | 856 CHECK(parent.Get(IS_DIR)) << parent << e; |
| 857 CHECK(!parent.Get(IS_DEL)) << parent << e; | 857 CHECK(!parent.Get(IS_DEL)) << parent << e; |
| 858 CHECK(handles.end() != handles.find(parent.Get(META_HANDLE))) | 858 CHECK(handles.end() != handles.find(parent.Get(META_HANDLE))) |
| 859 << e << parent; | 859 << e << parent; |
| 860 parentid = parent.Get(PARENT_ID); | 860 parentid = parent.Get(PARENT_ID); |
| 861 CHECK(--safety_count >= 0) << e << parent; | 861 CHECK(--safety_count >= 0) << e << parent; |
| 862 } | 862 } |
| 863 } | 863 } |
| 864 int64 base_version = e.Get(BASE_VERSION); | 864 int64 base_version = e.Get(BASE_VERSION); |
| 865 int64 server_version = e.Get(SERVER_VERSION); | 865 int64 server_version = e.Get(SERVER_VERSION); |
| 866 bool using_unique_client_tag = !e.Get(UNIQUE_CLIENT_TAG).empty(); |
| 866 if (CHANGES_VERSION == base_version || 0 == base_version) { | 867 if (CHANGES_VERSION == base_version || 0 == base_version) { |
| 867 if (e.Get(IS_UNAPPLIED_UPDATE)) { | 868 if (e.Get(IS_UNAPPLIED_UPDATE)) { |
| 868 // Unapplied new item. | 869 // Must be a new item, or a de-duplicated unique client tag |
| 869 CHECK(e.Get(IS_DEL)) << e; | 870 // that was created both locally and remotely. |
| 871 if (!using_unique_client_tag) { |
| 872 CHECK(e.Get(IS_DEL)) << e; |
| 873 } |
| 874 // It came from the server, so it must have a server ID. |
| 870 CHECK(id.ServerKnows()) << e; | 875 CHECK(id.ServerKnows()) << e; |
| 871 } else { | 876 } else { |
| 872 if (e.Get(IS_DIR)) { | 877 if (e.Get(IS_DIR)) { |
| 873 // TODO(chron): Implement this mode if clients ever need it. | 878 // TODO(chron): Implement this mode if clients ever need it. |
| 874 // For now, you can't combine a client tag and a directory. | 879 // For now, you can't combine a client tag and a directory. |
| 875 CHECK(e.Get(UNIQUE_CLIENT_TAG).empty()) << e; | 880 CHECK(!using_unique_client_tag) << e; |
| 876 } | 881 } |
| 877 // Uncommitted item. | 882 // Should be an uncomitted item, or a successfully deleted one. |
| 878 if (!e.Get(IS_DEL)) { | 883 if (!e.Get(IS_DEL)) { |
| 879 CHECK(e.Get(IS_UNSYNCED)) << e; | 884 CHECK(e.Get(IS_UNSYNCED)) << e; |
| 880 } | 885 } |
| 886 // If the next check failed, it would imply that an item exists |
| 887 // on the server, isn't waiting for application locally, but either |
| 888 // is an unsynced create or a sucessful delete in the local copy. |
| 889 // Either way, that's a mismatch. |
| 881 CHECK(0 == server_version) << e; | 890 CHECK(0 == server_version) << e; |
| 882 CHECK(!id.ServerKnows()) << e; | 891 // Items that aren't using the unique client tag should have a zero |
| 892 // base version only if they have a local ID. Items with unique client |
| 893 // tags are allowed to use the zero base version for undeletion and |
| 894 // de-duplication; the unique client tag trumps the server ID. |
| 895 if (!using_unique_client_tag) { |
| 896 CHECK(!id.ServerKnows()) << e; |
| 897 } |
| 883 } | 898 } |
| 884 } else { | 899 } else { |
| 885 CHECK(id.ServerKnows()); | 900 CHECK(id.ServerKnows()); |
| 886 } | 901 } |
| 887 ++entries_done; | 902 ++entries_done; |
| 888 int64 elapsed_ms = check_timer.Elapsed().InMilliseconds(); | 903 int64 elapsed_ms = check_timer.Elapsed().InMilliseconds(); |
| 889 if (elapsed_ms > max_ms) { | 904 if (elapsed_ms > max_ms) { |
| 890 LOG(INFO) << "Cutting Invariant check short after " << elapsed_ms << "ms." | 905 LOG(INFO) << "Cutting Invariant check short after " << elapsed_ms << "ms." |
| 891 " Processed " << entries_done << "/" << handles.size() << " entries"; | 906 " Processed " << entries_done << "/" << handles.size() << " entries"; |
| 892 return; | 907 return; |
| 893 } | 908 } |
| 894 } | 909 } |
| 895 // I did intend to add a check here to ensure no entries had been pulled into | |
| 896 // memory by this function, but we can't guard against another ReadTransaction | |
| 897 // pulling entries into RAM | |
| 898 } | 910 } |
| 899 | 911 |
| 900 browser_sync::ChannelHookup<DirectoryChangeEvent>* Directory::AddChangeObserver( | 912 browser_sync::ChannelHookup<DirectoryChangeEvent>* Directory::AddChangeObserver( |
| 901 browser_sync::ChannelEventHandler<DirectoryChangeEvent>* observer) { | 913 browser_sync::ChannelEventHandler<DirectoryChangeEvent>* observer) { |
| 902 return kernel_->changes_channel.AddObserver(observer); | 914 return kernel_->changes_channel.AddObserver(observer); |
| 903 } | 915 } |
| 904 | 916 |
| 905 /////////////////////////////////////////////////////////////////////////////// | 917 /////////////////////////////////////////////////////////////////////////////// |
| 906 // ScopedKernelLocks | 918 // ScopedKernelLocks |
| 907 | 919 |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1546 return s << std::dec; | 1558 return s << std::dec; |
| 1547 } | 1559 } |
| 1548 | 1560 |
| 1549 FastDump& operator<<(FastDump& dump, const syncable::Blob& blob) { | 1561 FastDump& operator<<(FastDump& dump, const syncable::Blob& blob) { |
| 1550 if (blob.empty()) | 1562 if (blob.empty()) |
| 1551 return dump; | 1563 return dump; |
| 1552 string buffer(HexEncode(&blob[0], blob.size())); | 1564 string buffer(HexEncode(&blob[0], blob.size())); |
| 1553 dump.out_->sputn(buffer.c_str(), buffer.size()); | 1565 dump.out_->sputn(buffer.c_str(), buffer.size()); |
| 1554 return dump; | 1566 return dump; |
| 1555 } | 1567 } |
| OLD | NEW |