Skip to content

Commit

Permalink
Add more info for invalid position check.
Browse files Browse the repository at this point in the history
BUG=332371

Review URL: https://codereview.chromium.org/1258863007

Cr-Commit-Position: refs/heads/master@{#342437}
  • Loading branch information
gangwu authored and Commit bot committed Aug 7, 2015
1 parent 46a37de commit 81f8552
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 58 deletions.
2 changes: 1 addition & 1 deletion sync/syncable/directory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ void Directory::PutPredecessor(EntryKernel* e, EntryKernel* predecessor) {
// without valid positions. See TODO above.
// Using a release CHECK here because the following UniquePosition::Between
// call crashes anyway when the position string is empty (see crbug/332371).
CHECK(successor->ref(UNIQUE_POSITION).IsValid());
CHECK(successor->ref(UNIQUE_POSITION).IsValid()) << *successor;

// Finally, the normal case: inserting between two elements.
UniquePosition pos = UniquePosition::Between(
Expand Down
56 changes: 3 additions & 53 deletions sync/syncable/entry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@

#include <iomanip>

#include "base/json/string_escape.h"
#include "base/strings/string_util.h"
#include "sync/syncable/directory.h"
#include "sync/syncable/syncable_base_transaction.h"
#include "sync/syncable/syncable_columns.h"

using std::string;

namespace syncer {
namespace syncable {
Expand All @@ -22,7 +17,7 @@ Entry::Entry(BaseTransaction* trans, GetById, const Id& id)
kernel_ = trans->directory()->GetEntryById(id);
}

Entry::Entry(BaseTransaction* trans, GetByClientTag, const string& tag)
Entry::Entry(BaseTransaction* trans, GetByClientTag, const std::string& tag)
: basetrans_(trans) {
kernel_ = trans->directory()->GetEntryByClientTag(tag);
}
Expand All @@ -38,7 +33,7 @@ Entry::Entry(BaseTransaction* trans, GetByHandle, int64 metahandle)
kernel_ = trans->directory()->GetEntryByHandle(metahandle);
}

Entry::Entry(BaseTransaction* trans, GetByServerTag, const string& tag)
Entry::Entry(BaseTransaction* trans, GetByServerTag, const std::string& tag)
: basetrans_(trans) {
kernel_ = trans->directory()->GetEntryByServerTag(tag);
}
Expand Down Expand Up @@ -135,52 +130,7 @@ bool Entry::ShouldMaintainHierarchy() const {
}

std::ostream& operator<<(std::ostream& os, const Entry& entry) {
int i;
EntryKernel* const kernel = entry.kernel_;
for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) {
os << g_metas_columns[i].name << ": "
<< kernel->ref(static_cast<Int64Field>(i)) << ", ";
}
for ( ; i < TIME_FIELDS_END; ++i) {
os << g_metas_columns[i].name << ": "
<< GetTimeDebugString(kernel->ref(static_cast<TimeField>(i))) << ", ";
}
for ( ; i < ID_FIELDS_END; ++i) {
os << g_metas_columns[i].name << ": "
<< kernel->ref(static_cast<IdField>(i)) << ", ";
}
os << "Flags: ";
for ( ; i < BIT_FIELDS_END; ++i) {
if (kernel->ref(static_cast<BitField>(i)))
os << g_metas_columns[i].name << ", ";
}
for ( ; i < STRING_FIELDS_END; ++i) {
const std::string& field = kernel->ref(static_cast<StringField>(i));
os << g_metas_columns[i].name << ": " << field << ", ";
}
for ( ; i < PROTO_FIELDS_END; ++i) {
std::string escaped_str = base::EscapeBytesAsInvalidJSONString(
kernel->ref(static_cast<ProtoField>(i)).SerializeAsString(),
false);
os << g_metas_columns[i].name << ": " << escaped_str << ", ";
}
for ( ; i < UNIQUE_POSITION_FIELDS_END; ++i) {
os << g_metas_columns[i].name << ": "
<< kernel->ref(static_cast<UniquePositionField>(i)).ToDebugString()
<< ", ";
}
for ( ; i < ATTACHMENT_METADATA_FIELDS_END; ++i) {
std::string escaped_str = base::EscapeBytesAsInvalidJSONString(
kernel->ref(static_cast<AttachmentMetadataField>(i))
.SerializeAsString(),
false);
os << g_metas_columns[i].name << ": " << escaped_str << ", ";
}
os << "TempFlags: ";
for ( ; i < BIT_TEMPS_END; ++i) {
if (kernel->ref(static_cast<BitTemp>(i)))
os << "#" << i - BIT_TEMPS_BEGIN << ", ";
}
os << *(entry.kernel_);
return os;
}

Expand Down
51 changes: 51 additions & 0 deletions sync/syncable/entry_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

#include "sync/syncable/entry_kernel.h"

#include "base/json/string_escape.h"
#include "base/strings/string_number_conversions.h"
#include "sync/protocol/proto_value_conversions.h"
#include "sync/syncable/syncable_columns.h"
#include "sync/syncable/syncable_enum_conversions.h"
#include "sync/util/cryptographer.h"

Expand Down Expand Up @@ -236,5 +238,54 @@ base::DictionaryValue* EntryKernelMutationToValue(
return dict;
}

std::ostream& operator<<(std::ostream& os, const EntryKernel& entry_kernel) {
int i;
EntryKernel* const kernel = const_cast<EntryKernel*>(&entry_kernel);
for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) {
os << g_metas_columns[i].name << ": "
<< kernel->ref(static_cast<Int64Field>(i)) << ", ";
}
for (; i < TIME_FIELDS_END; ++i) {
os << g_metas_columns[i].name << ": "
<< GetTimeDebugString(kernel->ref(static_cast<TimeField>(i))) << ", ";
}
for (; i < ID_FIELDS_END; ++i) {
os << g_metas_columns[i].name << ": "
<< kernel->ref(static_cast<IdField>(i)) << ", ";
}
os << "Flags: ";
for (; i < BIT_FIELDS_END; ++i) {
if (kernel->ref(static_cast<BitField>(i)))
os << g_metas_columns[i].name << ", ";
}
for (; i < STRING_FIELDS_END; ++i) {
const std::string& field = kernel->ref(static_cast<StringField>(i));
os << g_metas_columns[i].name << ": " << field << ", ";
}
for (; i < PROTO_FIELDS_END; ++i) {
std::string escaped_str = base::EscapeBytesAsInvalidJSONString(
kernel->ref(static_cast<ProtoField>(i)).SerializeAsString(), false);
os << g_metas_columns[i].name << ": " << escaped_str << ", ";
}
for (; i < UNIQUE_POSITION_FIELDS_END; ++i) {
os << g_metas_columns[i].name << ": "
<< kernel->ref(static_cast<UniquePositionField>(i)).ToDebugString()
<< ", ";
}
for (; i < ATTACHMENT_METADATA_FIELDS_END; ++i) {
std::string escaped_str = base::EscapeBytesAsInvalidJSONString(
kernel->ref(static_cast<AttachmentMetadataField>(i))
.SerializeAsString(),
false);
os << g_metas_columns[i].name << ": " << escaped_str << ", ";
}
os << "TempFlags: ";
for (; i < BIT_TEMPS_END; ++i) {
if (kernel->ref(static_cast<BitTemp>(i)))
os << "#" << i - BIT_TEMPS_BEGIN << ", ";
}
return os;
}

} // namespace syncer
} // namespace syncable
10 changes: 6 additions & 4 deletions sync/syncable/entry_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ enum StringField {
// A tag string which identifies this node as a particular top-level
// permanent object. The tag can be thought of as a unique key that
// identifies a singleton instance.
UNIQUE_SERVER_TAG, // Tagged by the server
UNIQUE_CLIENT_TAG, // Tagged by the client
UNIQUE_SERVER_TAG, // Tagged by the server
UNIQUE_CLIENT_TAG, // Tagged by the client
UNIQUE_BOOKMARK_TAG, // Client tags for bookmark items
STRING_FIELDS_END,
};
Expand Down Expand Up @@ -191,8 +191,6 @@ enum {
BIT_TEMPS_COUNT = BIT_TEMPS_END - BIT_TEMPS_BEGIN
};



struct SYNC_EXPORT_PRIVATE EntryKernel {
private:
std::string string_fields[STRING_FIELDS_COUNT];
Expand All @@ -206,6 +204,8 @@ struct SYNC_EXPORT_PRIVATE EntryKernel {
std::bitset<BIT_FIELDS_COUNT> bit_fields;
std::bitset<BIT_TEMPS_COUNT> bit_temps;

friend std::ostream& operator<<(std::ostream& s, const EntryKernel& e);

public:
EntryKernel();
~EntryKernel();
Expand Down Expand Up @@ -405,6 +405,8 @@ base::DictionaryValue* EntryKernelMutationToValue(
base::ListValue* EntryKernelMutationMapToValue(
const EntryKernelMutationMap& mutations);

std::ostream& operator<<(std::ostream& os, const EntryKernel& entry_kernel);

} // namespace syncable
} // namespace syncer

Expand Down

0 comments on commit 81f8552

Please sign in to comment.