| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 DEVICE_INFO: | 79 case DEVICE_INFO: |
| 80 specifics->mutable_device_info(); | 80 specifics->mutable_device_info(); |
| 81 break; | 81 break; |
| 82 case EXPERIMENTS: | 82 case EXPERIMENTS: |
| 83 specifics->mutable_experiments(); | 83 specifics->mutable_experiments(); |
| 84 break; | 84 break; |
| 85 case CONTROL_PREFERENCES: |
| 86 specifics->mutable_control_preference(); |
| 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 } |
| 89 | 92 |
| 90 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { | 93 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { |
| 91 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 94 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
| 92 ModelType model_type = ModelTypeFromInt(i); | 95 ModelType model_type = ModelTypeFromInt(i); |
| 93 if (GetSpecificsFieldNumberFromModelType(model_type) == field_number) | 96 if (GetSpecificsFieldNumberFromModelType(model_type) == field_number) |
| 94 return model_type; | 97 return model_type; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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; |
| 148 case DEVICE_INFO: | 151 case DEVICE_INFO: |
| 149 return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber; | 152 return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber; |
| 150 break; | 153 break; |
| 151 case EXPERIMENTS: | 154 case EXPERIMENTS: |
| 152 return sync_pb::EntitySpecifics::kExperimentsFieldNumber; | 155 return sync_pb::EntitySpecifics::kExperimentsFieldNumber; |
| 153 break; | 156 break; |
| 157 case CONTROL_PREFERENCES: |
| 158 return sync_pb::EntitySpecifics::kControlPreferenceFieldNumber; |
| 159 break; |
| 154 default: | 160 default: |
| 155 NOTREACHED() << "No known extension for model type."; | 161 NOTREACHED() << "No known extension for model type."; |
| 156 return 0; | 162 return 0; |
| 157 } | 163 } |
| 158 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of " | 164 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of " |
| 159 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681"; | 165 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681"; |
| 160 return 0; | 166 return 0; |
| 161 } | 167 } |
| 162 | 168 |
| 163 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in) { | 169 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 | 251 |
| 246 if (specifics.has_history_delete_directive()) | 252 if (specifics.has_history_delete_directive()) |
| 247 return HISTORY_DELETE_DIRECTIVES; | 253 return HISTORY_DELETE_DIRECTIVES; |
| 248 | 254 |
| 249 if (specifics.has_device_info()) | 255 if (specifics.has_device_info()) |
| 250 return DEVICE_INFO; | 256 return DEVICE_INFO; |
| 251 | 257 |
| 252 if (specifics.has_experiments()) | 258 if (specifics.has_experiments()) |
| 253 return EXPERIMENTS; | 259 return EXPERIMENTS; |
| 254 | 260 |
| 261 if (specifics.has_control_preference()) |
| 262 return CONTROL_PREFERENCES; |
| 263 |
| 255 return UNSPECIFIED; | 264 return UNSPECIFIED; |
| 256 } | 265 } |
| 257 | 266 |
| 258 bool ShouldMaintainPosition(ModelType model_type) { | 267 bool ShouldMaintainPosition(ModelType model_type) { |
| 259 return model_type == BOOKMARKS; | 268 return model_type == BOOKMARKS; |
| 260 } | 269 } |
| 261 | 270 |
| 262 ModelTypeSet UserTypes() { | 271 ModelTypeSet UserTypes() { |
| 263 ModelTypeSet set; | 272 ModelTypeSet set; |
| 264 for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) { | 273 for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) { |
| 265 set.Put(ModelTypeFromInt(i)); | 274 set.Put(ModelTypeFromInt(i)); |
| 266 } | 275 } |
| 267 return set; | 276 return set; |
| 268 } | 277 } |
| 269 | 278 |
| 270 ModelTypeSet EncryptableUserTypes() { | 279 ModelTypeSet EncryptableUserTypes() { |
| 271 ModelTypeSet encryptable_user_types = UserTypes(); | 280 ModelTypeSet encryptable_user_types = UserTypes(); |
| 272 // We never encrypt history delete directives. | 281 // We never encrypt history delete directives. |
| 273 encryptable_user_types.Remove(HISTORY_DELETE_DIRECTIVES); | 282 encryptable_user_types.Remove(HISTORY_DELETE_DIRECTIVES); |
| 274 return encryptable_user_types; | 283 return encryptable_user_types; |
| 275 } | 284 } |
| 276 | 285 |
| 277 ModelTypeSet ControlTypes() { | 286 ModelTypeSet ControlTypes() { |
| 278 ModelTypeSet set; | 287 ModelTypeSet set; |
| 279 for (int i = FIRST_CONTROL_MODEL_TYPE; i <= LAST_CONTROL_MODEL_TYPE; ++i) { | 288 for (int i = FIRST_CONTROL_MODEL_TYPE; i <= LAST_CONTROL_MODEL_TYPE; ++i) { |
| 280 set.Put(ModelTypeFromInt(i)); | 289 set.Put(ModelTypeFromInt(i)); |
| 281 } | 290 } |
| 282 | 291 |
| 292 // TODO(albertb): Re-enable this when the server supports it. |
| 293 set.Remove(CONTROL_PREFERENCES); |
| 294 |
| 283 return set; | 295 return set; |
| 284 } | 296 } |
| 285 | 297 |
| 286 bool IsControlType(ModelType model_type) { | 298 bool IsControlType(ModelType model_type) { |
| 287 return ControlTypes().Has(model_type); | 299 return ControlTypes().Has(model_type); |
| 288 } | 300 } |
| 289 | 301 |
| 290 const char* ModelTypeToString(ModelType model_type) { | 302 const char* ModelTypeToString(ModelType model_type) { |
| 291 // This is used in serialization routines as well as for displaying debug | 303 // This is used in serialization routines as well as for displaying debug |
| 292 // information. Do not attempt to change these string values unless you know | 304 // information. Do not attempt to change these string values unless you know |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 case EXTENSION_SETTINGS: | 337 case EXTENSION_SETTINGS: |
| 326 return "Extension settings"; | 338 return "Extension settings"; |
| 327 case APP_NOTIFICATIONS: | 339 case APP_NOTIFICATIONS: |
| 328 return "App Notifications"; | 340 return "App Notifications"; |
| 329 case HISTORY_DELETE_DIRECTIVES: | 341 case HISTORY_DELETE_DIRECTIVES: |
| 330 return "History Delete Directives"; | 342 return "History Delete Directives"; |
| 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"; |
| 347 case CONTROL_PREFERENCES: |
| 348 return "Control Preferences"; |
| 335 default: | 349 default: |
| 336 break; | 350 break; |
| 337 } | 351 } |
| 338 NOTREACHED() << "No known extension for model type."; | 352 NOTREACHED() << "No known extension for model type."; |
| 339 return "INVALID"; | 353 return "INVALID"; |
| 340 } | 354 } |
| 341 | 355 |
| 342 StringValue* ModelTypeToValue(ModelType model_type) { | 356 StringValue* ModelTypeToValue(ModelType model_type) { |
| 343 if (model_type >= FIRST_REAL_MODEL_TYPE) { | 357 if (model_type >= FIRST_REAL_MODEL_TYPE) { |
| 344 return Value::CreateStringValue(ModelTypeToString(model_type)); | 358 return Value::CreateStringValue(ModelTypeToString(model_type)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 else if (model_type_string == "Extension settings") | 410 else if (model_type_string == "Extension settings") |
| 397 return EXTENSION_SETTINGS; | 411 return EXTENSION_SETTINGS; |
| 398 else if (model_type_string == "App Notifications") | 412 else if (model_type_string == "App Notifications") |
| 399 return APP_NOTIFICATIONS; | 413 return APP_NOTIFICATIONS; |
| 400 else if (model_type_string == "History Delete Directives") | 414 else if (model_type_string == "History Delete Directives") |
| 401 return HISTORY_DELETE_DIRECTIVES; | 415 return HISTORY_DELETE_DIRECTIVES; |
| 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; |
| 420 else if (model_type_string == "Control Preferences") |
| 421 return CONTROL_PREFERENCES; |
| 406 else | 422 else |
| 407 NOTREACHED() << "No known model type corresponding to " | 423 NOTREACHED() << "No known model type corresponding to " |
| 408 << model_type_string << "."; | 424 << model_type_string << "."; |
| 409 return UNSPECIFIED; | 425 return UNSPECIFIED; |
| 410 } | 426 } |
| 411 | 427 |
| 412 std::string ModelTypeSetToString(ModelTypeSet model_types) { | 428 std::string ModelTypeSetToString(ModelTypeSet model_types) { |
| 413 std::string result; | 429 std::string result; |
| 414 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { | 430 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { |
| 415 if (!result.empty()) { | 431 if (!result.empty()) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 case EXTENSION_SETTINGS: | 486 case EXTENSION_SETTINGS: |
| 471 return "google_chrome_extension_settings"; | 487 return "google_chrome_extension_settings"; |
| 472 case APP_NOTIFICATIONS: | 488 case APP_NOTIFICATIONS: |
| 473 return "google_chrome_app_notifications"; | 489 return "google_chrome_app_notifications"; |
| 474 case HISTORY_DELETE_DIRECTIVES: | 490 case HISTORY_DELETE_DIRECTIVES: |
| 475 return "google_chrome_history_delete_directives"; | 491 return "google_chrome_history_delete_directives"; |
| 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"; |
| 496 case CONTROL_PREFERENCES: |
| 497 return "google_chrome_control_preferences"; |
| 480 default: | 498 default: |
| 481 break; | 499 break; |
| 482 } | 500 } |
| 483 NOTREACHED() << "No known extension for model type."; | 501 NOTREACHED() << "No known extension for model type."; |
| 484 return "INVALID"; | 502 return "INVALID"; |
| 485 } | 503 } |
| 486 | 504 |
| 487 // TODO(akalin): Figure out a better way to do these mappings. | 505 // TODO(akalin): Figure out a better way to do these mappings. |
| 488 | 506 |
| 489 namespace { | 507 namespace { |
| 490 const char kBookmarkNotificationType[] = "BOOKMARK"; | 508 const char kBookmarkNotificationType[] = "BOOKMARK"; |
| 491 const char kPreferenceNotificationType[] = "PREFERENCE"; | 509 const char kPreferenceNotificationType[] = "PREFERENCE"; |
| 492 const char kPasswordNotificationType[] = "PASSWORD"; | 510 const char kPasswordNotificationType[] = "PASSWORD"; |
| 493 const char kAutofillNotificationType[] = "AUTOFILL"; | 511 const char kAutofillNotificationType[] = "AUTOFILL"; |
| 494 const char kThemeNotificationType[] = "THEME"; | 512 const char kThemeNotificationType[] = "THEME"; |
| 495 const char kTypedUrlNotificationType[] = "TYPED_URL"; | 513 const char kTypedUrlNotificationType[] = "TYPED_URL"; |
| 496 const char kExtensionNotificationType[] = "EXTENSION"; | 514 const char kExtensionNotificationType[] = "EXTENSION"; |
| 497 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; | 515 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; |
| 498 const char kNigoriNotificationType[] = "NIGORI"; | 516 const char kNigoriNotificationType[] = "NIGORI"; |
| 499 const char kAppSettingNotificationType[] = "APP_SETTING"; | 517 const char kAppSettingNotificationType[] = "APP_SETTING"; |
| 500 const char kAppNotificationType[] = "APP"; | 518 const char kAppNotificationType[] = "APP"; |
| 501 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; | 519 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; |
| 502 const char kSessionNotificationType[] = "SESSION"; | 520 const char kSessionNotificationType[] = "SESSION"; |
| 503 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; | 521 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; |
| 504 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; | 522 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; |
| 505 const char kHistoryDeleteDirectiveNotificationType[] = | 523 const char kHistoryDeleteDirectiveNotificationType[] = |
| 506 "HISTORY_DELETE_DIRECTIVE"; | 524 "HISTORY_DELETE_DIRECTIVE"; |
| 507 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; | 525 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; |
| 508 const char kExperimentsNotificationType[] = "EXPERIMENTS"; | 526 const char kExperimentsNotificationType[] = "EXPERIMENTS"; |
| 527 const char kControlPreferenceNotificationType[] = "CONTROL_PREFERENCE"; |
| 509 } // namespace | 528 } // namespace |
| 510 | 529 |
| 511 bool RealModelTypeToNotificationType(ModelType model_type, | 530 bool RealModelTypeToNotificationType(ModelType model_type, |
| 512 std::string* notification_type) { | 531 std::string* notification_type) { |
| 513 switch (model_type) { | 532 switch (model_type) { |
| 514 case BOOKMARKS: | 533 case BOOKMARKS: |
| 515 *notification_type = kBookmarkNotificationType; | 534 *notification_type = kBookmarkNotificationType; |
| 516 return true; | 535 return true; |
| 517 case PREFERENCES: | 536 case PREFERENCES: |
| 518 *notification_type = kPreferenceNotificationType; | 537 *notification_type = kPreferenceNotificationType; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 *notification_type = kAppNotificationNotificationType; | 576 *notification_type = kAppNotificationNotificationType; |
| 558 return true; | 577 return true; |
| 559 case HISTORY_DELETE_DIRECTIVES: | 578 case HISTORY_DELETE_DIRECTIVES: |
| 560 *notification_type = kHistoryDeleteDirectiveNotificationType; | 579 *notification_type = kHistoryDeleteDirectiveNotificationType; |
| 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; |
| 586 case CONTROL_PREFERENCES: |
| 587 *notification_type = kControlPreferenceNotificationType; |
| 567 default: | 588 default: |
| 568 break; | 589 break; |
| 569 } | 590 } |
| 570 notification_type->clear(); | 591 notification_type->clear(); |
| 571 return false; | 592 return false; |
| 572 } | 593 } |
| 573 | 594 |
| 574 bool NotificationTypeToRealModelType(const std::string& notification_type, | 595 bool NotificationTypeToRealModelType(const std::string& notification_type, |
| 575 ModelType* model_type) { | 596 ModelType* model_type) { |
| 576 if (notification_type == kBookmarkNotificationType) { | 597 if (notification_type == kBookmarkNotificationType) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 *model_type = EXTENSION_SETTINGS; | 637 *model_type = EXTENSION_SETTINGS; |
| 617 return true; | 638 return true; |
| 618 } else if (notification_type == kAppNotificationNotificationType) { | 639 } else if (notification_type == kAppNotificationNotificationType) { |
| 619 *model_type = APP_NOTIFICATIONS; | 640 *model_type = APP_NOTIFICATIONS; |
| 620 return true; | 641 return true; |
| 621 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) { | 642 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) { |
| 622 *model_type = HISTORY_DELETE_DIRECTIVES; | 643 *model_type = HISTORY_DELETE_DIRECTIVES; |
| 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; |
| 647 } else if (notification_type == kControlPreferenceNotificationType) { |
| 648 *model_type = CONTROL_PREFERENCES; |
| 649 return true; |
| 626 } | 650 } |
| 627 *model_type = UNSPECIFIED; | 651 *model_type = UNSPECIFIED; |
| 628 return false; | 652 return false; |
| 629 } | 653 } |
| 630 | 654 |
| 631 bool IsRealDataType(ModelType model_type) { | 655 bool IsRealDataType(ModelType model_type) { |
| 632 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; | 656 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; |
| 633 } | 657 } |
| 634 | 658 |
| 635 } // namespace syncer | 659 } // namespace syncer |
| OLD | NEW |