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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" | 44 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" |
45 #include "chrome/browser/sync/protocol/service_constants.h" | 45 #include "chrome/browser/sync/protocol/service_constants.h" |
46 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" | 46 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" |
47 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" | 47 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" |
48 #include "chrome/browser/sync/syncable/directory_backing_store.h" | 48 #include "chrome/browser/sync/syncable/directory_backing_store.h" |
49 #include "chrome/browser/sync/syncable/directory_manager.h" | 49 #include "chrome/browser/sync/syncable/directory_manager.h" |
50 #include "chrome/browser/sync/syncable/syncable-inl.h" | 50 #include "chrome/browser/sync/syncable/syncable-inl.h" |
51 #include "chrome/browser/sync/syncable/syncable_changes_version.h" | 51 #include "chrome/browser/sync/syncable/syncable_changes_version.h" |
52 #include "chrome/browser/sync/syncable/syncable_columns.h" | 52 #include "chrome/browser/sync/syncable/syncable_columns.h" |
53 #include "chrome/browser/sync/util/crypto_helpers.h" | 53 #include "chrome/browser/sync/util/crypto_helpers.h" |
54 #include "chrome/browser/sync/util/fast_dump.h" | |
55 #include "chrome/common/deprecated/event_sys-inl.h" | 54 #include "chrome/common/deprecated/event_sys-inl.h" |
56 #include "net/base/escape.h" | 55 #include "net/base/escape.h" |
57 | 56 |
58 namespace { | 57 namespace { |
59 enum InvariantCheckLevel { | 58 enum InvariantCheckLevel { |
60 OFF = 0, | 59 OFF = 0, |
61 VERIFY_IN_MEMORY = 1, | 60 VERIFY_IN_MEMORY = 1, |
62 FULL_DB_VERIFICATION = 2 | 61 FULL_DB_VERIFICATION = 2 |
63 }; | 62 }; |
64 | 63 |
65 static const InvariantCheckLevel kInvariantCheckLevel = VERIFY_IN_MEMORY; | 64 static const InvariantCheckLevel kInvariantCheckLevel = VERIFY_IN_MEMORY; |
66 | 65 |
67 // Max number of milliseconds to spend checking syncable entry invariants | 66 // Max number of milliseconds to spend checking syncable entry invariants |
68 static const int kInvariantCheckMaxMs = 50; | 67 static const int kInvariantCheckMaxMs = 50; |
69 } // namespace | 68 } // namespace |
70 | 69 |
71 using browser_sync::FastDump; | |
72 using browser_sync::SyncerUtil; | 70 using browser_sync::SyncerUtil; |
73 using std::string; | 71 using std::string; |
74 | 72 |
75 | 73 |
76 namespace syncable { | 74 namespace syncable { |
77 | 75 |
78 int64 Now() { | 76 int64 Now() { |
79 #if defined(OS_WIN) | 77 #if defined(OS_WIN) |
80 FILETIME filetime; | 78 FILETIME filetime; |
81 SYSTEMTIME systime; | 79 SYSTEMTIME systime; |
(...skipping 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1667 } | 1665 } |
1668 | 1666 |
1669 // This function sets only the flags needed to get this entry to sync. | 1667 // This function sets only the flags needed to get this entry to sync. |
1670 void MarkForSyncing(syncable::MutableEntry* e) { | 1668 void MarkForSyncing(syncable::MutableEntry* e) { |
1671 DCHECK_NE(static_cast<MutableEntry*>(NULL), e); | 1669 DCHECK_NE(static_cast<MutableEntry*>(NULL), e); |
1672 DCHECK(!e->IsRoot()) << "We shouldn't mark a permanent object for syncing."; | 1670 DCHECK(!e->IsRoot()) << "We shouldn't mark a permanent object for syncing."; |
1673 e->Put(IS_UNSYNCED, true); | 1671 e->Put(IS_UNSYNCED, true); |
1674 e->Put(SYNCING, false); | 1672 e->Put(SYNCING, false); |
1675 } | 1673 } |
1676 | 1674 |
1677 } // namespace syncable | 1675 std::ostream& operator<<(std::ostream& os, const Entry& entry) { |
1678 | |
1679 namespace { | |
1680 class DumpSeparator { | |
1681 } separator; | |
1682 class DumpColon { | |
1683 } colon; | |
1684 | |
1685 inline FastDump& operator<<(FastDump& dump, const DumpSeparator&) { | |
1686 dump.out_->sputn(", ", 2); | |
1687 return dump; | |
1688 } | |
1689 | |
1690 inline FastDump& operator<<(FastDump& dump, const DumpColon&) { | |
1691 dump.out_->sputn(": ", 2); | |
1692 return dump; | |
1693 } | |
1694 } // namespace | |
1695 | |
1696 namespace syncable { | |
1697 | |
1698 std::ostream& operator<<(std::ostream& stream, const Entry& entry) { | |
1699 // Using ostreams directly here is dreadfully slow, because a mutex is | |
1700 // acquired for every <<. Users noticed it spiking CPU. | |
1701 | |
1702 int i; | 1676 int i; |
1703 FastDump s(&stream); | |
1704 EntryKernel* const kernel = entry.kernel_; | 1677 EntryKernel* const kernel = entry.kernel_; |
1705 for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) { | 1678 for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) { |
1706 s << g_metas_columns[i].name << colon | 1679 os << g_metas_columns[i].name << ": " |
1707 << kernel->ref(static_cast<Int64Field>(i)) << separator; | 1680 << kernel->ref(static_cast<Int64Field>(i)) << ", "; |
1708 } | 1681 } |
1709 for ( ; i < ID_FIELDS_END; ++i) { | 1682 for ( ; i < ID_FIELDS_END; ++i) { |
1710 s << g_metas_columns[i].name << colon | 1683 os << g_metas_columns[i].name << ": " |
1711 << kernel->ref(static_cast<IdField>(i)) << separator; | 1684 << kernel->ref(static_cast<IdField>(i)) << ", "; |
1712 } | 1685 } |
1713 s << "Flags: "; | 1686 os << "Flags: "; |
1714 for ( ; i < BIT_FIELDS_END; ++i) { | 1687 for ( ; i < BIT_FIELDS_END; ++i) { |
1715 if (kernel->ref(static_cast<BitField>(i))) | 1688 if (kernel->ref(static_cast<BitField>(i))) |
1716 s << g_metas_columns[i].name << separator; | 1689 os << g_metas_columns[i].name << ", "; |
1717 } | 1690 } |
1718 for ( ; i < STRING_FIELDS_END; ++i) { | 1691 for ( ; i < STRING_FIELDS_END; ++i) { |
1719 const string& field = kernel->ref(static_cast<StringField>(i)); | 1692 const string& field = kernel->ref(static_cast<StringField>(i)); |
1720 s << g_metas_columns[i].name << colon << field << separator; | 1693 os << g_metas_columns[i].name << ": " << field << ", "; |
1721 } | 1694 } |
1722 for ( ; i < PROTO_FIELDS_END; ++i) { | 1695 for ( ; i < PROTO_FIELDS_END; ++i) { |
1723 s << g_metas_columns[i].name << colon | 1696 os << g_metas_columns[i].name << ": " |
1724 << EscapePath( | 1697 << EscapePath( |
1725 kernel->ref(static_cast<ProtoField>(i)).SerializeAsString()) | 1698 kernel->ref(static_cast<ProtoField>(i)).SerializeAsString()) |
1726 << separator; | 1699 << ", "; |
1727 } | 1700 } |
1728 s << "TempFlags: "; | 1701 os << "TempFlags: "; |
1729 for ( ; i < BIT_TEMPS_END; ++i) { | 1702 for ( ; i < BIT_TEMPS_END; ++i) { |
1730 if (kernel->ref(static_cast<BitTemp>(i))) | 1703 if (kernel->ref(static_cast<BitTemp>(i))) |
1731 s << "#" << i - BIT_TEMPS_BEGIN << separator; | 1704 os << "#" << i - BIT_TEMPS_BEGIN << ", "; |
1732 } | 1705 } |
1733 return stream; | 1706 return os; |
1734 } | 1707 } |
1735 | 1708 |
1736 std::ostream& operator<<(std::ostream& s, const Blob& blob) { | 1709 std::ostream& operator<<(std::ostream& s, const Blob& blob) { |
1737 for (Blob::const_iterator i = blob.begin(); i != blob.end(); ++i) | 1710 for (Blob::const_iterator i = blob.begin(); i != blob.end(); ++i) |
1738 s << std::hex << std::setw(2) | 1711 s << std::hex << std::setw(2) |
1739 << std::setfill('0') << static_cast<unsigned int>(*i); | 1712 << std::setfill('0') << static_cast<unsigned int>(*i); |
1740 return s << std::dec; | 1713 return s << std::dec; |
1741 } | 1714 } |
1742 | 1715 |
1743 FastDump& operator<<(FastDump& dump, const Blob& blob) { | |
1744 if (blob.empty()) | |
1745 return dump; | |
1746 string buffer(base::HexEncode(&blob[0], blob.size())); | |
1747 dump.out_->sputn(buffer.c_str(), buffer.size()); | |
1748 return dump; | |
1749 } | |
1750 | |
1751 } // namespace syncable | 1716 } // namespace syncable |
OLD | NEW |