| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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: | 76 case HISTORY_DELETE_DIRECTIVES: |
| 77 specifics->mutable_history_delete_directive(); | 77 specifics->mutable_history_delete_directive(); |
| 78 break; | 78 break; |
| 79 case SYNCED_NOTIFICATIONS: |
| 80 specifics->mutable_synced_notification(); |
| 81 break; |
| 79 case DEVICE_INFO: | 82 case DEVICE_INFO: |
| 80 specifics->mutable_device_info(); | 83 specifics->mutable_device_info(); |
| 81 break; | 84 break; |
| 82 case EXPERIMENTS: | 85 case EXPERIMENTS: |
| 83 specifics->mutable_experiments(); | 86 specifics->mutable_experiments(); |
| 84 break; | 87 break; |
| 85 default: | 88 default: |
| 86 NOTREACHED() << "No known extension for model type."; | 89 NOTREACHED() << "No known extension for model type."; |
| 87 } | 90 } |
| 88 } | 91 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 return sync_pb::EntitySpecifics::kAppSettingFieldNumber; | 141 return sync_pb::EntitySpecifics::kAppSettingFieldNumber; |
| 139 break; | 142 break; |
| 140 case EXTENSION_SETTINGS: | 143 case EXTENSION_SETTINGS: |
| 141 return sync_pb::EntitySpecifics::kExtensionSettingFieldNumber; | 144 return sync_pb::EntitySpecifics::kExtensionSettingFieldNumber; |
| 142 break; | 145 break; |
| 143 case APP_NOTIFICATIONS: | 146 case APP_NOTIFICATIONS: |
| 144 return sync_pb::EntitySpecifics::kAppNotificationFieldNumber; | 147 return sync_pb::EntitySpecifics::kAppNotificationFieldNumber; |
| 145 break; | 148 break; |
| 146 case HISTORY_DELETE_DIRECTIVES: | 149 case HISTORY_DELETE_DIRECTIVES: |
| 147 return sync_pb::EntitySpecifics::kHistoryDeleteDirectiveFieldNumber; | 150 return sync_pb::EntitySpecifics::kHistoryDeleteDirectiveFieldNumber; |
| 151 case SYNCED_NOTIFICATIONS: |
| 152 return sync_pb::EntitySpecifics::kSyncedNotificationFieldNumber; |
| 148 case DEVICE_INFO: | 153 case DEVICE_INFO: |
| 149 return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber; | 154 return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber; |
| 150 break; | 155 break; |
| 151 case EXPERIMENTS: | 156 case EXPERIMENTS: |
| 152 return sync_pb::EntitySpecifics::kExperimentsFieldNumber; | 157 return sync_pb::EntitySpecifics::kExperimentsFieldNumber; |
| 153 break; | 158 break; |
| 154 default: | 159 default: |
| 155 NOTREACHED() << "No known extension for model type."; | 160 NOTREACHED() << "No known extension for model type."; |
| 156 return 0; | 161 return 0; |
| 157 } | 162 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 244 |
| 240 if (specifics.has_extension_setting()) | 245 if (specifics.has_extension_setting()) |
| 241 return EXTENSION_SETTINGS; | 246 return EXTENSION_SETTINGS; |
| 242 | 247 |
| 243 if (specifics.has_app_notification()) | 248 if (specifics.has_app_notification()) |
| 244 return APP_NOTIFICATIONS; | 249 return APP_NOTIFICATIONS; |
| 245 | 250 |
| 246 if (specifics.has_history_delete_directive()) | 251 if (specifics.has_history_delete_directive()) |
| 247 return HISTORY_DELETE_DIRECTIVES; | 252 return HISTORY_DELETE_DIRECTIVES; |
| 248 | 253 |
| 254 if (specifics.has_synced_notification()) |
| 255 return SYNCED_NOTIFICATIONS; |
| 256 |
| 249 if (specifics.has_device_info()) | 257 if (specifics.has_device_info()) |
| 250 return DEVICE_INFO; | 258 return DEVICE_INFO; |
| 251 | 259 |
| 252 if (specifics.has_experiments()) | 260 if (specifics.has_experiments()) |
| 253 return EXPERIMENTS; | 261 return EXPERIMENTS; |
| 254 | 262 |
| 255 return UNSPECIFIED; | 263 return UNSPECIFIED; |
| 256 } | 264 } |
| 257 | 265 |
| 258 bool ShouldMaintainPosition(ModelType model_type) { | 266 bool ShouldMaintainPosition(ModelType model_type) { |
| 259 return model_type == BOOKMARKS; | 267 return model_type == BOOKMARKS; |
| 260 } | 268 } |
| 261 | 269 |
| 262 ModelTypeSet UserTypes() { | 270 ModelTypeSet UserTypes() { |
| 263 ModelTypeSet set; | 271 ModelTypeSet set; |
| 264 for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) { | 272 for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) { |
| 265 set.Put(ModelTypeFromInt(i)); | 273 set.Put(ModelTypeFromInt(i)); |
| 266 } | 274 } |
| 267 return set; | 275 return set; |
| 268 } | 276 } |
| 269 | 277 |
| 270 ModelTypeSet EncryptableUserTypes() { | 278 ModelTypeSet EncryptableUserTypes() { |
| 271 ModelTypeSet encryptable_user_types = UserTypes(); | 279 ModelTypeSet encryptable_user_types = UserTypes(); |
| 272 // We never encrypt history delete directives. | 280 // We never encrypt history delete directives. |
| 273 encryptable_user_types.Remove(HISTORY_DELETE_DIRECTIVES); | 281 encryptable_user_types.Remove(HISTORY_DELETE_DIRECTIVES); |
| 282 // Synced notifications are not encrypted since the server must see changes. |
| 283 encryptable_user_types.Remove(SYNCED_NOTIFICATIONS); |
| 274 return encryptable_user_types; | 284 return encryptable_user_types; |
| 275 } | 285 } |
| 276 | 286 |
| 277 ModelTypeSet ControlTypes() { | 287 ModelTypeSet ControlTypes() { |
| 278 ModelTypeSet set; | 288 ModelTypeSet set; |
| 279 for (int i = FIRST_CONTROL_MODEL_TYPE; i <= LAST_CONTROL_MODEL_TYPE; ++i) { | 289 for (int i = FIRST_CONTROL_MODEL_TYPE; i <= LAST_CONTROL_MODEL_TYPE; ++i) { |
| 280 set.Put(ModelTypeFromInt(i)); | 290 set.Put(ModelTypeFromInt(i)); |
| 281 } | 291 } |
| 282 | 292 |
| 283 return set; | 293 return set; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 case AUTOFILL_PROFILE: | 331 case AUTOFILL_PROFILE: |
| 322 return "Autofill Profiles"; | 332 return "Autofill Profiles"; |
| 323 case APP_SETTINGS: | 333 case APP_SETTINGS: |
| 324 return "App settings"; | 334 return "App settings"; |
| 325 case EXTENSION_SETTINGS: | 335 case EXTENSION_SETTINGS: |
| 326 return "Extension settings"; | 336 return "Extension settings"; |
| 327 case APP_NOTIFICATIONS: | 337 case APP_NOTIFICATIONS: |
| 328 return "App Notifications"; | 338 return "App Notifications"; |
| 329 case HISTORY_DELETE_DIRECTIVES: | 339 case HISTORY_DELETE_DIRECTIVES: |
| 330 return "History Delete Directives"; | 340 return "History Delete Directives"; |
| 341 case SYNCED_NOTIFICATIONS: |
| 342 return "Synced Notifications"; |
| 331 case DEVICE_INFO: | 343 case DEVICE_INFO: |
| 332 return "Device Info"; | 344 return "Device Info"; |
| 333 case EXPERIMENTS: | 345 case EXPERIMENTS: |
| 334 return "Experiments"; | 346 return "Experiments"; |
| 335 default: | 347 default: |
| 336 break; | 348 break; |
| 337 } | 349 } |
| 338 NOTREACHED() << "No known extension for model type."; | 350 NOTREACHED() << "No known extension for model type."; |
| 339 return "INVALID"; | 351 return "INVALID"; |
| 340 } | 352 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 else if (model_type_string == "Apps") | 404 else if (model_type_string == "Apps") |
| 393 return APPS; | 405 return APPS; |
| 394 else if (model_type_string == "App settings") | 406 else if (model_type_string == "App settings") |
| 395 return APP_SETTINGS; | 407 return APP_SETTINGS; |
| 396 else if (model_type_string == "Extension settings") | 408 else if (model_type_string == "Extension settings") |
| 397 return EXTENSION_SETTINGS; | 409 return EXTENSION_SETTINGS; |
| 398 else if (model_type_string == "App Notifications") | 410 else if (model_type_string == "App Notifications") |
| 399 return APP_NOTIFICATIONS; | 411 return APP_NOTIFICATIONS; |
| 400 else if (model_type_string == "History Delete Directives") | 412 else if (model_type_string == "History Delete Directives") |
| 401 return HISTORY_DELETE_DIRECTIVES; | 413 return HISTORY_DELETE_DIRECTIVES; |
| 414 else if (model_type_string == "Synced Notifications") |
| 415 return SYNCED_NOTIFICATIONS; |
| 402 else if (model_type_string == "Device Info") | 416 else if (model_type_string == "Device Info") |
| 403 return DEVICE_INFO; | 417 return DEVICE_INFO; |
| 404 else if (model_type_string == "Experiments") | 418 else if (model_type_string == "Experiments") |
| 405 return EXPERIMENTS; | 419 return EXPERIMENTS; |
| 406 else | 420 else |
| 407 NOTREACHED() << "No known model type corresponding to " | 421 NOTREACHED() << "No known model type corresponding to " |
| 408 << model_type_string << "."; | 422 << model_type_string << "."; |
| 409 return UNSPECIFIED; | 423 return UNSPECIFIED; |
| 410 } | 424 } |
| 411 | 425 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 case AUTOFILL_PROFILE: | 480 case AUTOFILL_PROFILE: |
| 467 return "google_chrome_autofill_profiles"; | 481 return "google_chrome_autofill_profiles"; |
| 468 case APP_SETTINGS: | 482 case APP_SETTINGS: |
| 469 return "google_chrome_app_settings"; | 483 return "google_chrome_app_settings"; |
| 470 case EXTENSION_SETTINGS: | 484 case EXTENSION_SETTINGS: |
| 471 return "google_chrome_extension_settings"; | 485 return "google_chrome_extension_settings"; |
| 472 case APP_NOTIFICATIONS: | 486 case APP_NOTIFICATIONS: |
| 473 return "google_chrome_app_notifications"; | 487 return "google_chrome_app_notifications"; |
| 474 case HISTORY_DELETE_DIRECTIVES: | 488 case HISTORY_DELETE_DIRECTIVES: |
| 475 return "google_chrome_history_delete_directives"; | 489 return "google_chrome_history_delete_directives"; |
| 490 case SYNCED_NOTIFICATIONS: |
| 491 return "google_chrome_synced_notifications"; |
| 476 case DEVICE_INFO: | 492 case DEVICE_INFO: |
| 477 return "google_chrome_device_info"; | 493 return "google_chrome_device_info"; |
| 478 case EXPERIMENTS: | 494 case EXPERIMENTS: |
| 479 return "google_chrome_experiments"; | 495 return "google_chrome_experiments"; |
| 480 default: | 496 default: |
| 481 break; | 497 break; |
| 482 } | 498 } |
| 483 NOTREACHED() << "No known extension for model type."; | 499 NOTREACHED() << "No known extension for model type."; |
| 484 return "INVALID"; | 500 return "INVALID"; |
| 485 } | 501 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 497 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; | 513 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; |
| 498 const char kNigoriNotificationType[] = "NIGORI"; | 514 const char kNigoriNotificationType[] = "NIGORI"; |
| 499 const char kAppSettingNotificationType[] = "APP_SETTING"; | 515 const char kAppSettingNotificationType[] = "APP_SETTING"; |
| 500 const char kAppNotificationType[] = "APP"; | 516 const char kAppNotificationType[] = "APP"; |
| 501 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; | 517 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; |
| 502 const char kSessionNotificationType[] = "SESSION"; | 518 const char kSessionNotificationType[] = "SESSION"; |
| 503 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; | 519 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; |
| 504 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; | 520 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; |
| 505 const char kHistoryDeleteDirectiveNotificationType[] = | 521 const char kHistoryDeleteDirectiveNotificationType[] = |
| 506 "HISTORY_DELETE_DIRECTIVE"; | 522 "HISTORY_DELETE_DIRECTIVE"; |
| 523 const char kSyncedNotificationType[] = "SYNCED_NOTIFICATION"; |
| 507 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; | 524 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; |
| 508 const char kExperimentsNotificationType[] = "EXPERIMENTS"; | 525 const char kExperimentsNotificationType[] = "EXPERIMENTS"; |
| 509 } // namespace | 526 } // namespace |
| 510 | 527 |
| 511 bool RealModelTypeToNotificationType(ModelType model_type, | 528 bool RealModelTypeToNotificationType(ModelType model_type, |
| 512 std::string* notification_type) { | 529 std::string* notification_type) { |
| 513 switch (model_type) { | 530 switch (model_type) { |
| 514 case BOOKMARKS: | 531 case BOOKMARKS: |
| 515 *notification_type = kBookmarkNotificationType; | 532 *notification_type = kBookmarkNotificationType; |
| 516 return true; | 533 return true; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 *notification_type = kAutofillProfileNotificationType; | 568 *notification_type = kAutofillProfileNotificationType; |
| 552 return true; | 569 return true; |
| 553 case EXTENSION_SETTINGS: | 570 case EXTENSION_SETTINGS: |
| 554 *notification_type = kExtensionSettingNotificationType; | 571 *notification_type = kExtensionSettingNotificationType; |
| 555 return true; | 572 return true; |
| 556 case APP_NOTIFICATIONS: | 573 case APP_NOTIFICATIONS: |
| 557 *notification_type = kAppNotificationNotificationType; | 574 *notification_type = kAppNotificationNotificationType; |
| 558 return true; | 575 return true; |
| 559 case HISTORY_DELETE_DIRECTIVES: | 576 case HISTORY_DELETE_DIRECTIVES: |
| 560 *notification_type = kHistoryDeleteDirectiveNotificationType; | 577 *notification_type = kHistoryDeleteDirectiveNotificationType; |
| 578 case SYNCED_NOTIFICATIONS: |
| 579 *notification_type = kSyncedNotificationType; |
| 561 case DEVICE_INFO: | 580 case DEVICE_INFO: |
| 562 *notification_type = kDeviceInfoNotificationType; | 581 *notification_type = kDeviceInfoNotificationType; |
| 563 return true; | 582 return true; |
| 564 case EXPERIMENTS: | 583 case EXPERIMENTS: |
| 565 *notification_type = kExperimentsNotificationType; | 584 *notification_type = kExperimentsNotificationType; |
| 566 return true; | 585 return true; |
| 567 default: | 586 default: |
| 568 break; | 587 break; |
| 569 } | 588 } |
| 570 notification_type->clear(); | 589 notification_type->clear(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 *model_type = APP_SETTINGS; | 632 *model_type = APP_SETTINGS; |
| 614 return true; | 633 return true; |
| 615 } else if (notification_type == kExtensionSettingNotificationType) { | 634 } else if (notification_type == kExtensionSettingNotificationType) { |
| 616 *model_type = EXTENSION_SETTINGS; | 635 *model_type = EXTENSION_SETTINGS; |
| 617 return true; | 636 return true; |
| 618 } else if (notification_type == kAppNotificationNotificationType) { | 637 } else if (notification_type == kAppNotificationNotificationType) { |
| 619 *model_type = APP_NOTIFICATIONS; | 638 *model_type = APP_NOTIFICATIONS; |
| 620 return true; | 639 return true; |
| 621 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) { | 640 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) { |
| 622 *model_type = HISTORY_DELETE_DIRECTIVES; | 641 *model_type = HISTORY_DELETE_DIRECTIVES; |
| 642 } else if (notification_type == kSyncedNotificationType) { |
| 643 *model_type = SYNCED_NOTIFICATIONS; |
| 623 } else if (notification_type == kDeviceInfoNotificationType) { | 644 } else if (notification_type == kDeviceInfoNotificationType) { |
| 624 *model_type = DEVICE_INFO;; | 645 *model_type = DEVICE_INFO;; |
| 625 return true; | 646 return true; |
| 626 } | 647 } |
| 627 *model_type = UNSPECIFIED; | 648 *model_type = UNSPECIFIED; |
| 628 return false; | 649 return false; |
| 629 } | 650 } |
| 630 | 651 |
| 631 bool IsRealDataType(ModelType model_type) { | 652 bool IsRealDataType(ModelType model_type) { |
| 632 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; | 653 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; |
| 633 } | 654 } |
| 634 | 655 |
| 635 } // namespace syncer | 656 } // namespace syncer |
| OLD | NEW |