Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(621)

Side by Side Diff: components/sync/base/model_type.h

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 COMPONENTS_SYNC_BASE_MODEL_TYPE_H_
10 #define SYNC_INTERNAL_API_PUBLIC_BASE_MODEL_TYPE_H_ 10 #define COMPONENTS_SYNC_BASE_MODEL_TYPE_H_
11 11
12 #include <map> 12 #include <map>
13 #include <memory> 13 #include <memory>
14 #include <ostream> 14 #include <ostream>
15 #include <set> 15 #include <set>
16 #include <string> 16 #include <string>
17 17
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "sync/base/sync_export.h" 19 #include "components/sync/base/enum_set.h"
20 #include "sync/internal_api/public/base/enum_set.h" 20 #include "components/sync/base/sync_export.h"
21 21
22 namespace base { 22 namespace base {
23 class ListValue; 23 class ListValue;
24 class StringValue; 24 class StringValue;
25 class Value; 25 class Value;
26 } 26 }
27 27
28 namespace sync_pb { 28 namespace sync_pb {
29 class EntitySpecifics; 29 class EntitySpecifics;
30 class SyncEntity; 30 class SyncEntity;
31 } 31 }
32 32
33 namespace syncer { 33 namespace syncer {
34 34
35 // TODO(akalin): Move the non-exported functions in this file to a 35 // TODO(akalin): Move the non-exported functions in this file to a
36 // private header. 36 // private header.
37 37
38 // A Java counterpart will be generated for this enum. 38 // A Java counterpart will be generated for this enum.
39 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.sync 39 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.sync
40 40
41 // |kModelTypeInfoMap| struct entries are in the same order as their definition 41 // |kModelTypeInfoMap| struct entries are in the same order as their definition
42 // in ModelType enum. Don't forget to update the |kModelTypeInfoMap| struct in 42 // in ModelType enum. Don't forget to update the |kModelTypeInfoMap| struct in
43 // model_type.cc when you make changes in ModelType enum. 43 // model_type.cc when you make changes in ModelType enum.
44 enum ModelType { 44 enum ModelType {
45 // Object type unknown. Objects may transition through 45 // Object type unknown. Objects may transition through
46 // the unknown state during their initial creation, before 46 // the unknown state during their initial creation, before
47 // their properties are set. After deletion, object types 47 // their properties are set. After deletion, object types
48 // are generally preserved. 48 // are generally preserved.
49 UNSPECIFIED, 49 UNSPECIFIED,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 // sync preferences UI, be sure to update the list in 159 // sync preferences UI, be sure to update the list in
160 // components/sync_driver/user_selectable_sync_type.h so that the UMA 160 // components/sync_driver/user_selectable_sync_type.h so that the UMA
161 // histograms for sync include your new type. In this case, be sure to also 161 // histograms for sync include your new type. In this case, be sure to also
162 // update the UserSelectableTypes() definition in 162 // update the UserSelectableTypes() definition in
163 // sync/syncable/model_type.cc. 163 // sync/syncable/model_type.cc.
164 MODEL_TYPE_COUNT, 164 MODEL_TYPE_COUNT,
165 }; 165 };
166 166
167 typedef EnumSet<ModelType, FIRST_REAL_MODEL_TYPE, LAST_REAL_MODEL_TYPE> 167 typedef EnumSet<ModelType, FIRST_REAL_MODEL_TYPE, LAST_REAL_MODEL_TYPE>
168 ModelTypeSet; 168 ModelTypeSet;
169 typedef EnumSet<ModelType, UNSPECIFIED, LAST_REAL_MODEL_TYPE> 169 typedef EnumSet<ModelType, UNSPECIFIED, LAST_REAL_MODEL_TYPE> FullModelTypeSet;
170 FullModelTypeSet;
171 typedef std::map<syncer::ModelType, const char*> ModelTypeNameMap; 170 typedef std::map<syncer::ModelType, const char*> ModelTypeNameMap;
172 171
173 inline ModelType ModelTypeFromInt(int i) { 172 inline ModelType ModelTypeFromInt(int i) {
174 DCHECK_GE(i, 0); 173 DCHECK_GE(i, 0);
175 DCHECK_LT(i, MODEL_TYPE_COUNT); 174 DCHECK_LT(i, MODEL_TYPE_COUNT);
176 return static_cast<ModelType>(i); 175 return static_cast<ModelType>(i);
177 } 176 }
178 177
179 // Used by tests outside of sync/. 178 // Used by tests outside of sync/.
180 SYNC_EXPORT void AddDefaultFieldValue(ModelType datatype, 179 SYNC_EXPORT void AddDefaultFieldValue(ModelType datatype,
181 sync_pb::EntitySpecifics* specifics); 180 sync_pb::EntitySpecifics* specifics);
182 181
183 // Extract the model type of a SyncEntity protocol buffer. ModelType is a 182 // Extract the model type of a SyncEntity protocol buffer. ModelType is a
184 // local concept: the enum is not in the protocol. The SyncEntity's ModelType 183 // local concept: the enum is not in the protocol. The SyncEntity's ModelType
185 // is inferred from the presence of particular datatype field in the 184 // is inferred from the presence of particular datatype field in the
186 // entity specifics. 185 // entity specifics.
187 SYNC_EXPORT ModelType GetModelType(const sync_pb::SyncEntity& sync_entity); 186 SYNC_EXPORT ModelType GetModelType(const sync_pb::SyncEntity& sync_entity);
188 187
189 // Extract the model type from an EntitySpecifics field. Note that there 188 // Extract the model type from an EntitySpecifics field. Note that there
190 // are some ModelTypes (like TOP_LEVEL_FOLDER) that can't be inferred this way; 189 // are some ModelTypes (like TOP_LEVEL_FOLDER) that can't be inferred this way;
191 // prefer using GetModelType where possible. 190 // prefer using GetModelType where possible.
192 SYNC_EXPORT ModelType GetModelTypeFromSpecifics( 191 SYNC_EXPORT ModelType
193 const sync_pb::EntitySpecifics& specifics); 192 GetModelTypeFromSpecifics(const sync_pb::EntitySpecifics& specifics);
194 193
195 // Protocol types are those types that have actual protocol buffer 194 // Protocol types are those types that have actual protocol buffer
196 // representations. This distinguishes them from Proxy types, which have no 195 // representations. This distinguishes them from Proxy types, which have no
197 // protocol representation and are never sent to the server. 196 // protocol representation and are never sent to the server.
198 SYNC_EXPORT ModelTypeSet ProtocolTypes(); 197 SYNC_EXPORT ModelTypeSet ProtocolTypes();
199 198
200 // These are the normal user-controlled types. This is to distinguish from 199 // These are the normal user-controlled types. This is to distinguish from
201 // ControlTypes which are always enabled. Note that some of these share a 200 // ControlTypes which are always enabled. Note that some of these share a
202 // preference flag, so not all of them are individually user-selectable. 201 // preference flag, so not all of them are individually user-selectable.
203 SYNC_EXPORT ModelTypeSet UserTypes(); 202 SYNC_EXPORT ModelTypeSet UserTypes();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 // if (!IsRealDataType(model_type)) { 260 // if (!IsRealDataType(model_type)) {
262 // DLOG(WARNING) << "Unknown field number " << field_number; 261 // DLOG(WARNING) << "Unknown field number " << field_number;
263 // continue; 262 // continue;
264 // } 263 // }
265 // model_types.Put(model_type); 264 // model_types.Put(model_type);
266 // } 265 // }
267 SYNC_EXPORT ModelType GetModelTypeFromSpecificsFieldNumber(int field_number); 266 SYNC_EXPORT ModelType GetModelTypeFromSpecificsFieldNumber(int field_number);
268 267
269 // Return the field number of the EntitySpecifics field associated with 268 // Return the field number of the EntitySpecifics field associated with
270 // a model type. 269 // a model type.
271 SYNC_EXPORT int GetSpecificsFieldNumberFromModelType( 270 SYNC_EXPORT int GetSpecificsFieldNumberFromModelType(ModelType model_type);
272 ModelType model_type);
273 271
274 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in); 272 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in);
275 273
276 // TODO(sync): The functions below badly need some cleanup. 274 // TODO(sync): The functions below badly need some cleanup.
277 275
278 // Returns a pointer to a string with application lifetime that represents 276 // Returns a pointer to a string with application lifetime that represents
279 // the name of |model_type|. 277 // the name of |model_type|.
280 SYNC_EXPORT const char* ModelTypeToString(ModelType model_type); 278 SYNC_EXPORT const char* ModelTypeToString(ModelType model_type);
281 279
282 // Some histograms take an integer parameter that represents a model type. 280 // Some histograms take an integer parameter that represents a model type.
283 // The mapping from ModelType to integer is defined here. It should match 281 // The mapping from ModelType to integer is defined here. It should match
284 // the mapping from integer to labels defined in histograms.xml. 282 // the mapping from integer to labels defined in histograms.xml.
285 SYNC_EXPORT int ModelTypeToHistogramInt(ModelType model_type); 283 SYNC_EXPORT int ModelTypeToHistogramInt(ModelType model_type);
286 284
287 // Handles all model types, and not just real ones. 285 // Handles all model types, and not just real ones.
288 // 286 //
289 // Caller takes ownership of returned value. 287 // Caller takes ownership of returned value.
290 SYNC_EXPORT base::StringValue* ModelTypeToValue(ModelType model_type); 288 SYNC_EXPORT base::StringValue* ModelTypeToValue(ModelType model_type);
291 289
292 // Converts a Value into a ModelType - complement to ModelTypeToValue(). 290 // Converts a Value into a ModelType - complement to ModelTypeToValue().
293 SYNC_EXPORT ModelType ModelTypeFromValue(const base::Value& value); 291 SYNC_EXPORT ModelType ModelTypeFromValue(const base::Value& value);
294 292
295 // Returns the ModelType corresponding to the name |model_type_string|. 293 // Returns the ModelType corresponding to the name |model_type_string|.
296 SYNC_EXPORT ModelType ModelTypeFromString( 294 SYNC_EXPORT ModelType ModelTypeFromString(const std::string& model_type_string);
297 const std::string& model_type_string);
298 295
299 // Returns the comma-separated string representation of |model_types|. 296 // Returns the comma-separated string representation of |model_types|.
300 SYNC_EXPORT std::string ModelTypeSetToString(ModelTypeSet model_types); 297 SYNC_EXPORT std::string ModelTypeSetToString(ModelTypeSet model_types);
301 298
302 // Necessary for compatibility with EXPECT_EQ and the like. 299 // Necessary for compatibility with EXPECT_EQ and the like.
303 SYNC_EXPORT std::ostream& operator<<(std::ostream& out, 300 SYNC_EXPORT std::ostream& operator<<(std::ostream& out,
304 ModelTypeSet model_type_set); 301 ModelTypeSet model_type_set);
305 302
306 // Returns the set of comma-separated model types from |model_type_string|. 303 // Returns the set of comma-separated model types from |model_type_string|.
307 SYNC_EXPORT ModelTypeSet ModelTypeSetFromString( 304 SYNC_EXPORT ModelTypeSet
308 const std::string& model_type_string); 305 ModelTypeSetFromString(const std::string& model_type_string);
309 306
310 SYNC_EXPORT std::unique_ptr<base::ListValue> ModelTypeSetToValue( 307 SYNC_EXPORT std::unique_ptr<base::ListValue> ModelTypeSetToValue(
311 ModelTypeSet model_types); 308 ModelTypeSet model_types);
312 309
313 SYNC_EXPORT ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value); 310 SYNC_EXPORT ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value);
314 311
315 // Returns a string corresponding to the syncable tag for this datatype. 312 // Returns a string corresponding to the syncable tag for this datatype.
316 SYNC_EXPORT std::string ModelTypeToRootTag(ModelType type); 313 SYNC_EXPORT std::string ModelTypeToRootTag(ModelType type);
317 314
318 // Returns root_tag for |model_type| in ModelTypeInfo. 315 // Returns root_tag for |model_type| in ModelTypeInfo.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 SYNC_EXPORT bool IsTypeWithClientGeneratedRoot(ModelType model_type); 353 SYNC_EXPORT bool IsTypeWithClientGeneratedRoot(ModelType model_type);
357 354
358 // Returns true if |model_type| supports parent-child hierarchy or entries. 355 // Returns true if |model_type| supports parent-child hierarchy or entries.
359 SYNC_EXPORT bool TypeSupportsHierarchy(ModelType model_type); 356 SYNC_EXPORT bool TypeSupportsHierarchy(ModelType model_type);
360 357
361 // Returns true if |model_type| supports ordering of sibling entries. 358 // Returns true if |model_type| supports ordering of sibling entries.
362 SYNC_EXPORT bool TypeSupportsOrdering(ModelType model_type); 359 SYNC_EXPORT bool TypeSupportsOrdering(ModelType model_type);
363 360
364 } // namespace syncer 361 } // namespace syncer
365 362
366 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_MODEL_TYPE_H_ 363 #endif // COMPONENTS_SYNC_BASE_MODEL_TYPE_H_
OLDNEW
« no previous file with comments | « components/sync/base/mock_unrecoverable_error_handler.cc ('k') | components/sync/base/model_type_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698