OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // Enumerate the various item subtypes that are supported by sync. | |
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. | |
8 | |
9 #ifndef CHROME_BROWSER_SYNC_SYNCABLE_MODEL_TYPE_H_ | |
10 #define CHROME_BROWSER_SYNC_SYNCABLE_MODEL_TYPE_H_ | |
11 #pragma once | |
12 | |
13 #include <set> | |
14 #include <string> | |
15 | |
16 #include "base/logging.h" | |
17 #include "base/time.h" | |
18 #include "chrome/browser/sync/util/enum_set.h" | |
19 | |
20 namespace base { | |
21 class ListValue; | |
22 class StringValue; | |
23 class Value; | |
24 } | |
25 | |
26 namespace sync_pb { | |
27 class EntitySpecifics; | |
28 class SyncEntity; | |
29 } | |
30 | |
31 namespace syncable { | |
32 | |
33 enum ModelType { | |
34 // Object type unknown. Objects may transition through | |
35 // the unknown state during their initial creation, before | |
36 // their properties are set. After deletion, object types | |
37 // are generally preserved. | |
38 UNSPECIFIED, | |
39 // A permanent folder whose children may be of mixed | |
40 // datatypes (e.g. the "Google Chrome" folder). | |
41 TOP_LEVEL_FOLDER, | |
42 | |
43 // ------------------------------------ Start of "real" model types. | |
44 // The model types declared before here are somewhat special, as they | |
45 // they do not correspond to any browser data model. The remaining types | |
46 // are bona fide model types; all have a related browser data model and | |
47 // can be represented in the protocol using a specific Message type in the | |
48 // EntitySpecifics protocol buffer. | |
49 // | |
50 // A bookmark folder or a bookmark URL object. | |
51 BOOKMARKS, | |
52 FIRST_REAL_MODEL_TYPE = BOOKMARKS, // Declared 2nd, for debugger prettiness. | |
53 | |
54 // A preference folder or a preference object. | |
55 PREFERENCES, | |
56 // A password folder or password object. | |
57 PASSWORDS, | |
58 // An AutofillProfile Object | |
59 AUTOFILL_PROFILE, | |
60 // An autofill folder or an autofill object. | |
61 AUTOFILL, | |
62 | |
63 // A themes folder or a themes object. | |
64 THEMES, | |
65 // A typed_url folder or a typed_url object. | |
66 TYPED_URLS, | |
67 // An extension folder or an extension object. | |
68 EXTENSIONS, | |
69 // An object representing a set of Nigori keys. | |
70 NIGORI, | |
71 // An object representing a custom search engine. | |
72 SEARCH_ENGINES, | |
73 // An object representing a browser session. | |
74 SESSIONS, | |
75 // An app folder or an app object. | |
76 APPS, | |
77 // An app setting from the extension settings API. | |
78 APP_SETTINGS, | |
79 // An extension setting from the extension settings API. | |
80 EXTENSION_SETTINGS, | |
81 // App notifications. | |
82 APP_NOTIFICATIONS, | |
83 LAST_REAL_MODEL_TYPE = APP_NOTIFICATIONS, | |
84 | |
85 // If you are adding a new sync datatype that is exposed to the user via the | |
86 // sync preferences UI, be sure to update the list in | |
87 // chrome/browser/sync/user_selectable_sync_type.h so that the UMA histograms | |
88 // for sync include your new type. | |
89 | |
90 MODEL_TYPE_COUNT, | |
91 }; | |
92 | |
93 typedef browser_sync::EnumSet< | |
94 ModelType, FIRST_REAL_MODEL_TYPE, LAST_REAL_MODEL_TYPE> ModelTypeSet; | |
95 typedef browser_sync::EnumSet< | |
96 ModelType, UNSPECIFIED, LAST_REAL_MODEL_TYPE> FullModelTypeSet; | |
97 | |
98 inline ModelType ModelTypeFromInt(int i) { | |
99 DCHECK_GE(i, 0); | |
100 DCHECK_LT(i, MODEL_TYPE_COUNT); | |
101 return static_cast<ModelType>(i); | |
102 } | |
103 | |
104 void AddDefaultFieldValue(syncable::ModelType datatype, | |
105 sync_pb::EntitySpecifics* specifics); | |
106 | |
107 // Extract the model type of a SyncEntity protocol buffer. ModelType is a | |
108 // local concept: the enum is not in the protocol. The SyncEntity's ModelType | |
109 // is inferred from the presence of particular datatype field in the | |
110 // entity specifics. | |
111 ModelType GetModelType(const sync_pb::SyncEntity& sync_entity); | |
112 | |
113 // Extract the model type from an EntitySpecifics field. Note that there | |
114 // are some ModelTypes (like TOP_LEVEL_FOLDER) that can't be inferred this way; | |
115 // prefer using GetModelType where possible. | |
116 ModelType GetModelTypeFromSpecifics(const sync_pb::EntitySpecifics& specifics); | |
117 | |
118 // If this returns false, we shouldn't bother maintaining a position | |
119 // value (sibling ordering) for this item. | |
120 bool ShouldMaintainPosition(ModelType model_type); | |
121 | |
122 // Determine a model type from the field number of its associated | |
123 // EntitySpecifics field. | |
124 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number); | |
125 | |
126 // Return the field number of the EntitySpecifics field associated with | |
127 // a model type. | |
128 int GetSpecificsFieldNumberFromModelType(ModelType model_type); | |
129 | |
130 // TODO(sync): The functions below badly need some cleanup. | |
131 | |
132 // Returns a pointer to a string with application lifetime that represents | |
133 // the name of |model_type|. | |
134 const char* ModelTypeToString(ModelType model_type); | |
135 | |
136 // Handles all model types, and not just real ones. | |
137 // | |
138 // Caller takes ownership of returned value. | |
139 base::StringValue* ModelTypeToValue(ModelType model_type); | |
140 | |
141 // Converts a Value into a ModelType - complement to ModelTypeToValue(). | |
142 ModelType ModelTypeFromValue(const base::Value& value); | |
143 | |
144 // Returns the ModelType corresponding to the name |model_type_string|. | |
145 ModelType ModelTypeFromString(const std::string& model_type_string); | |
146 | |
147 std::string ModelTypeSetToString(ModelTypeSet model_types); | |
148 | |
149 // Caller takes ownership of returned list. | |
150 base::ListValue* ModelTypeSetToValue(ModelTypeSet model_types); | |
151 | |
152 ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value); | |
153 | |
154 // Returns a string corresponding to the syncable tag for this datatype. | |
155 std::string ModelTypeToRootTag(ModelType type); | |
156 | |
157 // Convert a real model type to a notification type (used for | |
158 // subscribing to server-issued notifications). Returns true iff | |
159 // |model_type| was a real model type and |notification_type| was | |
160 // filled in. | |
161 bool RealModelTypeToNotificationType(ModelType model_type, | |
162 std::string* notification_type); | |
163 | |
164 // Converts a notification type to a real model type. Returns true | |
165 // iff |notification_type| was the notification type of a real model | |
166 // type and |model_type| was filled in. | |
167 bool NotificationTypeToRealModelType(const std::string& notification_type, | |
168 ModelType* model_type); | |
169 | |
170 // Returns true if |model_type| is a real datatype | |
171 bool IsRealDataType(ModelType model_type); | |
172 | |
173 } // namespace syncable | |
174 | |
175 #endif // CHROME_BROWSER_SYNC_SYNCABLE_MODEL_TYPE_H_ | |
OLD | NEW |