OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "sync/syncable/entry.h" | 5 #include "sync/syncable/entry.h" |
6 | 6 |
7 #include <iomanip> | 7 #include <iomanip> |
8 | 8 |
9 #include "base/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
10 #include "sync/syncable/base_transaction.h" | 10 #include "sync/syncable/base_transaction.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 Entry::Entry(BaseTransaction* trans, GetByHandle, int64 metahandle) | 35 Entry::Entry(BaseTransaction* trans, GetByHandle, int64 metahandle) |
36 : basetrans_(trans) { | 36 : basetrans_(trans) { |
37 kernel_ = trans->directory()->GetEntryByHandle(metahandle); | 37 kernel_ = trans->directory()->GetEntryByHandle(metahandle); |
38 } | 38 } |
39 | 39 |
40 Directory* Entry::dir() const { | 40 Directory* Entry::dir() const { |
41 return basetrans_->directory(); | 41 return basetrans_->directory(); |
42 } | 42 } |
43 | 43 |
44 Id Entry::ComputePrevIdFromServerPosition(const Id& parent_id) const { | |
45 return dir()->ComputePrevIdFromServerPosition(kernel_, parent_id); | |
46 } | |
47 | |
48 DictionaryValue* Entry::ToValue(Cryptographer* cryptographer) const { | 44 DictionaryValue* Entry::ToValue(Cryptographer* cryptographer) const { |
49 DictionaryValue* entry_info = new DictionaryValue(); | 45 DictionaryValue* entry_info = new DictionaryValue(); |
50 entry_info->SetBoolean("good", good()); | 46 entry_info->SetBoolean("good", good()); |
51 if (good()) { | 47 if (good()) { |
52 entry_info->Set("kernel", kernel_->ToValue(cryptographer)); | 48 entry_info->Set("kernel", kernel_->ToValue(cryptographer)); |
53 entry_info->Set("modelType", | 49 entry_info->Set("modelType", |
54 ModelTypeToValue(GetModelType())); | 50 ModelTypeToValue(GetModelType())); |
55 entry_info->SetBoolean("existsOnClientBecauseNameIsNonEmpty", | 51 entry_info->SetBoolean("existsOnClientBecauseNameIsNonEmpty", |
56 ExistsOnClientBecauseNameIsNonEmpty()); | 52 ExistsOnClientBecauseNameIsNonEmpty()); |
57 entry_info->SetBoolean("isRoot", IsRoot()); | 53 entry_info->SetBoolean("isRoot", IsRoot()); |
58 } | 54 } |
59 return entry_info; | 55 return entry_info; |
60 } | 56 } |
61 | 57 |
62 const string& Entry::Get(StringField field) const { | 58 const string& Entry::Get(StringField field) const { |
63 DCHECK(kernel_); | 59 DCHECK(kernel_); |
64 return kernel_->ref(field); | 60 return kernel_->ref(field); |
65 } | 61 } |
66 | 62 |
| 63 const string& Entry::Get(BytesField field) const { |
| 64 DCHECK(kernel_); |
| 65 return kernel_->ref(field); |
| 66 } |
| 67 |
67 ModelType Entry::GetServerModelType() const { | 68 ModelType Entry::GetServerModelType() const { |
68 ModelType specifics_type = kernel_->GetServerModelType(); | 69 ModelType specifics_type = kernel_->GetServerModelType(); |
69 if (specifics_type != UNSPECIFIED) | 70 if (specifics_type != UNSPECIFIED) |
70 return specifics_type; | 71 return specifics_type; |
71 | 72 |
72 // Otherwise, we don't have a server type yet. That should only happen | 73 // Otherwise, we don't have a server type yet. That should only happen |
73 // if the item is an uncommitted locally created item. | 74 // if the item is an uncommitted locally created item. |
74 // It's possible we'll need to relax these checks in the future; they're | 75 // It's possible we'll need to relax these checks in the future; they're |
75 // just here for now as a safety measure. | 76 // just here for now as a safety measure. |
76 DCHECK(Get(IS_UNSYNCED)); | 77 DCHECK(Get(IS_UNSYNCED)); |
(...skipping 11 matching lines...) Expand all Loading... |
88 if (IsRoot()) | 89 if (IsRoot()) |
89 return TOP_LEVEL_FOLDER; | 90 return TOP_LEVEL_FOLDER; |
90 // Loose check for server-created top-level folders that aren't | 91 // Loose check for server-created top-level folders that aren't |
91 // bound to a particular model type. | 92 // bound to a particular model type. |
92 if (!Get(UNIQUE_SERVER_TAG).empty() && Get(IS_DIR)) | 93 if (!Get(UNIQUE_SERVER_TAG).empty() && Get(IS_DIR)) |
93 return TOP_LEVEL_FOLDER; | 94 return TOP_LEVEL_FOLDER; |
94 | 95 |
95 return UNSPECIFIED; | 96 return UNSPECIFIED; |
96 } | 97 } |
97 | 98 |
| 99 Id Entry::GetPredecessorId() const { |
| 100 return dir()->GetPredecessorId(kernel_); |
| 101 } |
| 102 |
| 103 Id Entry::GetSuccessorId() const { |
| 104 return dir()->GetSuccessorId(kernel_); |
| 105 } |
| 106 |
| 107 Id Entry::GetFirstChildId() const { |
| 108 return dir()->GetFirstChildId(basetrans_, kernel_); |
| 109 } |
| 110 |
98 std::ostream& operator<<(std::ostream& s, const Blob& blob) { | 111 std::ostream& operator<<(std::ostream& s, const Blob& blob) { |
99 for (Blob::const_iterator i = blob.begin(); i != blob.end(); ++i) | 112 for (Blob::const_iterator i = blob.begin(); i != blob.end(); ++i) |
100 s << std::hex << std::setw(2) | 113 s << std::hex << std::setw(2) |
101 << std::setfill('0') << static_cast<unsigned int>(*i); | 114 << std::setfill('0') << static_cast<unsigned int>(*i); |
102 return s << std::dec; | 115 return s << std::dec; |
103 } | 116 } |
104 | 117 |
105 std::ostream& operator<<(std::ostream& os, const Entry& entry) { | 118 std::ostream& operator<<(std::ostream& os, const Entry& entry) { |
106 int i; | 119 int i; |
107 EntryKernel* const kernel = entry.kernel_; | 120 EntryKernel* const kernel = entry.kernel_; |
(...skipping 19 matching lines...) Expand all Loading... |
127 os << g_metas_columns[i].name << ": " << field << ", "; | 140 os << g_metas_columns[i].name << ": " << field << ", "; |
128 } | 141 } |
129 for ( ; i < PROTO_FIELDS_END; ++i) { | 142 for ( ; i < PROTO_FIELDS_END; ++i) { |
130 std::string escaped_str; | 143 std::string escaped_str; |
131 base::JsonDoubleQuote( | 144 base::JsonDoubleQuote( |
132 kernel->ref(static_cast<ProtoField>(i)).SerializeAsString(), | 145 kernel->ref(static_cast<ProtoField>(i)).SerializeAsString(), |
133 false, | 146 false, |
134 &escaped_str); | 147 &escaped_str); |
135 os << g_metas_columns[i].name << ": " << escaped_str << ", "; | 148 os << g_metas_columns[i].name << ": " << escaped_str << ", "; |
136 } | 149 } |
137 for ( ; i < ORDINAL_FIELDS_END; ++i) { | 150 for ( ; i < UNIQUE_POSITION_FIELDS_END; ++i) { |
138 os << g_metas_columns[i].name << ": " | 151 os << g_metas_columns[i].name << ": " |
139 << kernel->ref(static_cast<OrdinalField>(i)).ToDebugString() | 152 << kernel->ref(static_cast<UniquePositionField>(i)).ToDebugString() |
140 << ", "; | 153 << ", "; |
141 } | 154 } |
142 os << "TempFlags: "; | 155 os << "TempFlags: "; |
143 for ( ; i < BIT_TEMPS_END; ++i) { | 156 for ( ; i < BIT_TEMPS_END; ++i) { |
144 if (kernel->ref(static_cast<BitTemp>(i))) | 157 if (kernel->ref(static_cast<BitTemp>(i))) |
145 os << "#" << i - BIT_TEMPS_BEGIN << ", "; | 158 os << "#" << i - BIT_TEMPS_BEGIN << ", "; |
146 } | 159 } |
147 return os; | 160 return os; |
148 } | 161 } |
149 | 162 |
150 } // namespace syncable | 163 } // namespace syncable |
151 } // namespace syncer | 164 } // namespace syncer |
OLD | NEW |