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_kernel.h" | 5 #include "sync/syncable/entry_kernel.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "sync/protocol/proto_value_conversions.h" | 8 #include "sync/protocol/proto_value_conversions.h" |
9 #include "sync/syncable/syncable_enum_conversions.h" | 9 #include "sync/syncable/syncable_enum_conversions.h" |
10 #include "sync/util/cryptographer.h" | 10 #include "sync/util/cryptographer.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // bound to a particular model type. | 45 // bound to a particular model type. |
46 if (!ref(UNIQUE_SERVER_TAG).empty() && ref(SERVER_IS_DIR)) | 46 if (!ref(UNIQUE_SERVER_TAG).empty() && ref(SERVER_IS_DIR)) |
47 return TOP_LEVEL_FOLDER; | 47 return TOP_LEVEL_FOLDER; |
48 | 48 |
49 return UNSPECIFIED; | 49 return UNSPECIFIED; |
50 } | 50 } |
51 | 51 |
52 bool EntryKernel::ShouldMaintainPosition() const { | 52 bool EntryKernel::ShouldMaintainPosition() const { |
53 // We maintain positions for all bookmarks, except those that are | 53 // We maintain positions for all bookmarks, except those that are |
54 // server-created top-level folders. | 54 // server-created top-level folders. |
55 return (GetModelTypeFromSpecifics(ref(SPECIFICS)) == syncer::BOOKMARKS) | 55 return TypeSupportsOrdering(GetModelTypeFromSpecifics(ref(SPECIFICS))) && |
56 && !(!ref(UNIQUE_SERVER_TAG).empty() && ref(IS_DIR)); | 56 !(!ref(UNIQUE_SERVER_TAG).empty() && ref(IS_DIR)); |
57 } | 57 } |
58 | 58 |
59 bool EntryKernel::ShouldMaintainHierarchy() const { | 59 bool EntryKernel::ShouldMaintainHierarchy() const { |
60 // We maintain hierarchy for bookmarks and top-level folders, | 60 // We maintain hierarchy for bookmarks and top-level folders, |
61 // but no other types. Note that the Nigori node consists of a single | 61 // but no other types. Note that the Nigori node consists of a single |
62 // top-level folder, so it's included in this set. | 62 // top-level folder, so it's included in this set. |
63 return (GetModelTypeFromSpecifics(ref(SPECIFICS)) == syncer::BOOKMARKS) | 63 return TypeSupportsHierarchy(GetModelTypeFromSpecifics(ref(SPECIFICS))) || |
64 || (!ref(UNIQUE_SERVER_TAG).empty()); | 64 (!ref(UNIQUE_SERVER_TAG).empty()); |
65 } | 65 } |
66 | 66 |
67 namespace { | 67 namespace { |
68 | 68 |
69 // Utility function to loop through a set of enum values and add the | 69 // Utility function to loop through a set of enum values and add the |
70 // field keys/values in the kernel to the given dictionary. | 70 // field keys/values in the kernel to the given dictionary. |
71 // | 71 // |
72 // V should be convertible to Value. | 72 // V should be convertible to Value. |
73 template <class T, class U, class V> | 73 template <class T, class U, class V> |
74 void SetFieldValues(const EntryKernel& kernel, | 74 void SetFieldValues(const EntryKernel& kernel, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 const sync_pb::AttachmentMetadata& a) { | 141 const sync_pb::AttachmentMetadata& a) { |
142 return new base::StringValue(a.SerializeAsString()); | 142 return new base::StringValue(a.SerializeAsString()); |
143 } | 143 } |
144 | 144 |
145 } // namespace | 145 } // namespace |
146 | 146 |
147 base::DictionaryValue* EntryKernel::ToValue( | 147 base::DictionaryValue* EntryKernel::ToValue( |
148 Cryptographer* cryptographer) const { | 148 Cryptographer* cryptographer) const { |
149 base::DictionaryValue* kernel_info = new base::DictionaryValue(); | 149 base::DictionaryValue* kernel_info = new base::DictionaryValue(); |
150 kernel_info->SetBoolean("isDirty", is_dirty()); | 150 kernel_info->SetBoolean("isDirty", is_dirty()); |
151 kernel_info->Set("serverModelType", ModelTypeToValue(GetServerModelType())); | 151 ModelType dataType = GetServerModelType(); |
| 152 if (!IsRealDataType(dataType)) |
| 153 dataType = GetModelType(); |
| 154 kernel_info->Set("modelType", ModelTypeToValue(dataType)); |
152 | 155 |
153 // Int64 fields. | 156 // Int64 fields. |
154 SetFieldValues(*this, kernel_info, | 157 SetFieldValues(*this, kernel_info, |
155 &GetMetahandleFieldString, &Int64ToValue, | 158 &GetMetahandleFieldString, &Int64ToValue, |
156 INT64_FIELDS_BEGIN, META_HANDLE); | 159 INT64_FIELDS_BEGIN, META_HANDLE); |
157 SetFieldValues(*this, kernel_info, | 160 SetFieldValues(*this, kernel_info, |
158 &GetBaseVersionString, &Int64ToValue, | 161 &GetBaseVersionString, &Int64ToValue, |
159 META_HANDLE + 1, BASE_VERSION); | 162 META_HANDLE + 1, BASE_VERSION); |
160 SetFieldValues(*this, kernel_info, | 163 SetFieldValues(*this, kernel_info, |
161 &GetInt64FieldString, &Int64ToValue, | 164 &GetInt64FieldString, &Int64ToValue, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 base::DictionaryValue* EntryKernelMutationToValue( | 231 base::DictionaryValue* EntryKernelMutationToValue( |
229 const EntryKernelMutation& mutation) { | 232 const EntryKernelMutation& mutation) { |
230 base::DictionaryValue* dict = new base::DictionaryValue(); | 233 base::DictionaryValue* dict = new base::DictionaryValue(); |
231 dict->Set("original", mutation.original.ToValue(NULL)); | 234 dict->Set("original", mutation.original.ToValue(NULL)); |
232 dict->Set("mutated", mutation.mutated.ToValue(NULL)); | 235 dict->Set("mutated", mutation.mutated.ToValue(NULL)); |
233 return dict; | 236 return dict; |
234 } | 237 } |
235 | 238 |
236 } // namespace syncer | 239 } // namespace syncer |
237 } // namespace syncable | 240 } // namespace syncable |
OLD | NEW |