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 "sync/internal_api/public/base/model_type.h" | 5 #include "sync/internal_api/public/base/model_type.h" |
6 | 6 |
7 #include "base/string_split.h" | 7 #include "base/string_split.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "sync/protocol/app_notification_specifics.pb.h" | 9 #include "sync/protocol/app_notification_specifics.pb.h" |
10 #include "sync/protocol/app_setting_specifics.pb.h" | 10 #include "sync/protocol/app_setting_specifics.pb.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 break; | 66 break; |
67 case APP_SETTINGS: | 67 case APP_SETTINGS: |
68 specifics->mutable_app_setting(); | 68 specifics->mutable_app_setting(); |
69 break; | 69 break; |
70 case EXTENSION_SETTINGS: | 70 case EXTENSION_SETTINGS: |
71 specifics->mutable_extension_setting(); | 71 specifics->mutable_extension_setting(); |
72 break; | 72 break; |
73 case APP_NOTIFICATIONS: | 73 case APP_NOTIFICATIONS: |
74 specifics->mutable_app_notification(); | 74 specifics->mutable_app_notification(); |
75 break; | 75 break; |
| 76 case HISTORY_DELETE_DIRECTIVES: |
| 77 specifics->mutable_history_delete_directive(); |
| 78 break; |
76 default: | 79 default: |
77 NOTREACHED() << "No known extension for model type."; | 80 NOTREACHED() << "No known extension for model type."; |
78 } | 81 } |
79 } | 82 } |
80 | 83 |
81 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { | 84 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { |
82 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 85 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
83 ModelType model_type = ModelTypeFromInt(i); | 86 ModelType model_type = ModelTypeFromInt(i); |
84 if (GetSpecificsFieldNumberFromModelType(model_type) == field_number) | 87 if (GetSpecificsFieldNumberFromModelType(model_type) == field_number) |
85 return model_type; | 88 return model_type; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 break; | 131 break; |
129 case APP_SETTINGS: | 132 case APP_SETTINGS: |
130 return sync_pb::EntitySpecifics::kAppSettingFieldNumber; | 133 return sync_pb::EntitySpecifics::kAppSettingFieldNumber; |
131 break; | 134 break; |
132 case EXTENSION_SETTINGS: | 135 case EXTENSION_SETTINGS: |
133 return sync_pb::EntitySpecifics::kExtensionSettingFieldNumber; | 136 return sync_pb::EntitySpecifics::kExtensionSettingFieldNumber; |
134 break; | 137 break; |
135 case APP_NOTIFICATIONS: | 138 case APP_NOTIFICATIONS: |
136 return sync_pb::EntitySpecifics::kAppNotificationFieldNumber; | 139 return sync_pb::EntitySpecifics::kAppNotificationFieldNumber; |
137 break; | 140 break; |
| 141 case HISTORY_DELETE_DIRECTIVES: |
| 142 return sync_pb::EntitySpecifics::kHistoryDeleteDirectiveFieldNumber; |
| 143 break; |
138 default: | 144 default: |
139 NOTREACHED() << "No known extension for model type."; | 145 NOTREACHED() << "No known extension for model type."; |
140 return 0; | 146 return 0; |
141 } | 147 } |
142 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of " | 148 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of " |
143 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681"; | 149 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681"; |
144 return 0; | 150 return 0; |
145 } | 151 } |
146 | 152 |
147 // Note: keep this consistent with GetModelType in syncable.cc! | 153 // Note: keep this consistent with GetModelType in entry.cc! |
148 ModelType GetModelType(const sync_pb::SyncEntity& sync_entity) { | 154 ModelType GetModelType(const sync_pb::SyncEntity& sync_entity) { |
149 DCHECK(!IsRoot(sync_entity)); // Root shouldn't ever go over the wire. | 155 DCHECK(!IsRoot(sync_entity)); // Root shouldn't ever go over the wire. |
150 | 156 |
151 if (sync_entity.deleted()) | 157 if (sync_entity.deleted()) |
152 return UNSPECIFIED; | 158 return UNSPECIFIED; |
153 | 159 |
154 // Backwards compatibility with old (pre-specifics) protocol. | 160 // Backwards compatibility with old (pre-specifics) protocol. |
155 if (sync_entity.has_bookmarkdata()) | 161 if (sync_entity.has_bookmarkdata()) |
156 return BOOKMARKS; | 162 return BOOKMARKS; |
157 | 163 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 218 |
213 if (specifics.has_app_setting()) | 219 if (specifics.has_app_setting()) |
214 return APP_SETTINGS; | 220 return APP_SETTINGS; |
215 | 221 |
216 if (specifics.has_extension_setting()) | 222 if (specifics.has_extension_setting()) |
217 return EXTENSION_SETTINGS; | 223 return EXTENSION_SETTINGS; |
218 | 224 |
219 if (specifics.has_app_notification()) | 225 if (specifics.has_app_notification()) |
220 return APP_NOTIFICATIONS; | 226 return APP_NOTIFICATIONS; |
221 | 227 |
| 228 if (specifics.has_history_delete_directive()) |
| 229 return HISTORY_DELETE_DIRECTIVES; |
| 230 |
222 return UNSPECIFIED; | 231 return UNSPECIFIED; |
223 } | 232 } |
224 | 233 |
225 bool ShouldMaintainPosition(ModelType model_type) { | 234 bool ShouldMaintainPosition(ModelType model_type) { |
226 return model_type == BOOKMARKS; | 235 return model_type == BOOKMARKS; |
227 } | 236 } |
228 | 237 |
229 const char* ModelTypeToString(ModelType model_type) { | 238 const char* ModelTypeToString(ModelType model_type) { |
230 // This is used in serialization routines as well as for displaying debug | 239 // This is used in serialization routines as well as for displaying debug |
231 // information. Do not attempt to change these string values unless you know | 240 // information. Do not attempt to change these string values unless you know |
(...skipping 26 matching lines...) Expand all Loading... |
258 case APPS: | 267 case APPS: |
259 return "Apps"; | 268 return "Apps"; |
260 case AUTOFILL_PROFILE: | 269 case AUTOFILL_PROFILE: |
261 return "Autofill Profiles"; | 270 return "Autofill Profiles"; |
262 case APP_SETTINGS: | 271 case APP_SETTINGS: |
263 return "App settings"; | 272 return "App settings"; |
264 case EXTENSION_SETTINGS: | 273 case EXTENSION_SETTINGS: |
265 return "Extension settings"; | 274 return "Extension settings"; |
266 case APP_NOTIFICATIONS: | 275 case APP_NOTIFICATIONS: |
267 return "App Notifications"; | 276 return "App Notifications"; |
| 277 case HISTORY_DELETE_DIRECTIVES: |
| 278 return "History Delete Directives"; |
268 default: | 279 default: |
269 break; | 280 break; |
270 } | 281 } |
271 NOTREACHED() << "No known extension for model type."; | 282 NOTREACHED() << "No known extension for model type."; |
272 return "INVALID"; | 283 return "INVALID"; |
273 } | 284 } |
274 | 285 |
275 StringValue* ModelTypeToValue(ModelType model_type) { | 286 StringValue* ModelTypeToValue(ModelType model_type) { |
276 if (model_type >= FIRST_REAL_MODEL_TYPE) { | 287 if (model_type >= FIRST_REAL_MODEL_TYPE) { |
277 return Value::CreateStringValue(ModelTypeToString(model_type)); | 288 return Value::CreateStringValue(ModelTypeToString(model_type)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 else if (model_type_string == "Sessions") | 334 else if (model_type_string == "Sessions") |
324 return SESSIONS; | 335 return SESSIONS; |
325 else if (model_type_string == "Apps") | 336 else if (model_type_string == "Apps") |
326 return APPS; | 337 return APPS; |
327 else if (model_type_string == "App settings") | 338 else if (model_type_string == "App settings") |
328 return APP_SETTINGS; | 339 return APP_SETTINGS; |
329 else if (model_type_string == "Extension settings") | 340 else if (model_type_string == "Extension settings") |
330 return EXTENSION_SETTINGS; | 341 return EXTENSION_SETTINGS; |
331 else if (model_type_string == "App Notifications") | 342 else if (model_type_string == "App Notifications") |
332 return APP_NOTIFICATIONS; | 343 return APP_NOTIFICATIONS; |
| 344 else if (model_type_string == "History Delete Directives") |
| 345 return HISTORY_DELETE_DIRECTIVES; |
333 else | 346 else |
334 NOTREACHED() << "No known model type corresponding to " | 347 NOTREACHED() << "No known model type corresponding to " |
335 << model_type_string << "."; | 348 << model_type_string << "."; |
336 return UNSPECIFIED; | 349 return UNSPECIFIED; |
337 } | 350 } |
338 | 351 |
339 std::string ModelTypeSetToString(ModelTypeSet model_types) { | 352 std::string ModelTypeSetToString(ModelTypeSet model_types) { |
340 std::string result; | 353 std::string result; |
341 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { | 354 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { |
342 if (!result.empty()) { | 355 if (!result.empty()) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 case APPS: | 404 case APPS: |
392 return "google_chrome_apps"; | 405 return "google_chrome_apps"; |
393 case AUTOFILL_PROFILE: | 406 case AUTOFILL_PROFILE: |
394 return "google_chrome_autofill_profiles"; | 407 return "google_chrome_autofill_profiles"; |
395 case APP_SETTINGS: | 408 case APP_SETTINGS: |
396 return "google_chrome_app_settings"; | 409 return "google_chrome_app_settings"; |
397 case EXTENSION_SETTINGS: | 410 case EXTENSION_SETTINGS: |
398 return "google_chrome_extension_settings"; | 411 return "google_chrome_extension_settings"; |
399 case APP_NOTIFICATIONS: | 412 case APP_NOTIFICATIONS: |
400 return "google_chrome_app_notifications"; | 413 return "google_chrome_app_notifications"; |
| 414 case HISTORY_DELETE_DIRECTIVES: |
| 415 return "google_chrome_history_delete_directives"; |
401 default: | 416 default: |
402 break; | 417 break; |
403 } | 418 } |
404 NOTREACHED() << "No known extension for model type."; | 419 NOTREACHED() << "No known extension for model type."; |
405 return "INVALID"; | 420 return "INVALID"; |
406 } | 421 } |
407 | 422 |
408 // TODO(akalin): Figure out a better way to do these mappings. | 423 // TODO(akalin): Figure out a better way to do these mappings. |
409 | 424 |
410 namespace { | 425 namespace { |
411 const char kBookmarkNotificationType[] = "BOOKMARK"; | 426 const char kBookmarkNotificationType[] = "BOOKMARK"; |
412 const char kPreferenceNotificationType[] = "PREFERENCE"; | 427 const char kPreferenceNotificationType[] = "PREFERENCE"; |
413 const char kPasswordNotificationType[] = "PASSWORD"; | 428 const char kPasswordNotificationType[] = "PASSWORD"; |
414 const char kAutofillNotificationType[] = "AUTOFILL"; | 429 const char kAutofillNotificationType[] = "AUTOFILL"; |
415 const char kThemeNotificationType[] = "THEME"; | 430 const char kThemeNotificationType[] = "THEME"; |
416 const char kTypedUrlNotificationType[] = "TYPED_URL"; | 431 const char kTypedUrlNotificationType[] = "TYPED_URL"; |
417 const char kExtensionNotificationType[] = "EXTENSION"; | 432 const char kExtensionNotificationType[] = "EXTENSION"; |
418 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; | 433 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; |
419 const char kNigoriNotificationType[] = "NIGORI"; | 434 const char kNigoriNotificationType[] = "NIGORI"; |
420 const char kAppSettingNotificationType[] = "APP_SETTING"; | 435 const char kAppSettingNotificationType[] = "APP_SETTING"; |
421 const char kAppNotificationType[] = "APP"; | 436 const char kAppNotificationType[] = "APP"; |
422 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; | 437 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; |
423 const char kSessionNotificationType[] = "SESSION"; | 438 const char kSessionNotificationType[] = "SESSION"; |
424 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; | 439 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; |
425 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; | 440 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; |
| 441 const char kHistoryDeleteDirectiveNotificationType[] = |
| 442 "HISTORY_DELETE_DIRECTIVE"; |
426 } // namespace | 443 } // namespace |
427 | 444 |
428 bool RealModelTypeToNotificationType(ModelType model_type, | 445 bool RealModelTypeToNotificationType(ModelType model_type, |
429 std::string* notification_type) { | 446 std::string* notification_type) { |
430 switch (model_type) { | 447 switch (model_type) { |
431 case BOOKMARKS: | 448 case BOOKMARKS: |
432 *notification_type = kBookmarkNotificationType; | 449 *notification_type = kBookmarkNotificationType; |
433 return true; | 450 return true; |
434 case PREFERENCES: | 451 case PREFERENCES: |
435 *notification_type = kPreferenceNotificationType; | 452 *notification_type = kPreferenceNotificationType; |
(...skipping 30 matching lines...) Expand all Loading... |
466 return true; | 483 return true; |
467 case AUTOFILL_PROFILE: | 484 case AUTOFILL_PROFILE: |
468 *notification_type = kAutofillProfileNotificationType; | 485 *notification_type = kAutofillProfileNotificationType; |
469 return true; | 486 return true; |
470 case EXTENSION_SETTINGS: | 487 case EXTENSION_SETTINGS: |
471 *notification_type = kExtensionSettingNotificationType; | 488 *notification_type = kExtensionSettingNotificationType; |
472 return true; | 489 return true; |
473 case APP_NOTIFICATIONS: | 490 case APP_NOTIFICATIONS: |
474 *notification_type = kAppNotificationNotificationType; | 491 *notification_type = kAppNotificationNotificationType; |
475 return true; | 492 return true; |
| 493 case HISTORY_DELETE_DIRECTIVES: |
| 494 *notification_type = kHistoryDeleteDirectiveNotificationType; |
| 495 return true; |
476 default: | 496 default: |
477 break; | 497 break; |
478 } | 498 } |
479 notification_type->clear(); | 499 notification_type->clear(); |
480 return false; | 500 return false; |
481 } | 501 } |
482 | 502 |
483 bool NotificationTypeToRealModelType(const std::string& notification_type, | 503 bool NotificationTypeToRealModelType(const std::string& notification_type, |
484 ModelType* model_type) { | 504 ModelType* model_type) { |
485 if (notification_type == kBookmarkNotificationType) { | 505 if (notification_type == kBookmarkNotificationType) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 return true; | 540 return true; |
521 } else if (notification_type == kAppSettingNotificationType) { | 541 } else if (notification_type == kAppSettingNotificationType) { |
522 *model_type = APP_SETTINGS; | 542 *model_type = APP_SETTINGS; |
523 return true; | 543 return true; |
524 } else if (notification_type == kExtensionSettingNotificationType) { | 544 } else if (notification_type == kExtensionSettingNotificationType) { |
525 *model_type = EXTENSION_SETTINGS; | 545 *model_type = EXTENSION_SETTINGS; |
526 return true; | 546 return true; |
527 } else if (notification_type == kAppNotificationNotificationType) { | 547 } else if (notification_type == kAppNotificationNotificationType) { |
528 *model_type = APP_NOTIFICATIONS; | 548 *model_type = APP_NOTIFICATIONS; |
529 return true; | 549 return true; |
| 550 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) { |
| 551 *model_type = HISTORY_DELETE_DIRECTIVES; |
| 552 return true; |
530 } else { | 553 } else { |
531 *model_type = UNSPECIFIED; | 554 *model_type = UNSPECIFIED; |
532 return false; | 555 return false; |
533 } | 556 } |
534 } | 557 } |
535 | 558 |
536 bool IsRealDataType(ModelType model_type) { | 559 bool IsRealDataType(ModelType model_type) { |
537 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; | 560 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; |
538 } | 561 } |
539 | 562 |
540 } // namespace syncer | 563 } // namespace syncer |
OLD | NEW |