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 // Enumerate the various item subtypes that are supported by sync. | 5 // Enumerate the various item subtypes that are supported by sync. |
6 // Each sync object is expected to have an immutable object type. | 6 // Each sync object is expected to have an immutable object type. |
7 // An object's type is inferred from the type of data it holds. | 7 // An object's type is inferred from the type of data it holds. |
8 | 8 |
9 #ifndef SYNC_INTERNAL_API_PUBLIC_BASE_MODEL_TYPE_H_ | 9 #ifndef SYNC_INTERNAL_API_PUBLIC_BASE_MODEL_TYPE_H_ |
10 #define SYNC_INTERNAL_API_PUBLIC_BASE_MODEL_TYPE_H_ | 10 #define SYNC_INTERNAL_API_PUBLIC_BASE_MODEL_TYPE_H_ |
11 | 11 |
12 #include <set> | 12 #include <set> |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "sync/base/sync_export.h" | |
17 #include "sync/internal_api/public/base/enum_set.h" | 18 #include "sync/internal_api/public/base/enum_set.h" |
18 | 19 |
19 namespace base { | 20 namespace base { |
20 class ListValue; | 21 class ListValue; |
21 class StringValue; | 22 class StringValue; |
22 class Value; | 23 class Value; |
23 } | 24 } |
24 | 25 |
25 namespace sync_pb { | 26 namespace sync_pb { |
26 class EntitySpecifics; | 27 class EntitySpecifics; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 ModelType, FIRST_REAL_MODEL_TYPE, LAST_REAL_MODEL_TYPE> ModelTypeSet; | 94 ModelType, FIRST_REAL_MODEL_TYPE, LAST_REAL_MODEL_TYPE> ModelTypeSet; |
94 typedef syncer::EnumSet< | 95 typedef syncer::EnumSet< |
95 ModelType, UNSPECIFIED, LAST_REAL_MODEL_TYPE> FullModelTypeSet; | 96 ModelType, UNSPECIFIED, LAST_REAL_MODEL_TYPE> FullModelTypeSet; |
96 | 97 |
97 inline ModelType ModelTypeFromInt(int i) { | 98 inline ModelType ModelTypeFromInt(int i) { |
98 DCHECK_GE(i, 0); | 99 DCHECK_GE(i, 0); |
99 DCHECK_LT(i, MODEL_TYPE_COUNT); | 100 DCHECK_LT(i, MODEL_TYPE_COUNT); |
100 return static_cast<ModelType>(i); | 101 return static_cast<ModelType>(i); |
101 } | 102 } |
102 | 103 |
103 void AddDefaultFieldValue(ModelType datatype, | 104 SYNC_EXPORT void AddDefaultFieldValue(ModelType datatype, |
104 sync_pb::EntitySpecifics* specifics); | 105 sync_pb::EntitySpecifics* specifics); |
105 | 106 |
106 // Extract the model type of a SyncEntity protocol buffer. ModelType is a | 107 // Extract the model type of a SyncEntity protocol buffer. ModelType is a |
107 // local concept: the enum is not in the protocol. The SyncEntity's ModelType | 108 // local concept: the enum is not in the protocol. The SyncEntity's ModelType |
108 // is inferred from the presence of particular datatype field in the | 109 // is inferred from the presence of particular datatype field in the |
109 // entity specifics. | 110 // entity specifics. |
110 ModelType GetModelType(const sync_pb::SyncEntity& sync_entity); | 111 SYNC_EXPORT ModelType GetModelType(const sync_pb::SyncEntity& sync_entity); |
111 | 112 |
112 // Extract the model type from an EntitySpecifics field. Note that there | 113 // Extract the model type from an EntitySpecifics field. Note that there |
113 // are some ModelTypes (like TOP_LEVEL_FOLDER) that can't be inferred this way; | 114 // are some ModelTypes (like TOP_LEVEL_FOLDER) that can't be inferred this way; |
114 // prefer using GetModelType where possible. | 115 // prefer using GetModelType where possible. |
115 ModelType GetModelTypeFromSpecifics(const sync_pb::EntitySpecifics& specifics); | 116 SYNC_EXPORT ModelType GetModelTypeFromSpecifics( |
117 const sync_pb::EntitySpecifics& specifics); | |
116 | 118 |
117 // If this returns false, we shouldn't bother maintaining a position | 119 // If this returns false, we shouldn't bother maintaining a position |
118 // value (sibling ordering) for this item. | 120 // value (sibling ordering) for this item. |
119 bool ShouldMaintainPosition(ModelType model_type); | 121 SYNC_EXPORT bool ShouldMaintainPosition(ModelType model_type); |
rlarocque
2012/07/12 17:45:56
Does this need to be exported? I don't think it's
| |
120 | 122 |
121 // Determine a model type from the field number of its associated | 123 // Determine a model type from the field number of its associated |
122 // EntitySpecifics field. | 124 // EntitySpecifics field. |
123 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number); | 125 // |
126 // TODO(akalin): Move this to a more private place? | |
127 SYNC_EXPORT ModelType GetModelTypeFromSpecificsFieldNumber(int field_number); | |
124 | 128 |
125 // Return the field number of the EntitySpecifics field associated with | 129 // Return the field number of the EntitySpecifics field associated with |
126 // a model type. | 130 // a model type. |
127 int GetSpecificsFieldNumberFromModelType(ModelType model_type); | 131 SYNC_EXPORT_PRIVATE int GetSpecificsFieldNumberFromModelType( |
132 ModelType model_type); | |
128 | 133 |
129 // TODO(sync): The functions below badly need some cleanup. | 134 // TODO(sync): The functions below badly need some cleanup. |
130 | 135 |
131 // Returns a pointer to a string with application lifetime that represents | 136 // Returns a pointer to a string with application lifetime that represents |
132 // the name of |model_type|. | 137 // the name of |model_type|. |
133 const char* ModelTypeToString(ModelType model_type); | 138 SYNC_EXPORT const char* ModelTypeToString(ModelType model_type); |
134 | 139 |
135 // Handles all model types, and not just real ones. | 140 // Handles all model types, and not just real ones. |
136 // | 141 // |
137 // Caller takes ownership of returned value. | 142 // Caller takes ownership of returned value. |
138 base::StringValue* ModelTypeToValue(ModelType model_type); | 143 SYNC_EXPORT base::StringValue* ModelTypeToValue(ModelType model_type); |
139 | 144 |
140 // Converts a Value into a ModelType - complement to ModelTypeToValue(). | 145 // Converts a Value into a ModelType - complement to ModelTypeToValue(). |
141 ModelType ModelTypeFromValue(const base::Value& value); | 146 SYNC_EXPORT ModelType ModelTypeFromValue(const base::Value& value); |
142 | 147 |
143 // Returns the ModelType corresponding to the name |model_type_string|. | 148 // Returns the ModelType corresponding to the name |model_type_string|. |
144 ModelType ModelTypeFromString(const std::string& model_type_string); | 149 SYNC_EXPORT ModelType ModelTypeFromString( |
150 const std::string& model_type_string); | |
145 | 151 |
146 std::string ModelTypeSetToString(ModelTypeSet model_types); | 152 SYNC_EXPORT std::string ModelTypeSetToString(ModelTypeSet model_types); |
147 | 153 |
148 // Caller takes ownership of returned list. | 154 // Caller takes ownership of returned list. |
149 base::ListValue* ModelTypeSetToValue(ModelTypeSet model_types); | 155 SYNC_EXPORT base::ListValue* ModelTypeSetToValue(ModelTypeSet model_types); |
150 | 156 |
151 ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value); | 157 SYNC_EXPORT ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value); |
152 | 158 |
153 // Returns a string corresponding to the syncable tag for this datatype. | 159 // Returns a string corresponding to the syncable tag for this datatype. |
154 std::string ModelTypeToRootTag(ModelType type); | 160 SYNC_EXPORT std::string ModelTypeToRootTag(ModelType type); |
155 | 161 |
156 // Convert a real model type to a notification type (used for | 162 // Convert a real model type to a notification type (used for |
157 // subscribing to server-issued notifications). Returns true iff | 163 // subscribing to server-issued notifications). Returns true iff |
158 // |model_type| was a real model type and |notification_type| was | 164 // |model_type| was a real model type and |notification_type| was |
159 // filled in. | 165 // filled in. |
160 bool RealModelTypeToNotificationType(ModelType model_type, | 166 SYNC_EXPORT bool RealModelTypeToNotificationType( |
161 std::string* notification_type); | 167 ModelType model_type, std::string* notification_type); |
162 | 168 |
163 // Converts a notification type to a real model type. Returns true | 169 // Converts a notification type to a real model type. Returns true |
164 // iff |notification_type| was the notification type of a real model | 170 // iff |notification_type| was the notification type of a real model |
165 // type and |model_type| was filled in. | 171 // type and |model_type| was filled in. |
166 bool NotificationTypeToRealModelType(const std::string& notification_type, | 172 SYNC_EXPORT bool NotificationTypeToRealModelType( |
167 ModelType* model_type); | 173 const std::string& notification_type, |
174 ModelType* model_type); | |
168 | 175 |
169 // Returns true if |model_type| is a real datatype | 176 // Returns true if |model_type| is a real datatype |
170 bool IsRealDataType(ModelType model_type); | 177 SYNC_EXPORT bool IsRealDataType(ModelType model_type); |
171 | 178 |
172 } // namespace syncer | 179 } // namespace syncer |
173 | 180 |
174 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_MODEL_TYPE_H_ | 181 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_MODEL_TYPE_H_ |
OLD | NEW |