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 DICTIONARY: |
| 86 specifics->mutable_dictionary(); |
| 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 DICTIONARY: |
| 158 return sync_pb::EntitySpecifics::kDictionaryFieldNumber; |
| 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_dictionary()) |
| 262 return DICTIONARY; |
| 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) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 case EXTENSION_SETTINGS: | 334 case EXTENSION_SETTINGS: |
326 return "Extension settings"; | 335 return "Extension settings"; |
327 case APP_NOTIFICATIONS: | 336 case APP_NOTIFICATIONS: |
328 return "App Notifications"; | 337 return "App Notifications"; |
329 case HISTORY_DELETE_DIRECTIVES: | 338 case HISTORY_DELETE_DIRECTIVES: |
330 return "History Delete Directives"; | 339 return "History Delete Directives"; |
331 case DEVICE_INFO: | 340 case DEVICE_INFO: |
332 return "Device Info"; | 341 return "Device Info"; |
333 case EXPERIMENTS: | 342 case EXPERIMENTS: |
334 return "Experiments"; | 343 return "Experiments"; |
| 344 case DICTIONARY: |
| 345 return "Dictionary"; |
335 default: | 346 default: |
336 break; | 347 break; |
337 } | 348 } |
338 NOTREACHED() << "No known extension for model type."; | 349 NOTREACHED() << "No known extension for model type."; |
339 return "INVALID"; | 350 return "INVALID"; |
340 } | 351 } |
341 | 352 |
342 StringValue* ModelTypeToValue(ModelType model_type) { | 353 StringValue* ModelTypeToValue(ModelType model_type) { |
343 if (model_type >= FIRST_REAL_MODEL_TYPE) { | 354 if (model_type >= FIRST_REAL_MODEL_TYPE) { |
344 return Value::CreateStringValue(ModelTypeToString(model_type)); | 355 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") | 407 else if (model_type_string == "Extension settings") |
397 return EXTENSION_SETTINGS; | 408 return EXTENSION_SETTINGS; |
398 else if (model_type_string == "App Notifications") | 409 else if (model_type_string == "App Notifications") |
399 return APP_NOTIFICATIONS; | 410 return APP_NOTIFICATIONS; |
400 else if (model_type_string == "History Delete Directives") | 411 else if (model_type_string == "History Delete Directives") |
401 return HISTORY_DELETE_DIRECTIVES; | 412 return HISTORY_DELETE_DIRECTIVES; |
402 else if (model_type_string == "Device Info") | 413 else if (model_type_string == "Device Info") |
403 return DEVICE_INFO; | 414 return DEVICE_INFO; |
404 else if (model_type_string == "Experiments") | 415 else if (model_type_string == "Experiments") |
405 return EXPERIMENTS; | 416 return EXPERIMENTS; |
| 417 else if (model_type_string == "Dictionary") |
| 418 return DICTIONARY; |
406 else | 419 else |
407 NOTREACHED() << "No known model type corresponding to " | 420 NOTREACHED() << "No known model type corresponding to " |
408 << model_type_string << "."; | 421 << model_type_string << "."; |
409 return UNSPECIFIED; | 422 return UNSPECIFIED; |
410 } | 423 } |
411 | 424 |
412 std::string ModelTypeSetToString(ModelTypeSet model_types) { | 425 std::string ModelTypeSetToString(ModelTypeSet model_types) { |
413 std::string result; | 426 std::string result; |
414 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { | 427 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { |
415 if (!result.empty()) { | 428 if (!result.empty()) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 case EXTENSION_SETTINGS: | 483 case EXTENSION_SETTINGS: |
471 return "google_chrome_extension_settings"; | 484 return "google_chrome_extension_settings"; |
472 case APP_NOTIFICATIONS: | 485 case APP_NOTIFICATIONS: |
473 return "google_chrome_app_notifications"; | 486 return "google_chrome_app_notifications"; |
474 case HISTORY_DELETE_DIRECTIVES: | 487 case HISTORY_DELETE_DIRECTIVES: |
475 return "google_chrome_history_delete_directives"; | 488 return "google_chrome_history_delete_directives"; |
476 case DEVICE_INFO: | 489 case DEVICE_INFO: |
477 return "google_chrome_device_info"; | 490 return "google_chrome_device_info"; |
478 case EXPERIMENTS: | 491 case EXPERIMENTS: |
479 return "google_chrome_experiments"; | 492 return "google_chrome_experiments"; |
| 493 case DICTIONARY: |
| 494 return "google_chrome_dictionary"; |
480 default: | 495 default: |
481 break; | 496 break; |
482 } | 497 } |
483 NOTREACHED() << "No known extension for model type."; | 498 NOTREACHED() << "No known extension for model type."; |
484 return "INVALID"; | 499 return "INVALID"; |
485 } | 500 } |
486 | 501 |
487 // TODO(akalin): Figure out a better way to do these mappings. | 502 // TODO(akalin): Figure out a better way to do these mappings. |
488 | 503 |
489 namespace { | 504 namespace { |
490 const char kBookmarkNotificationType[] = "BOOKMARK"; | 505 const char kBookmarkNotificationType[] = "BOOKMARK"; |
491 const char kPreferenceNotificationType[] = "PREFERENCE"; | 506 const char kPreferenceNotificationType[] = "PREFERENCE"; |
492 const char kPasswordNotificationType[] = "PASSWORD"; | 507 const char kPasswordNotificationType[] = "PASSWORD"; |
493 const char kAutofillNotificationType[] = "AUTOFILL"; | 508 const char kAutofillNotificationType[] = "AUTOFILL"; |
494 const char kThemeNotificationType[] = "THEME"; | 509 const char kThemeNotificationType[] = "THEME"; |
495 const char kTypedUrlNotificationType[] = "TYPED_URL"; | 510 const char kTypedUrlNotificationType[] = "TYPED_URL"; |
496 const char kExtensionNotificationType[] = "EXTENSION"; | 511 const char kExtensionNotificationType[] = "EXTENSION"; |
497 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; | 512 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; |
498 const char kNigoriNotificationType[] = "NIGORI"; | 513 const char kNigoriNotificationType[] = "NIGORI"; |
499 const char kAppSettingNotificationType[] = "APP_SETTING"; | 514 const char kAppSettingNotificationType[] = "APP_SETTING"; |
500 const char kAppNotificationType[] = "APP"; | 515 const char kAppNotificationType[] = "APP"; |
501 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; | 516 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; |
502 const char kSessionNotificationType[] = "SESSION"; | 517 const char kSessionNotificationType[] = "SESSION"; |
503 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; | 518 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; |
504 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; | 519 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; |
505 const char kHistoryDeleteDirectiveNotificationType[] = | 520 const char kHistoryDeleteDirectiveNotificationType[] = |
506 "HISTORY_DELETE_DIRECTIVE"; | 521 "HISTORY_DELETE_DIRECTIVE"; |
507 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; | 522 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; |
508 const char kExperimentsNotificationType[] = "EXPERIMENTS"; | 523 const char kExperimentsNotificationType[] = "EXPERIMENTS"; |
| 524 const char kDictionaryNotificationType[] = "DICTIONARY"; |
509 } // namespace | 525 } // namespace |
510 | 526 |
511 bool RealModelTypeToNotificationType(ModelType model_type, | 527 bool RealModelTypeToNotificationType(ModelType model_type, |
512 std::string* notification_type) { | 528 std::string* notification_type) { |
513 switch (model_type) { | 529 switch (model_type) { |
514 case BOOKMARKS: | 530 case BOOKMARKS: |
515 *notification_type = kBookmarkNotificationType; | 531 *notification_type = kBookmarkNotificationType; |
516 return true; | 532 return true; |
517 case PREFERENCES: | 533 case PREFERENCES: |
518 *notification_type = kPreferenceNotificationType; | 534 *notification_type = kPreferenceNotificationType; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 *notification_type = kAppNotificationNotificationType; | 573 *notification_type = kAppNotificationNotificationType; |
558 return true; | 574 return true; |
559 case HISTORY_DELETE_DIRECTIVES: | 575 case HISTORY_DELETE_DIRECTIVES: |
560 *notification_type = kHistoryDeleteDirectiveNotificationType; | 576 *notification_type = kHistoryDeleteDirectiveNotificationType; |
561 case DEVICE_INFO: | 577 case DEVICE_INFO: |
562 *notification_type = kDeviceInfoNotificationType; | 578 *notification_type = kDeviceInfoNotificationType; |
563 return true; | 579 return true; |
564 case EXPERIMENTS: | 580 case EXPERIMENTS: |
565 *notification_type = kExperimentsNotificationType; | 581 *notification_type = kExperimentsNotificationType; |
566 return true; | 582 return true; |
| 583 case DICTIONARY: |
| 584 *notification_type = kDictionaryNotificationType; |
| 585 return true; |
567 default: | 586 default: |
568 break; | 587 break; |
569 } | 588 } |
570 notification_type->clear(); | 589 notification_type->clear(); |
571 return false; | 590 return false; |
572 } | 591 } |
573 | 592 |
574 bool NotificationTypeToRealModelType(const std::string& notification_type, | 593 bool NotificationTypeToRealModelType(const std::string& notification_type, |
575 ModelType* model_type) { | 594 ModelType* model_type) { |
576 if (notification_type == kBookmarkNotificationType) { | 595 if (notification_type == kBookmarkNotificationType) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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; |
623 } else if (notification_type == kDeviceInfoNotificationType) { | 642 } else if (notification_type == kDeviceInfoNotificationType) { |
624 *model_type = DEVICE_INFO;; | 643 *model_type = DEVICE_INFO;; |
625 return true; | 644 return true; |
| 645 } else if (notification_type == kDictionaryNotificationType) { |
| 646 *model_type = DICTIONARY; |
| 647 return true; |
626 } | 648 } |
627 *model_type = UNSPECIFIED; | 649 *model_type = UNSPECIFIED; |
628 return false; | 650 return false; |
629 } | 651 } |
630 | 652 |
631 bool IsRealDataType(ModelType model_type) { | 653 bool IsRealDataType(ModelType model_type) { |
632 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; | 654 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; |
633 } | 655 } |
634 | 656 |
635 } // namespace syncer | 657 } // namespace syncer |
OLD | NEW |