| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 break; | 81 break; |
| 82 case DEVICE_INFO: | 82 case DEVICE_INFO: |
| 83 specifics->mutable_device_info(); | 83 specifics->mutable_device_info(); |
| 84 break; | 84 break; |
| 85 case EXPERIMENTS: | 85 case EXPERIMENTS: |
| 86 specifics->mutable_experiments(); | 86 specifics->mutable_experiments(); |
| 87 break; | 87 break; |
| 88 case PRIORITY_PREFERENCES: | 88 case PRIORITY_PREFERENCES: |
| 89 specifics->mutable_priority_preference(); | 89 specifics->mutable_priority_preference(); |
| 90 break; | 90 break; |
| 91 case TABS: |
| 92 break; |
| 91 default: | 93 default: |
| 92 NOTREACHED() << "No known extension for model type."; | 94 NOTREACHED() << "No known extension for model type."; |
| 93 } | 95 } |
| 94 } | 96 } |
| 95 | 97 |
| 96 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { | 98 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { |
| 97 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 99 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
| 98 ModelType model_type = ModelTypeFromInt(i); | 100 ModelType model_type = ModelTypeFromInt(i); |
| 99 if (GetSpecificsFieldNumberFromModelType(model_type) == field_number) | 101 if (GetSpecificsFieldNumberFromModelType(model_type) == field_number) |
| 100 return model_type; | 102 return model_type; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 return sync_pb::EntitySpecifics::kSyncedNotificationFieldNumber; | 157 return sync_pb::EntitySpecifics::kSyncedNotificationFieldNumber; |
| 156 case DEVICE_INFO: | 158 case DEVICE_INFO: |
| 157 return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber; | 159 return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber; |
| 158 break; | 160 break; |
| 159 case EXPERIMENTS: | 161 case EXPERIMENTS: |
| 160 return sync_pb::EntitySpecifics::kExperimentsFieldNumber; | 162 return sync_pb::EntitySpecifics::kExperimentsFieldNumber; |
| 161 break; | 163 break; |
| 162 case PRIORITY_PREFERENCES: | 164 case PRIORITY_PREFERENCES: |
| 163 return sync_pb::EntitySpecifics::kPriorityPreferenceFieldNumber; | 165 return sync_pb::EntitySpecifics::kPriorityPreferenceFieldNumber; |
| 164 break; | 166 break; |
| 167 case TABS: |
| 168 return sync_pb::EntitySpecifics::kTabFieldNumber; |
| 165 default: | 169 default: |
| 166 NOTREACHED() << "No known extension for model type."; | 170 NOTREACHED() << "No known extension for model type."; |
| 167 return 0; | 171 return 0; |
| 168 } | 172 } |
| 169 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of " | 173 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of " |
| 170 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681"; | 174 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681"; |
| 171 return 0; | 175 return 0; |
| 172 } | 176 } |
| 173 | 177 |
| 174 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in) { | 178 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 } | 304 } |
| 301 | 305 |
| 302 // TODO(albertb): Re-enable this when the server supports it. | 306 // TODO(albertb): Re-enable this when the server supports it. |
| 303 set.Remove(PRIORITY_PREFERENCES); | 307 set.Remove(PRIORITY_PREFERENCES); |
| 304 | 308 |
| 305 return set; | 309 return set; |
| 306 } | 310 } |
| 307 | 311 |
| 308 ModelTypeSet VirtualTypes() { | 312 ModelTypeSet VirtualTypes() { |
| 309 ModelTypeSet set; | 313 ModelTypeSet set; |
| 310 // TODO(zea): add a TABS type here. | 314 set.Put(TABS); |
| 311 return set; | 315 return set; |
| 312 } | 316 } |
| 313 | 317 |
| 314 bool IsControlType(ModelType model_type) { | 318 bool IsControlType(ModelType model_type) { |
| 315 return ControlTypes().Has(model_type); | 319 return ControlTypes().Has(model_type); |
| 316 } | 320 } |
| 317 | 321 |
| 318 const char* ModelTypeToString(ModelType model_type) { | 322 const char* ModelTypeToString(ModelType model_type) { |
| 319 // This is used in serialization routines as well as for displaying debug | 323 // This is used in serialization routines as well as for displaying debug |
| 320 // information. Do not attempt to change these string values unless you know | 324 // information. Do not attempt to change these string values unless you know |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 case HISTORY_DELETE_DIRECTIVES: | 361 case HISTORY_DELETE_DIRECTIVES: |
| 358 return "History Delete Directives"; | 362 return "History Delete Directives"; |
| 359 case SYNCED_NOTIFICATIONS: | 363 case SYNCED_NOTIFICATIONS: |
| 360 return "Synced Notifications"; | 364 return "Synced Notifications"; |
| 361 case DEVICE_INFO: | 365 case DEVICE_INFO: |
| 362 return "Device Info"; | 366 return "Device Info"; |
| 363 case EXPERIMENTS: | 367 case EXPERIMENTS: |
| 364 return "Experiments"; | 368 return "Experiments"; |
| 365 case PRIORITY_PREFERENCES: | 369 case PRIORITY_PREFERENCES: |
| 366 return "Priority Preferences"; | 370 return "Priority Preferences"; |
| 371 case TABS: |
| 372 return "Tabs"; |
| 367 default: | 373 default: |
| 368 break; | 374 break; |
| 369 } | 375 } |
| 370 NOTREACHED() << "No known extension for model type."; | 376 NOTREACHED() << "No known extension for model type."; |
| 371 return "INVALID"; | 377 return "INVALID"; |
| 372 } | 378 } |
| 373 | 379 |
| 374 StringValue* ModelTypeToValue(ModelType model_type) { | 380 StringValue* ModelTypeToValue(ModelType model_type) { |
| 375 if (model_type >= FIRST_REAL_MODEL_TYPE) { | 381 if (model_type >= FIRST_REAL_MODEL_TYPE) { |
| 376 return Value::CreateStringValue(ModelTypeToString(model_type)); | 382 return Value::CreateStringValue(ModelTypeToString(model_type)); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 else if (model_type_string == "History Delete Directives") | 438 else if (model_type_string == "History Delete Directives") |
| 433 return HISTORY_DELETE_DIRECTIVES; | 439 return HISTORY_DELETE_DIRECTIVES; |
| 434 else if (model_type_string == "Synced Notifications") | 440 else if (model_type_string == "Synced Notifications") |
| 435 return SYNCED_NOTIFICATIONS; | 441 return SYNCED_NOTIFICATIONS; |
| 436 else if (model_type_string == "Device Info") | 442 else if (model_type_string == "Device Info") |
| 437 return DEVICE_INFO; | 443 return DEVICE_INFO; |
| 438 else if (model_type_string == "Experiments") | 444 else if (model_type_string == "Experiments") |
| 439 return EXPERIMENTS; | 445 return EXPERIMENTS; |
| 440 else if (model_type_string == "Priority Preferences") | 446 else if (model_type_string == "Priority Preferences") |
| 441 return PRIORITY_PREFERENCES; | 447 return PRIORITY_PREFERENCES; |
| 448 else if (model_type_string == "Tabs") |
| 449 return TABS; |
| 442 else | 450 else |
| 443 NOTREACHED() << "No known model type corresponding to " | 451 NOTREACHED() << "No known model type corresponding to " |
| 444 << model_type_string << "."; | 452 << model_type_string << "."; |
| 445 return UNSPECIFIED; | 453 return UNSPECIFIED; |
| 446 } | 454 } |
| 447 | 455 |
| 448 std::string ModelTypeSetToString(ModelTypeSet model_types) { | 456 std::string ModelTypeSetToString(ModelTypeSet model_types) { |
| 449 std::string result; | 457 std::string result; |
| 450 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { | 458 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { |
| 451 if (!result.empty()) { | 459 if (!result.empty()) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 case HISTORY_DELETE_DIRECTIVES: | 518 case HISTORY_DELETE_DIRECTIVES: |
| 511 return "google_chrome_history_delete_directives"; | 519 return "google_chrome_history_delete_directives"; |
| 512 case SYNCED_NOTIFICATIONS: | 520 case SYNCED_NOTIFICATIONS: |
| 513 return "google_chrome_synced_notifications"; | 521 return "google_chrome_synced_notifications"; |
| 514 case DEVICE_INFO: | 522 case DEVICE_INFO: |
| 515 return "google_chrome_device_info"; | 523 return "google_chrome_device_info"; |
| 516 case EXPERIMENTS: | 524 case EXPERIMENTS: |
| 517 return "google_chrome_experiments"; | 525 return "google_chrome_experiments"; |
| 518 case PRIORITY_PREFERENCES: | 526 case PRIORITY_PREFERENCES: |
| 519 return "google_chrome_priority_preferences"; | 527 return "google_chrome_priority_preferences"; |
| 528 case TABS: |
| 529 return ""; |
| 520 default: | 530 default: |
| 521 break; | 531 break; |
| 522 } | 532 } |
| 523 NOTREACHED() << "No known extension for model type."; | 533 NOTREACHED() << "No known extension for model type."; |
| 524 return "INVALID"; | 534 return "INVALID"; |
| 525 } | 535 } |
| 526 | 536 |
| 527 // TODO(akalin): Figure out a better way to do these mappings. | 537 // TODO(akalin): Figure out a better way to do these mappings. |
| 528 | 538 |
| 529 namespace { | 539 namespace { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 541 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; | 551 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; |
| 542 const char kSessionNotificationType[] = "SESSION"; | 552 const char kSessionNotificationType[] = "SESSION"; |
| 543 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; | 553 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; |
| 544 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; | 554 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; |
| 545 const char kHistoryDeleteDirectiveNotificationType[] = | 555 const char kHistoryDeleteDirectiveNotificationType[] = |
| 546 "HISTORY_DELETE_DIRECTIVE"; | 556 "HISTORY_DELETE_DIRECTIVE"; |
| 547 const char kSyncedNotificationType[] = "SYNCED_NOTIFICATION"; | 557 const char kSyncedNotificationType[] = "SYNCED_NOTIFICATION"; |
| 548 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; | 558 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; |
| 549 const char kExperimentsNotificationType[] = "EXPERIMENTS"; | 559 const char kExperimentsNotificationType[] = "EXPERIMENTS"; |
| 550 const char kPriorityPreferenceNotificationType[] = "PRIORITY_PREFERENCE"; | 560 const char kPriorityPreferenceNotificationType[] = "PRIORITY_PREFERENCE"; |
| 561 const char kTabNotificationType[] = "TAB"; |
| 551 } // namespace | 562 } // namespace |
| 552 | 563 |
| 553 bool RealModelTypeToNotificationType(ModelType model_type, | 564 bool RealModelTypeToNotificationType(ModelType model_type, |
| 554 std::string* notification_type) { | 565 std::string* notification_type) { |
| 555 switch (model_type) { | 566 switch (model_type) { |
| 556 case BOOKMARKS: | 567 case BOOKMARKS: |
| 557 *notification_type = kBookmarkNotificationType; | 568 *notification_type = kBookmarkNotificationType; |
| 558 return true; | 569 return true; |
| 559 case PREFERENCES: | 570 case PREFERENCES: |
| 560 *notification_type = kPreferenceNotificationType; | 571 *notification_type = kPreferenceNotificationType; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 case SYNCED_NOTIFICATIONS: | 614 case SYNCED_NOTIFICATIONS: |
| 604 *notification_type = kSyncedNotificationType; | 615 *notification_type = kSyncedNotificationType; |
| 605 case DEVICE_INFO: | 616 case DEVICE_INFO: |
| 606 *notification_type = kDeviceInfoNotificationType; | 617 *notification_type = kDeviceInfoNotificationType; |
| 607 return true; | 618 return true; |
| 608 case EXPERIMENTS: | 619 case EXPERIMENTS: |
| 609 *notification_type = kExperimentsNotificationType; | 620 *notification_type = kExperimentsNotificationType; |
| 610 return true; | 621 return true; |
| 611 case PRIORITY_PREFERENCES: | 622 case PRIORITY_PREFERENCES: |
| 612 *notification_type = kPriorityPreferenceNotificationType; | 623 *notification_type = kPriorityPreferenceNotificationType; |
| 624 return true; |
| 625 case TABS: |
| 626 *notification_type = kTabNotificationType; |
| 627 return true; |
| 613 default: | 628 default: |
| 614 break; | 629 break; |
| 615 } | 630 } |
| 616 notification_type->clear(); | 631 notification_type->clear(); |
| 617 return false; | 632 return false; |
| 618 } | 633 } |
| 619 | 634 |
| 620 bool NotificationTypeToRealModelType(const std::string& notification_type, | 635 bool NotificationTypeToRealModelType(const std::string& notification_type, |
| 621 ModelType* model_type) { | 636 ModelType* model_type) { |
| 622 if (notification_type == kBookmarkNotificationType) { | 637 if (notification_type == kBookmarkNotificationType) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 } else if (notification_type == kAppNotificationNotificationType) { | 679 } else if (notification_type == kAppNotificationNotificationType) { |
| 665 *model_type = APP_NOTIFICATIONS; | 680 *model_type = APP_NOTIFICATIONS; |
| 666 return true; | 681 return true; |
| 667 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) { | 682 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) { |
| 668 *model_type = HISTORY_DELETE_DIRECTIVES; | 683 *model_type = HISTORY_DELETE_DIRECTIVES; |
| 669 } else if (notification_type == kSyncedNotificationType) { | 684 } else if (notification_type == kSyncedNotificationType) { |
| 670 *model_type = SYNCED_NOTIFICATIONS; | 685 *model_type = SYNCED_NOTIFICATIONS; |
| 671 } else if (notification_type == kDeviceInfoNotificationType) { | 686 } else if (notification_type == kDeviceInfoNotificationType) { |
| 672 *model_type = DEVICE_INFO;; | 687 *model_type = DEVICE_INFO;; |
| 673 return true; | 688 return true; |
| 689 } else if (notification_type == kExperimentsNotificationType) { |
| 690 *model_type = EXPERIMENTS; |
| 691 return true; |
| 674 } else if (notification_type == kPriorityPreferenceNotificationType) { | 692 } else if (notification_type == kPriorityPreferenceNotificationType) { |
| 675 *model_type = PRIORITY_PREFERENCES; | 693 *model_type = PRIORITY_PREFERENCES; |
| 676 return true; | 694 return true; |
| 695 } else if (notification_type == kTabNotificationType) { |
| 696 *model_type = TABS; |
| 697 return true; |
| 677 } | 698 } |
| 678 *model_type = UNSPECIFIED; | 699 *model_type = UNSPECIFIED; |
| 679 return false; | 700 return false; |
| 680 } | 701 } |
| 681 | 702 |
| 682 bool IsRealDataType(ModelType model_type) { | 703 bool IsRealDataType(ModelType model_type) { |
| 683 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; | 704 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; |
| 684 } | 705 } |
| 685 | 706 |
| 686 } // namespace syncer | 707 } // namespace syncer |
| OLD | NEW |