| 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/string_number_conversions.h" | 7 #include "base/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 | 10 |
| 11 namespace syncer { | 11 namespace syncer { |
| 12 namespace syncable { | 12 namespace syncable { |
| 13 | 13 |
| 14 EntryKernel::EntryKernel() : dirty_(false) { | 14 EntryKernel::EntryKernel() : dirty_(false) { |
| 15 // Everything else should already be default-initialized. | 15 // Everything else should already be default-initialized. |
| 16 for (int i = INT64_FIELDS_BEGIN; i < INT64_FIELDS_END; ++i) { | 16 for (int i = INT64_FIELDS_BEGIN; i < INT64_FIELDS_END; ++i) { |
| 17 int64_fields[i] = 0; | 17 int64_fields[i] = 0; |
| 18 } | 18 } |
| 19 } | 19 } |
| 20 | 20 |
| 21 EntryKernel::~EntryKernel() {} | 21 EntryKernel::~EntryKernel() {} |
| 22 | 22 |
| 23 syncer::ModelType EntryKernel::GetServerModelType() const { | 23 ModelType EntryKernel::GetServerModelType() const { |
| 24 ModelType specifics_type = GetModelTypeFromSpecifics(ref(SERVER_SPECIFICS)); | 24 ModelType specifics_type = GetModelTypeFromSpecifics(ref(SERVER_SPECIFICS)); |
| 25 if (specifics_type != UNSPECIFIED) | 25 if (specifics_type != UNSPECIFIED) |
| 26 return specifics_type; | 26 return specifics_type; |
| 27 if (ref(ID).IsRoot()) | 27 if (ref(ID).IsRoot()) |
| 28 return TOP_LEVEL_FOLDER; | 28 return TOP_LEVEL_FOLDER; |
| 29 // Loose check for server-created top-level folders that aren't | 29 // Loose check for server-created top-level folders that aren't |
| 30 // bound to a particular model type. | 30 // bound to a particular model type. |
| 31 if (!ref(UNIQUE_SERVER_TAG).empty() && ref(SERVER_IS_DIR)) | 31 if (!ref(UNIQUE_SERVER_TAG).empty() && ref(SERVER_IS_DIR)) |
| 32 return TOP_LEVEL_FOLDER; | 32 return TOP_LEVEL_FOLDER; |
| 33 | 33 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Helper functions for SetFieldValues(). | 58 // Helper functions for SetFieldValues(). |
| 59 | 59 |
| 60 StringValue* Int64ToValue(int64 i) { | 60 StringValue* Int64ToValue(int64 i) { |
| 61 return Value::CreateStringValue(base::Int64ToString(i)); | 61 return Value::CreateStringValue(base::Int64ToString(i)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 StringValue* TimeToValue(const base::Time& t) { | 64 StringValue* TimeToValue(const base::Time& t) { |
| 65 return Value::CreateStringValue(syncer::GetTimeDebugString(t)); | 65 return Value::CreateStringValue(GetTimeDebugString(t)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 StringValue* IdToValue(const Id& id) { | 68 StringValue* IdToValue(const Id& id) { |
| 69 return id.ToValue(); | 69 return id.ToValue(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 } // namespace | 72 } // namespace |
| 73 | 73 |
| 74 DictionaryValue* EntryKernel::ToValue() const { | 74 DictionaryValue* EntryKernel::ToValue() const { |
| 75 DictionaryValue* kernel_info = new DictionaryValue(); | 75 DictionaryValue* kernel_info = new DictionaryValue(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 // Pick out the function overload we want. | 113 // Pick out the function overload we want. |
| 114 StringValue* (*string_to_value)(const std::string&) = | 114 StringValue* (*string_to_value)(const std::string&) = |
| 115 &Value::CreateStringValue; | 115 &Value::CreateStringValue; |
| 116 SetFieldValues(*this, kernel_info, | 116 SetFieldValues(*this, kernel_info, |
| 117 &GetStringFieldString, string_to_value, | 117 &GetStringFieldString, string_to_value, |
| 118 STRING_FIELDS_BEGIN, STRING_FIELDS_END - 1); | 118 STRING_FIELDS_BEGIN, STRING_FIELDS_END - 1); |
| 119 } | 119 } |
| 120 | 120 |
| 121 // Proto fields. | 121 // Proto fields. |
| 122 SetFieldValues(*this, kernel_info, | 122 SetFieldValues(*this, kernel_info, |
| 123 &GetProtoFieldString, &syncer::EntitySpecificsToValue, | 123 &GetProtoFieldString, &EntitySpecificsToValue, |
| 124 PROTO_FIELDS_BEGIN, PROTO_FIELDS_END - 1); | 124 PROTO_FIELDS_BEGIN, PROTO_FIELDS_END - 1); |
| 125 | 125 |
| 126 // Bit temps. | 126 // Bit temps. |
| 127 SetFieldValues(*this, kernel_info, | 127 SetFieldValues(*this, kernel_info, |
| 128 &GetBitTempString, &Value::CreateBooleanValue, | 128 &GetBitTempString, &Value::CreateBooleanValue, |
| 129 BIT_TEMPS_BEGIN, BIT_TEMPS_END - 1); | 129 BIT_TEMPS_BEGIN, BIT_TEMPS_END - 1); |
| 130 | 130 |
| 131 return kernel_info; | 131 return kernel_info; |
| 132 } | 132 } |
| 133 | 133 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 144 DictionaryValue* EntryKernelMutationToValue( | 144 DictionaryValue* EntryKernelMutationToValue( |
| 145 const EntryKernelMutation& mutation) { | 145 const EntryKernelMutation& mutation) { |
| 146 DictionaryValue* dict = new DictionaryValue(); | 146 DictionaryValue* dict = new DictionaryValue(); |
| 147 dict->Set("original", mutation.original.ToValue()); | 147 dict->Set("original", mutation.original.ToValue()); |
| 148 dict->Set("mutated", mutation.mutated.ToValue()); | 148 dict->Set("mutated", mutation.mutated.ToValue()); |
| 149 return dict; | 149 return dict; |
| 150 } | 150 } |
| 151 | 151 |
| 152 } // namespace syncer | 152 } // namespace syncer |
| 153 } // namespace syncable | 153 } // namespace syncable |
| OLD | NEW |