| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 break; | 78 break; |
| 79 case SYNCED_NOTIFICATIONS: | 79 case SYNCED_NOTIFICATIONS: |
| 80 specifics->mutable_synced_notification(); | 80 specifics->mutable_synced_notification(); |
| 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 DICTIONARY: |
| 89 specifics->mutable_dictionary(); |
| 90 break; |
| 88 default: | 91 default: |
| 89 NOTREACHED() << "No known extension for model type."; | 92 NOTREACHED() << "No known extension for model type."; |
| 90 } | 93 } |
| 91 } | 94 } |
| 92 | 95 |
| 93 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { | 96 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { |
| 94 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 97 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
| 95 ModelType model_type = ModelTypeFromInt(i); | 98 ModelType model_type = ModelTypeFromInt(i); |
| 96 if (GetSpecificsFieldNumberFromModelType(model_type) == field_number) | 99 if (GetSpecificsFieldNumberFromModelType(model_type) == field_number) |
| 97 return model_type; | 100 return model_type; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 case HISTORY_DELETE_DIRECTIVES: | 152 case HISTORY_DELETE_DIRECTIVES: |
| 150 return sync_pb::EntitySpecifics::kHistoryDeleteDirectiveFieldNumber; | 153 return sync_pb::EntitySpecifics::kHistoryDeleteDirectiveFieldNumber; |
| 151 case SYNCED_NOTIFICATIONS: | 154 case SYNCED_NOTIFICATIONS: |
| 152 return sync_pb::EntitySpecifics::kSyncedNotificationFieldNumber; | 155 return sync_pb::EntitySpecifics::kSyncedNotificationFieldNumber; |
| 153 case DEVICE_INFO: | 156 case DEVICE_INFO: |
| 154 return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber; | 157 return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber; |
| 155 break; | 158 break; |
| 156 case EXPERIMENTS: | 159 case EXPERIMENTS: |
| 157 return sync_pb::EntitySpecifics::kExperimentsFieldNumber; | 160 return sync_pb::EntitySpecifics::kExperimentsFieldNumber; |
| 158 break; | 161 break; |
| 162 case DICTIONARY: |
| 163 return sync_pb::EntitySpecifics::kDictionaryFieldNumber; |
| 164 break; |
| 159 default: | 165 default: |
| 160 NOTREACHED() << "No known extension for model type."; | 166 NOTREACHED() << "No known extension for model type."; |
| 161 return 0; | 167 return 0; |
| 162 } | 168 } |
| 163 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of " | 169 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of " |
| 164 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681"; | 170 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681"; |
| 165 return 0; | 171 return 0; |
| 166 } | 172 } |
| 167 | 173 |
| 168 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in) { | 174 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 259 |
| 254 if (specifics.has_synced_notification()) | 260 if (specifics.has_synced_notification()) |
| 255 return SYNCED_NOTIFICATIONS; | 261 return SYNCED_NOTIFICATIONS; |
| 256 | 262 |
| 257 if (specifics.has_device_info()) | 263 if (specifics.has_device_info()) |
| 258 return DEVICE_INFO; | 264 return DEVICE_INFO; |
| 259 | 265 |
| 260 if (specifics.has_experiments()) | 266 if (specifics.has_experiments()) |
| 261 return EXPERIMENTS; | 267 return EXPERIMENTS; |
| 262 | 268 |
| 269 if (specifics.has_dictionary()) |
| 270 return DICTIONARY; |
| 271 |
| 263 return UNSPECIFIED; | 272 return UNSPECIFIED; |
| 264 } | 273 } |
| 265 | 274 |
| 266 bool ShouldMaintainPosition(ModelType model_type) { | 275 bool ShouldMaintainPosition(ModelType model_type) { |
| 267 return model_type == BOOKMARKS; | 276 return model_type == BOOKMARKS; |
| 268 } | 277 } |
| 269 | 278 |
| 270 ModelTypeSet UserTypes() { | 279 ModelTypeSet UserTypes() { |
| 271 ModelTypeSet set; | 280 ModelTypeSet set; |
| 272 for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) { | 281 for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 case APP_NOTIFICATIONS: | 346 case APP_NOTIFICATIONS: |
| 338 return "App Notifications"; | 347 return "App Notifications"; |
| 339 case HISTORY_DELETE_DIRECTIVES: | 348 case HISTORY_DELETE_DIRECTIVES: |
| 340 return "History Delete Directives"; | 349 return "History Delete Directives"; |
| 341 case SYNCED_NOTIFICATIONS: | 350 case SYNCED_NOTIFICATIONS: |
| 342 return "Synced Notifications"; | 351 return "Synced Notifications"; |
| 343 case DEVICE_INFO: | 352 case DEVICE_INFO: |
| 344 return "Device Info"; | 353 return "Device Info"; |
| 345 case EXPERIMENTS: | 354 case EXPERIMENTS: |
| 346 return "Experiments"; | 355 return "Experiments"; |
| 356 case DICTIONARY: |
| 357 return "Dictionary"; |
| 347 default: | 358 default: |
| 348 break; | 359 break; |
| 349 } | 360 } |
| 350 NOTREACHED() << "No known extension for model type."; | 361 NOTREACHED() << "No known extension for model type."; |
| 351 return "INVALID"; | 362 return "INVALID"; |
| 352 } | 363 } |
| 353 | 364 |
| 354 StringValue* ModelTypeToValue(ModelType model_type) { | 365 StringValue* ModelTypeToValue(ModelType model_type) { |
| 355 if (model_type >= FIRST_REAL_MODEL_TYPE) { | 366 if (model_type >= FIRST_REAL_MODEL_TYPE) { |
| 356 return Value::CreateStringValue(ModelTypeToString(model_type)); | 367 return Value::CreateStringValue(ModelTypeToString(model_type)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 else if (model_type_string == "App Notifications") | 421 else if (model_type_string == "App Notifications") |
| 411 return APP_NOTIFICATIONS; | 422 return APP_NOTIFICATIONS; |
| 412 else if (model_type_string == "History Delete Directives") | 423 else if (model_type_string == "History Delete Directives") |
| 413 return HISTORY_DELETE_DIRECTIVES; | 424 return HISTORY_DELETE_DIRECTIVES; |
| 414 else if (model_type_string == "Synced Notifications") | 425 else if (model_type_string == "Synced Notifications") |
| 415 return SYNCED_NOTIFICATIONS; | 426 return SYNCED_NOTIFICATIONS; |
| 416 else if (model_type_string == "Device Info") | 427 else if (model_type_string == "Device Info") |
| 417 return DEVICE_INFO; | 428 return DEVICE_INFO; |
| 418 else if (model_type_string == "Experiments") | 429 else if (model_type_string == "Experiments") |
| 419 return EXPERIMENTS; | 430 return EXPERIMENTS; |
| 431 else if (model_type_string == "Dictionary") |
| 432 return DICTIONARY; |
| 420 else | 433 else |
| 421 NOTREACHED() << "No known model type corresponding to " | 434 NOTREACHED() << "No known model type corresponding to " |
| 422 << model_type_string << "."; | 435 << model_type_string << "."; |
| 423 return UNSPECIFIED; | 436 return UNSPECIFIED; |
| 424 } | 437 } |
| 425 | 438 |
| 426 std::string ModelTypeSetToString(ModelTypeSet model_types) { | 439 std::string ModelTypeSetToString(ModelTypeSet model_types) { |
| 427 std::string result; | 440 std::string result; |
| 428 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { | 441 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { |
| 429 if (!result.empty()) { | 442 if (!result.empty()) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 case APP_NOTIFICATIONS: | 499 case APP_NOTIFICATIONS: |
| 487 return "google_chrome_app_notifications"; | 500 return "google_chrome_app_notifications"; |
| 488 case HISTORY_DELETE_DIRECTIVES: | 501 case HISTORY_DELETE_DIRECTIVES: |
| 489 return "google_chrome_history_delete_directives"; | 502 return "google_chrome_history_delete_directives"; |
| 490 case SYNCED_NOTIFICATIONS: | 503 case SYNCED_NOTIFICATIONS: |
| 491 return "google_chrome_synced_notifications"; | 504 return "google_chrome_synced_notifications"; |
| 492 case DEVICE_INFO: | 505 case DEVICE_INFO: |
| 493 return "google_chrome_device_info"; | 506 return "google_chrome_device_info"; |
| 494 case EXPERIMENTS: | 507 case EXPERIMENTS: |
| 495 return "google_chrome_experiments"; | 508 return "google_chrome_experiments"; |
| 509 case DICTIONARY: |
| 510 return "google_chrome_dictionary"; |
| 496 default: | 511 default: |
| 497 break; | 512 break; |
| 498 } | 513 } |
| 499 NOTREACHED() << "No known extension for model type."; | 514 NOTREACHED() << "No known extension for model type."; |
| 500 return "INVALID"; | 515 return "INVALID"; |
| 501 } | 516 } |
| 502 | 517 |
| 503 // TODO(akalin): Figure out a better way to do these mappings. | 518 // TODO(akalin): Figure out a better way to do these mappings. |
| 504 | 519 |
| 505 namespace { | 520 namespace { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 516 const char kAppNotificationType[] = "APP"; | 531 const char kAppNotificationType[] = "APP"; |
| 517 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; | 532 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; |
| 518 const char kSessionNotificationType[] = "SESSION"; | 533 const char kSessionNotificationType[] = "SESSION"; |
| 519 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; | 534 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; |
| 520 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; | 535 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; |
| 521 const char kHistoryDeleteDirectiveNotificationType[] = | 536 const char kHistoryDeleteDirectiveNotificationType[] = |
| 522 "HISTORY_DELETE_DIRECTIVE"; | 537 "HISTORY_DELETE_DIRECTIVE"; |
| 523 const char kSyncedNotificationType[] = "SYNCED_NOTIFICATION"; | 538 const char kSyncedNotificationType[] = "SYNCED_NOTIFICATION"; |
| 524 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; | 539 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; |
| 525 const char kExperimentsNotificationType[] = "EXPERIMENTS"; | 540 const char kExperimentsNotificationType[] = "EXPERIMENTS"; |
| 541 const char kDictionaryNotificationType[] = "DICTIONARY"; |
| 526 } // namespace | 542 } // namespace |
| 527 | 543 |
| 528 bool RealModelTypeToNotificationType(ModelType model_type, | 544 bool RealModelTypeToNotificationType(ModelType model_type, |
| 529 std::string* notification_type) { | 545 std::string* notification_type) { |
| 530 switch (model_type) { | 546 switch (model_type) { |
| 531 case BOOKMARKS: | 547 case BOOKMARKS: |
| 532 *notification_type = kBookmarkNotificationType; | 548 *notification_type = kBookmarkNotificationType; |
| 533 return true; | 549 return true; |
| 534 case PREFERENCES: | 550 case PREFERENCES: |
| 535 *notification_type = kPreferenceNotificationType; | 551 *notification_type = kPreferenceNotificationType; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 case HISTORY_DELETE_DIRECTIVES: | 592 case HISTORY_DELETE_DIRECTIVES: |
| 577 *notification_type = kHistoryDeleteDirectiveNotificationType; | 593 *notification_type = kHistoryDeleteDirectiveNotificationType; |
| 578 case SYNCED_NOTIFICATIONS: | 594 case SYNCED_NOTIFICATIONS: |
| 579 *notification_type = kSyncedNotificationType; | 595 *notification_type = kSyncedNotificationType; |
| 580 case DEVICE_INFO: | 596 case DEVICE_INFO: |
| 581 *notification_type = kDeviceInfoNotificationType; | 597 *notification_type = kDeviceInfoNotificationType; |
| 582 return true; | 598 return true; |
| 583 case EXPERIMENTS: | 599 case EXPERIMENTS: |
| 584 *notification_type = kExperimentsNotificationType; | 600 *notification_type = kExperimentsNotificationType; |
| 585 return true; | 601 return true; |
| 602 case DICTIONARY: |
| 603 *notification_type = kDictionaryNotificationType; |
| 604 return true; |
| 586 default: | 605 default: |
| 587 break; | 606 break; |
| 588 } | 607 } |
| 589 notification_type->clear(); | 608 notification_type->clear(); |
| 590 return false; | 609 return false; |
| 591 } | 610 } |
| 592 | 611 |
| 593 bool NotificationTypeToRealModelType(const std::string& notification_type, | 612 bool NotificationTypeToRealModelType(const std::string& notification_type, |
| 594 ModelType* model_type) { | 613 ModelType* model_type) { |
| 595 if (notification_type == kBookmarkNotificationType) { | 614 if (notification_type == kBookmarkNotificationType) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 } else if (notification_type == kAppNotificationNotificationType) { | 656 } else if (notification_type == kAppNotificationNotificationType) { |
| 638 *model_type = APP_NOTIFICATIONS; | 657 *model_type = APP_NOTIFICATIONS; |
| 639 return true; | 658 return true; |
| 640 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) { | 659 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) { |
| 641 *model_type = HISTORY_DELETE_DIRECTIVES; | 660 *model_type = HISTORY_DELETE_DIRECTIVES; |
| 642 } else if (notification_type == kSyncedNotificationType) { | 661 } else if (notification_type == kSyncedNotificationType) { |
| 643 *model_type = SYNCED_NOTIFICATIONS; | 662 *model_type = SYNCED_NOTIFICATIONS; |
| 644 } else if (notification_type == kDeviceInfoNotificationType) { | 663 } else if (notification_type == kDeviceInfoNotificationType) { |
| 645 *model_type = DEVICE_INFO;; | 664 *model_type = DEVICE_INFO;; |
| 646 return true; | 665 return true; |
| 666 } else if (notification_type == kDictionaryNotificationType) { |
| 667 *model_type = DICTIONARY; |
| 668 return true; |
| 647 } | 669 } |
| 648 *model_type = UNSPECIFIED; | 670 *model_type = UNSPECIFIED; |
| 649 return false; | 671 return false; |
| 650 } | 672 } |
| 651 | 673 |
| 652 bool IsRealDataType(ModelType model_type) { | 674 bool IsRealDataType(ModelType model_type) { |
| 653 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; | 675 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; |
| 654 } | 676 } |
| 655 | 677 |
| 656 } // namespace syncer | 678 } // namespace syncer |
| OLD | NEW |