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; |
27 class SyncEntity; | 28 class SyncEntity; |
28 } | 29 } |
29 | 30 |
30 namespace syncer { | 31 namespace syncer { |
31 | 32 |
| 33 // TODO(akalin): Move the non-exported functions in this file to a |
| 34 // private header. |
| 35 |
32 enum ModelType { | 36 enum ModelType { |
33 // Object type unknown. Objects may transition through | 37 // Object type unknown. Objects may transition through |
34 // the unknown state during their initial creation, before | 38 // the unknown state during their initial creation, before |
35 // their properties are set. After deletion, object types | 39 // their properties are set. After deletion, object types |
36 // are generally preserved. | 40 // are generally preserved. |
37 UNSPECIFIED, | 41 UNSPECIFIED, |
38 // A permanent folder whose children may be of mixed | 42 // A permanent folder whose children may be of mixed |
39 // datatypes (e.g. the "Google Chrome" folder). | 43 // datatypes (e.g. the "Google Chrome" folder). |
40 TOP_LEVEL_FOLDER, | 44 TOP_LEVEL_FOLDER, |
41 | 45 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 ModelType, FIRST_REAL_MODEL_TYPE, LAST_REAL_MODEL_TYPE> ModelTypeSet; | 97 ModelType, FIRST_REAL_MODEL_TYPE, LAST_REAL_MODEL_TYPE> ModelTypeSet; |
94 typedef syncer::EnumSet< | 98 typedef syncer::EnumSet< |
95 ModelType, UNSPECIFIED, LAST_REAL_MODEL_TYPE> FullModelTypeSet; | 99 ModelType, UNSPECIFIED, LAST_REAL_MODEL_TYPE> FullModelTypeSet; |
96 | 100 |
97 inline ModelType ModelTypeFromInt(int i) { | 101 inline ModelType ModelTypeFromInt(int i) { |
98 DCHECK_GE(i, 0); | 102 DCHECK_GE(i, 0); |
99 DCHECK_LT(i, MODEL_TYPE_COUNT); | 103 DCHECK_LT(i, MODEL_TYPE_COUNT); |
100 return static_cast<ModelType>(i); | 104 return static_cast<ModelType>(i); |
101 } | 105 } |
102 | 106 |
103 void AddDefaultFieldValue(ModelType datatype, | 107 // Used by tests outside of sync/. |
104 sync_pb::EntitySpecifics* specifics); | 108 SYNC_EXPORT void AddDefaultFieldValue(ModelType datatype, |
| 109 sync_pb::EntitySpecifics* specifics); |
105 | 110 |
106 // Extract the model type of a SyncEntity protocol buffer. ModelType is a | 111 // 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 | 112 // 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 | 113 // is inferred from the presence of particular datatype field in the |
109 // entity specifics. | 114 // entity specifics. |
110 ModelType GetModelType(const sync_pb::SyncEntity& sync_entity); | 115 ModelType GetModelType(const sync_pb::SyncEntity& sync_entity); |
111 | 116 |
112 // Extract the model type from an EntitySpecifics field. Note that there | 117 // 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; | 118 // are some ModelTypes (like TOP_LEVEL_FOLDER) that can't be inferred this way; |
114 // prefer using GetModelType where possible. | 119 // prefer using GetModelType where possible. |
115 ModelType GetModelTypeFromSpecifics(const sync_pb::EntitySpecifics& specifics); | 120 SYNC_EXPORT ModelType GetModelTypeFromSpecifics( |
| 121 const sync_pb::EntitySpecifics& specifics); |
116 | 122 |
117 // If this returns false, we shouldn't bother maintaining a position | 123 // If this returns false, we shouldn't bother maintaining a position |
118 // value (sibling ordering) for this item. | 124 // value (sibling ordering) for this item. |
119 bool ShouldMaintainPosition(ModelType model_type); | 125 bool ShouldMaintainPosition(ModelType model_type); |
120 | 126 |
121 // Determine a model type from the field number of its associated | 127 // Determine a model type from the field number of its associated |
122 // EntitySpecifics field. | 128 // EntitySpecifics field. |
123 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number); | 129 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number); |
124 | 130 |
125 // Return the field number of the EntitySpecifics field associated with | 131 // Return the field number of the EntitySpecifics field associated with |
126 // a model type. | 132 // a model type. |
127 int GetSpecificsFieldNumberFromModelType(ModelType model_type); | 133 // |
| 134 // Used by tests outside of sync. |
| 135 SYNC_EXPORT int GetSpecificsFieldNumberFromModelType( |
| 136 ModelType model_type); |
128 | 137 |
129 // TODO(sync): The functions below badly need some cleanup. | 138 // TODO(sync): The functions below badly need some cleanup. |
130 | 139 |
131 // Returns a pointer to a string with application lifetime that represents | 140 // Returns a pointer to a string with application lifetime that represents |
132 // the name of |model_type|. | 141 // the name of |model_type|. |
133 const char* ModelTypeToString(ModelType model_type); | 142 SYNC_EXPORT const char* ModelTypeToString(ModelType model_type); |
134 | 143 |
135 // Handles all model types, and not just real ones. | 144 // Handles all model types, and not just real ones. |
136 // | 145 // |
137 // Caller takes ownership of returned value. | 146 // Caller takes ownership of returned value. |
138 base::StringValue* ModelTypeToValue(ModelType model_type); | 147 base::StringValue* ModelTypeToValue(ModelType model_type); |
139 | 148 |
140 // Converts a Value into a ModelType - complement to ModelTypeToValue(). | 149 // Converts a Value into a ModelType - complement to ModelTypeToValue(). |
141 ModelType ModelTypeFromValue(const base::Value& value); | 150 ModelType ModelTypeFromValue(const base::Value& value); |
142 | 151 |
143 // Returns the ModelType corresponding to the name |model_type_string|. | 152 // Returns the ModelType corresponding to the name |model_type_string|. |
144 ModelType ModelTypeFromString(const std::string& model_type_string); | 153 SYNC_EXPORT ModelType ModelTypeFromString( |
| 154 const std::string& model_type_string); |
145 | 155 |
146 std::string ModelTypeSetToString(ModelTypeSet model_types); | 156 SYNC_EXPORT std::string ModelTypeSetToString(ModelTypeSet model_types); |
147 | 157 |
148 // Caller takes ownership of returned list. | 158 // Caller takes ownership of returned list. |
149 base::ListValue* ModelTypeSetToValue(ModelTypeSet model_types); | 159 SYNC_EXPORT base::ListValue* ModelTypeSetToValue(ModelTypeSet model_types); |
150 | 160 |
151 ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value); | 161 SYNC_EXPORT ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value); |
152 | 162 |
153 // Returns a string corresponding to the syncable tag for this datatype. | 163 // Returns a string corresponding to the syncable tag for this datatype. |
154 std::string ModelTypeToRootTag(ModelType type); | 164 SYNC_EXPORT std::string ModelTypeToRootTag(ModelType type); |
155 | 165 |
156 // Convert a real model type to a notification type (used for | 166 // Convert a real model type to a notification type (used for |
157 // subscribing to server-issued notifications). Returns true iff | 167 // subscribing to server-issued notifications). Returns true iff |
158 // |model_type| was a real model type and |notification_type| was | 168 // |model_type| was a real model type and |notification_type| was |
159 // filled in. | 169 // filled in. |
160 bool RealModelTypeToNotificationType(ModelType model_type, | 170 bool RealModelTypeToNotificationType(ModelType model_type, |
161 std::string* notification_type); | 171 std::string* notification_type); |
162 | 172 |
163 // Converts a notification type to a real model type. Returns true | 173 // Converts a notification type to a real model type. Returns true |
164 // iff |notification_type| was the notification type of a real model | 174 // iff |notification_type| was the notification type of a real model |
165 // type and |model_type| was filled in. | 175 // type and |model_type| was filled in. |
166 bool NotificationTypeToRealModelType(const std::string& notification_type, | 176 bool NotificationTypeToRealModelType(const std::string& notification_type, |
167 ModelType* model_type); | 177 ModelType* model_type); |
168 | 178 |
169 // Returns true if |model_type| is a real datatype | 179 // Returns true if |model_type| is a real datatype |
170 bool IsRealDataType(ModelType model_type); | 180 SYNC_EXPORT bool IsRealDataType(ModelType model_type); |
171 | 181 |
172 } // namespace syncer | 182 } // namespace syncer |
173 | 183 |
174 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_MODEL_TYPE_H_ | 184 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_MODEL_TYPE_H_ |
OLD | NEW |