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 "components/sync/base/model_type.h" | 5 #include "components/sync/base/model_type.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "components/sync/protocol/app_notification_specifics.pb.h" | 12 #include "components/sync/protocol/app_notification_specifics.pb.h" |
13 #include "components/sync/protocol/app_setting_specifics.pb.h" | 13 #include "components/sync/protocol/app_setting_specifics.pb.h" |
14 #include "components/sync/protocol/app_specifics.pb.h" | 14 #include "components/sync/protocol/app_specifics.pb.h" |
15 #include "components/sync/protocol/autofill_specifics.pb.h" | 15 #include "components/sync/protocol/autofill_specifics.pb.h" |
16 #include "components/sync/protocol/bookmark_specifics.pb.h" | 16 #include "components/sync/protocol/bookmark_specifics.pb.h" |
17 #include "components/sync/protocol/extension_setting_specifics.pb.h" | 17 #include "components/sync/protocol/extension_setting_specifics.pb.h" |
18 #include "components/sync/protocol/extension_specifics.pb.h" | 18 #include "components/sync/protocol/extension_specifics.pb.h" |
19 #include "components/sync/protocol/nigori_specifics.pb.h" | 19 #include "components/sync/protocol/nigori_specifics.pb.h" |
20 #include "components/sync/protocol/password_specifics.pb.h" | 20 #include "components/sync/protocol/password_specifics.pb.h" |
21 #include "components/sync/protocol/preference_specifics.pb.h" | 21 #include "components/sync/protocol/preference_specifics.pb.h" |
| 22 #include "components/sync/protocol/reading_list_specifics.pb.h" |
22 #include "components/sync/protocol/search_engine_specifics.pb.h" | 23 #include "components/sync/protocol/search_engine_specifics.pb.h" |
23 #include "components/sync/protocol/session_specifics.pb.h" | 24 #include "components/sync/protocol/session_specifics.pb.h" |
24 #include "components/sync/protocol/sync.pb.h" | 25 #include "components/sync/protocol/sync.pb.h" |
25 #include "components/sync/protocol/theme_specifics.pb.h" | 26 #include "components/sync/protocol/theme_specifics.pb.h" |
26 #include "components/sync/protocol/typed_url_specifics.pb.h" | 27 #include "components/sync/protocol/typed_url_specifics.pb.h" |
27 #include "components/sync/syncable/syncable_proto_util.h" | 28 #include "components/sync/syncable/syncable_proto_util.h" |
28 | 29 |
29 namespace syncer { | 30 namespace syncer { |
30 | 31 |
31 struct ModelTypeInfo { | 32 struct ModelTypeInfo { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 {WIFI_CREDENTIALS, "WIFI_CREDENTIAL", "wifi_credentials", | 129 {WIFI_CREDENTIALS, "WIFI_CREDENTIAL", "wifi_credentials", |
129 "WiFi Credentials", sync_pb::EntitySpecifics::kWifiCredentialFieldNumber, | 130 "WiFi Credentials", sync_pb::EntitySpecifics::kWifiCredentialFieldNumber, |
130 32}, | 131 32}, |
131 {SUPERVISED_USER_WHITELISTS, "MANAGED_USER_WHITELIST", | 132 {SUPERVISED_USER_WHITELISTS, "MANAGED_USER_WHITELIST", |
132 "managed_user_whitelists", "Managed User Whitelists", | 133 "managed_user_whitelists", "Managed User Whitelists", |
133 sync_pb::EntitySpecifics::kManagedUserWhitelistFieldNumber, 33}, | 134 sync_pb::EntitySpecifics::kManagedUserWhitelistFieldNumber, 33}, |
134 {ARC_PACKAGE, "ARC_PACKAGE", "arc_package", "Arc Package", | 135 {ARC_PACKAGE, "ARC_PACKAGE", "arc_package", "Arc Package", |
135 sync_pb::EntitySpecifics::kArcPackageFieldNumber, 36}, | 136 sync_pb::EntitySpecifics::kArcPackageFieldNumber, 36}, |
136 {PRINTERS, "PRINTER", "printers", "Printers", | 137 {PRINTERS, "PRINTER", "printers", "Printers", |
137 sync_pb::EntitySpecifics::kPrinterFieldNumber, 37}, | 138 sync_pb::EntitySpecifics::kPrinterFieldNumber, 37}, |
| 139 {READING_LIST, "READING_LIST", "reading_list", "Reading List", |
| 140 sync_pb::EntitySpecifics::kReadingListFieldNumber, 38}, |
138 {PROXY_TABS, "", "", "Tabs", -1, 25}, | 141 {PROXY_TABS, "", "", "Tabs", -1, 25}, |
139 {NIGORI, "NIGORI", "nigori", "Encryption keys", | 142 {NIGORI, "NIGORI", "nigori", "Encryption keys", |
140 sync_pb::EntitySpecifics::kNigoriFieldNumber, 17}, | 143 sync_pb::EntitySpecifics::kNigoriFieldNumber, 17}, |
141 {EXPERIMENTS, "EXPERIMENTS", "experiments", "Experiments", | 144 {EXPERIMENTS, "EXPERIMENTS", "experiments", "Experiments", |
142 sync_pb::EntitySpecifics::kExperimentsFieldNumber, 19}, | 145 sync_pb::EntitySpecifics::kExperimentsFieldNumber, 19}, |
143 }; | 146 }; |
144 | 147 |
145 static_assert(arraysize(kModelTypeInfoMap) == MODEL_TYPE_COUNT, | 148 static_assert(arraysize(kModelTypeInfoMap) == MODEL_TYPE_COUNT, |
146 "kModelTypeInfoMap should have MODEL_TYPE_COUNT elements"); | 149 "kModelTypeInfoMap should have MODEL_TYPE_COUNT elements"); |
147 | 150 |
148 // Notes: | 151 // Notes: |
149 // 1) This list must contain exactly the same elements as the set returned by | 152 // 1) This list must contain exactly the same elements as the set returned by |
150 // UserSelectableTypes(). | 153 // UserSelectableTypes(). |
151 // 2) This list must be in the same order as the respective values in the | 154 // 2) This list must be in the same order as the respective values in the |
152 // ModelType enum. | 155 // ModelType enum. |
153 const char* kUserSelectableDataTypeNames[] = { | 156 const char* kUserSelectableDataTypeNames[] = { |
154 "bookmarks", "preferences", "passwords", "autofill", "themes", | 157 "bookmarks", "preferences", "passwords", "autofill", "themes", |
155 "typedUrls", "extensions", "apps", "tabs", | 158 "typedUrls", "extensions", "apps", "tabs", |
156 }; | 159 }; |
157 | 160 |
158 static_assert( | 161 static_assert( |
159 38 == MODEL_TYPE_COUNT, | 162 39 == MODEL_TYPE_COUNT, |
160 "update kUserSelectableDataTypeName to match UserSelectableTypes"); | 163 "update kUserSelectableDataTypeName to match UserSelectableTypes"); |
161 | 164 |
162 void AddDefaultFieldValue(ModelType datatype, | 165 void AddDefaultFieldValue(ModelType datatype, |
163 sync_pb::EntitySpecifics* specifics) { | 166 sync_pb::EntitySpecifics* specifics) { |
164 if (!ProtocolTypes().Has(datatype)) { | 167 if (!ProtocolTypes().Has(datatype)) { |
165 NOTREACHED() << "Only protocol types have field values."; | 168 NOTREACHED() << "Only protocol types have field values."; |
166 return; | 169 return; |
167 } | 170 } |
168 switch (datatype) { | 171 switch (datatype) { |
169 case BOOKMARKS: | 172 case BOOKMARKS: |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 break; | 267 break; |
265 case SUPERVISED_USER_WHITELISTS: | 268 case SUPERVISED_USER_WHITELISTS: |
266 specifics->mutable_managed_user_whitelist(); | 269 specifics->mutable_managed_user_whitelist(); |
267 break; | 270 break; |
268 case ARTICLES: | 271 case ARTICLES: |
269 specifics->mutable_article(); | 272 specifics->mutable_article(); |
270 break; | 273 break; |
271 case WIFI_CREDENTIALS: | 274 case WIFI_CREDENTIALS: |
272 specifics->mutable_wifi_credential(); | 275 specifics->mutable_wifi_credential(); |
273 break; | 276 break; |
| 277 case READING_LIST: |
| 278 specifics->mutable_reading_list(); |
| 279 break; |
274 default: | 280 default: |
275 NOTREACHED() << "No known extension for model type."; | 281 NOTREACHED() << "No known extension for model type."; |
276 } | 282 } |
277 } | 283 } |
278 | 284 |
279 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { | 285 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { |
280 ModelTypeSet protocol_types = ProtocolTypes(); | 286 ModelTypeSet protocol_types = ProtocolTypes(); |
281 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); | 287 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); |
282 iter.Inc()) { | 288 iter.Inc()) { |
283 if (GetSpecificsFieldNumberFromModelType(iter.Get()) == field_number) | 289 if (GetSpecificsFieldNumberFromModelType(iter.Get()) == field_number) |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 | 386 |
381 if (specifics.has_app_setting()) | 387 if (specifics.has_app_setting()) |
382 return APP_SETTINGS; | 388 return APP_SETTINGS; |
383 | 389 |
384 if (specifics.has_extension_setting()) | 390 if (specifics.has_extension_setting()) |
385 return EXTENSION_SETTINGS; | 391 return EXTENSION_SETTINGS; |
386 | 392 |
387 if (specifics.has_app_notification()) | 393 if (specifics.has_app_notification()) |
388 return APP_NOTIFICATIONS; | 394 return APP_NOTIFICATIONS; |
389 | 395 |
| 396 if (specifics.has_reading_list()) |
| 397 return READING_LIST; |
| 398 |
390 if (specifics.has_history_delete_directive()) | 399 if (specifics.has_history_delete_directive()) |
391 return HISTORY_DELETE_DIRECTIVES; | 400 return HISTORY_DELETE_DIRECTIVES; |
392 | 401 |
393 if (specifics.has_synced_notification()) | 402 if (specifics.has_synced_notification()) |
394 return SYNCED_NOTIFICATIONS; | 403 return SYNCED_NOTIFICATIONS; |
395 | 404 |
396 if (specifics.has_synced_notification_app_info()) | 405 if (specifics.has_synced_notification_app_info()) |
397 return SYNCED_NOTIFICATION_APP_INFO; | 406 return SYNCED_NOTIFICATION_APP_INFO; |
398 | 407 |
399 if (specifics.has_device_info()) | 408 if (specifics.has_device_info()) |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 bool TypeSupportsHierarchy(ModelType model_type) { | 765 bool TypeSupportsHierarchy(ModelType model_type) { |
757 // TODO(stanisc): crbug/438313: Should this also include TOP_LEVEL_FOLDER? | 766 // TODO(stanisc): crbug/438313: Should this also include TOP_LEVEL_FOLDER? |
758 return model_type == BOOKMARKS; | 767 return model_type == BOOKMARKS; |
759 } | 768 } |
760 | 769 |
761 bool TypeSupportsOrdering(ModelType model_type) { | 770 bool TypeSupportsOrdering(ModelType model_type) { |
762 return model_type == BOOKMARKS; | 771 return model_type == BOOKMARKS; |
763 } | 772 } |
764 | 773 |
765 } // namespace syncer | 774 } // namespace syncer |
OLD | NEW |