| 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/strings/string_split.h" | 7 #include "base/strings/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" |
| 11 #include "sync/protocol/app_specifics.pb.h" | 11 #include "sync/protocol/app_specifics.pb.h" |
| 12 #include "sync/protocol/autofill_specifics.pb.h" | 12 #include "sync/protocol/autofill_specifics.pb.h" |
| 13 #include "sync/protocol/bookmark_specifics.pb.h" | 13 #include "sync/protocol/bookmark_specifics.pb.h" |
| 14 #include "sync/protocol/extension_setting_specifics.pb.h" | 14 #include "sync/protocol/extension_setting_specifics.pb.h" |
| 15 #include "sync/protocol/extension_specifics.pb.h" | 15 #include "sync/protocol/extension_specifics.pb.h" |
| 16 #include "sync/protocol/nigori_specifics.pb.h" | 16 #include "sync/protocol/nigori_specifics.pb.h" |
| 17 #include "sync/protocol/password_specifics.pb.h" | 17 #include "sync/protocol/password_specifics.pb.h" |
| 18 #include "sync/protocol/preference_specifics.pb.h" | 18 #include "sync/protocol/preference_specifics.pb.h" |
| 19 #include "sync/protocol/search_engine_specifics.pb.h" | 19 #include "sync/protocol/search_engine_specifics.pb.h" |
| 20 #include "sync/protocol/session_specifics.pb.h" | 20 #include "sync/protocol/session_specifics.pb.h" |
| 21 #include "sync/protocol/sync.pb.h" | 21 #include "sync/protocol/sync.pb.h" |
| 22 #include "sync/protocol/theme_specifics.pb.h" | 22 #include "sync/protocol/theme_specifics.pb.h" |
| 23 #include "sync/protocol/typed_url_specifics.pb.h" | 23 #include "sync/protocol/typed_url_specifics.pb.h" |
| 24 #include "sync/syncable/syncable_proto_util.h" | 24 #include "sync/syncable/syncable_proto_util.h" |
| 25 | 25 |
| 26 namespace syncer { | 26 namespace syncer { |
| 27 | 27 |
| 28 // Notes: |
| 29 // 1) This list must contain exactly the same elements as the set returned by |
| 30 // UserSelectableTypes(). |
| 31 // 2) This list must be in the same order as the respective values in the |
| 32 // ModelType enum. |
| 33 const char* kUserSelectableDataTypeNames[] = { |
| 34 "bookmarks", |
| 35 "preferences", |
| 36 "passwords", |
| 37 "autofill", |
| 38 "themes", |
| 39 "typedUrls", |
| 40 "extensions", |
| 41 "apps", |
| 42 "wifiCredentials", |
| 43 "tabs", |
| 44 }; |
| 45 |
| 46 COMPILE_ASSERT( |
| 47 33 == MODEL_TYPE_COUNT, |
| 48 update_kUserSelectableDataTypeNames_to_match_UserSelectableTypes); |
| 49 |
| 28 void AddDefaultFieldValue(ModelType datatype, | 50 void AddDefaultFieldValue(ModelType datatype, |
| 29 sync_pb::EntitySpecifics* specifics) { | 51 sync_pb::EntitySpecifics* specifics) { |
| 30 if (!ProtocolTypes().Has(datatype)) { | 52 if (!ProtocolTypes().Has(datatype)) { |
| 31 NOTREACHED() << "Only protocol types have field values."; | 53 NOTREACHED() << "Only protocol types have field values."; |
| 32 return; | 54 return; |
| 33 } | 55 } |
| 34 switch (datatype) { | 56 switch (datatype) { |
| 35 case BOOKMARKS: | 57 case BOOKMARKS: |
| 36 specifics->mutable_bookmark(); | 58 specifics->mutable_bookmark(); |
| 37 break; | 59 break; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 break; | 134 break; |
| 113 case SUPERVISED_USERS: | 135 case SUPERVISED_USERS: |
| 114 specifics->mutable_managed_user(); | 136 specifics->mutable_managed_user(); |
| 115 break; | 137 break; |
| 116 case SUPERVISED_USER_SHARED_SETTINGS: | 138 case SUPERVISED_USER_SHARED_SETTINGS: |
| 117 specifics->mutable_managed_user_shared_setting(); | 139 specifics->mutable_managed_user_shared_setting(); |
| 118 break; | 140 break; |
| 119 case ARTICLES: | 141 case ARTICLES: |
| 120 specifics->mutable_article(); | 142 specifics->mutable_article(); |
| 121 break; | 143 break; |
| 144 case WIFI_CREDENTIALS: |
| 145 specifics->mutable_wifi_credential(); |
| 146 break; |
| 122 default: | 147 default: |
| 123 NOTREACHED() << "No known extension for model type."; | 148 NOTREACHED() << "No known extension for model type."; |
| 124 } | 149 } |
| 125 } | 150 } |
| 126 | 151 |
| 127 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { | 152 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { |
| 128 ModelTypeSet protocol_types = ProtocolTypes(); | 153 ModelTypeSet protocol_types = ProtocolTypes(); |
| 129 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); | 154 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); |
| 130 iter.Inc()) { | 155 iter.Inc()) { |
| 131 if (GetSpecificsFieldNumberFromModelType(iter.Get()) == field_number) | 156 if (GetSpecificsFieldNumberFromModelType(iter.Get()) == field_number) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 case FAVICON_TRACKING: | 214 case FAVICON_TRACKING: |
| 190 return sync_pb::EntitySpecifics::kFaviconTrackingFieldNumber; | 215 return sync_pb::EntitySpecifics::kFaviconTrackingFieldNumber; |
| 191 case SUPERVISED_USER_SETTINGS: | 216 case SUPERVISED_USER_SETTINGS: |
| 192 return sync_pb::EntitySpecifics::kManagedUserSettingFieldNumber; | 217 return sync_pb::EntitySpecifics::kManagedUserSettingFieldNumber; |
| 193 case SUPERVISED_USERS: | 218 case SUPERVISED_USERS: |
| 194 return sync_pb::EntitySpecifics::kManagedUserFieldNumber; | 219 return sync_pb::EntitySpecifics::kManagedUserFieldNumber; |
| 195 case SUPERVISED_USER_SHARED_SETTINGS: | 220 case SUPERVISED_USER_SHARED_SETTINGS: |
| 196 return sync_pb::EntitySpecifics::kManagedUserSharedSettingFieldNumber; | 221 return sync_pb::EntitySpecifics::kManagedUserSharedSettingFieldNumber; |
| 197 case ARTICLES: | 222 case ARTICLES: |
| 198 return sync_pb::EntitySpecifics::kArticleFieldNumber; | 223 return sync_pb::EntitySpecifics::kArticleFieldNumber; |
| 224 case WIFI_CREDENTIALS: |
| 225 return sync_pb::EntitySpecifics::kWifiCredentialFieldNumber; |
| 199 default: | 226 default: |
| 200 NOTREACHED() << "No known extension for model type."; | 227 NOTREACHED() << "No known extension for model type."; |
| 201 return 0; | 228 return 0; |
| 202 } | 229 } |
| 203 } | 230 } |
| 204 | 231 |
| 205 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in) { | 232 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in) { |
| 206 FullModelTypeSet out; | 233 FullModelTypeSet out; |
| 207 for (ModelTypeSet::Iterator i = in.First(); i.Good(); i.Inc()) { | 234 for (ModelTypeSet::Iterator i = in.First(); i.Good(); i.Inc()) { |
| 208 out.Put(i.Get()); | 235 out.Put(i.Get()); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 | 344 |
| 318 if (specifics.has_managed_user()) | 345 if (specifics.has_managed_user()) |
| 319 return SUPERVISED_USERS; | 346 return SUPERVISED_USERS; |
| 320 | 347 |
| 321 if (specifics.has_managed_user_shared_setting()) | 348 if (specifics.has_managed_user_shared_setting()) |
| 322 return SUPERVISED_USER_SHARED_SETTINGS; | 349 return SUPERVISED_USER_SHARED_SETTINGS; |
| 323 | 350 |
| 324 if (specifics.has_article()) | 351 if (specifics.has_article()) |
| 325 return ARTICLES; | 352 return ARTICLES; |
| 326 | 353 |
| 354 if (specifics.has_wifi_credential()) |
| 355 return WIFI_CREDENTIALS; |
| 356 |
| 327 return UNSPECIFIED; | 357 return UNSPECIFIED; |
| 328 } | 358 } |
| 329 | 359 |
| 330 ModelTypeSet ProtocolTypes() { | 360 ModelTypeSet ProtocolTypes() { |
| 331 ModelTypeSet set = ModelTypeSet::All(); | 361 ModelTypeSet set = ModelTypeSet::All(); |
| 332 set.RemoveAll(ProxyTypes()); | 362 set.RemoveAll(ProxyTypes()); |
| 333 return set; | 363 return set; |
| 334 } | 364 } |
| 335 | 365 |
| 336 ModelTypeSet UserTypes() { | 366 ModelTypeSet UserTypes() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 349 // Although the order doesn't technically matter here, it's clearer to keep | 379 // Although the order doesn't technically matter here, it's clearer to keep |
| 350 // these in the same order as their definition in the ModelType enum. | 380 // these in the same order as their definition in the ModelType enum. |
| 351 set.Put(BOOKMARKS); | 381 set.Put(BOOKMARKS); |
| 352 set.Put(PREFERENCES); | 382 set.Put(PREFERENCES); |
| 353 set.Put(PASSWORDS); | 383 set.Put(PASSWORDS); |
| 354 set.Put(AUTOFILL); | 384 set.Put(AUTOFILL); |
| 355 set.Put(THEMES); | 385 set.Put(THEMES); |
| 356 set.Put(TYPED_URLS); | 386 set.Put(TYPED_URLS); |
| 357 set.Put(EXTENSIONS); | 387 set.Put(EXTENSIONS); |
| 358 set.Put(APPS); | 388 set.Put(APPS); |
| 389 set.Put(WIFI_CREDENTIALS); |
| 359 set.Put(PROXY_TABS); | 390 set.Put(PROXY_TABS); |
| 360 return set; | 391 return set; |
| 361 } | 392 } |
| 362 | 393 |
| 363 bool IsUserSelectableType(ModelType model_type) { | 394 bool IsUserSelectableType(ModelType model_type) { |
| 364 return UserSelectableTypes().Has(model_type); | 395 return UserSelectableTypes().Has(model_type); |
| 365 } | 396 } |
| 366 | 397 |
| 398 ModelTypeNameMap GetUserSelectableTypeNameMap() { |
| 399 ModelTypeNameMap type_names; |
| 400 ModelTypeSet type_set = UserSelectableTypes(); |
| 401 ModelTypeSet::Iterator it = type_set.First(); |
| 402 DCHECK_EQ(arraysize(kUserSelectableDataTypeNames), type_set.Size()); |
| 403 for (size_t i = 0; i < arraysize(kUserSelectableDataTypeNames) && it.Good(); |
| 404 ++i, it.Inc()) { |
| 405 type_names[it.Get()] = kUserSelectableDataTypeNames[i]; |
| 406 } |
| 407 return type_names; |
| 408 } |
| 409 |
| 367 ModelTypeSet EncryptableUserTypes() { | 410 ModelTypeSet EncryptableUserTypes() { |
| 368 ModelTypeSet encryptable_user_types = UserTypes(); | 411 ModelTypeSet encryptable_user_types = UserTypes(); |
| 369 // We never encrypt history delete directives. | 412 // We never encrypt history delete directives. |
| 370 encryptable_user_types.Remove(HISTORY_DELETE_DIRECTIVES); | 413 encryptable_user_types.Remove(HISTORY_DELETE_DIRECTIVES); |
| 371 // Synced notifications are not encrypted since the server must see changes. | 414 // Synced notifications are not encrypted since the server must see changes. |
| 372 encryptable_user_types.Remove(SYNCED_NOTIFICATIONS); | 415 encryptable_user_types.Remove(SYNCED_NOTIFICATIONS); |
| 373 // Synced Notification App Info does not have private data, so it is not | 416 // Synced Notification App Info does not have private data, so it is not |
| 374 // encrypted. | 417 // encrypted. |
| 375 encryptable_user_types.Remove(SYNCED_NOTIFICATION_APP_INFO); | 418 encryptable_user_types.Remove(SYNCED_NOTIFICATION_APP_INFO); |
| 376 // Device info data is not encrypted because it might be synced before | 419 // Device info data is not encrypted because it might be synced before |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 case FAVICON_TRACKING: | 560 case FAVICON_TRACKING: |
| 518 return "Favicon Tracking"; | 561 return "Favicon Tracking"; |
| 519 case SUPERVISED_USER_SETTINGS: | 562 case SUPERVISED_USER_SETTINGS: |
| 520 return "Managed User Settings"; | 563 return "Managed User Settings"; |
| 521 case SUPERVISED_USERS: | 564 case SUPERVISED_USERS: |
| 522 return "Managed Users"; | 565 return "Managed Users"; |
| 523 case SUPERVISED_USER_SHARED_SETTINGS: | 566 case SUPERVISED_USER_SHARED_SETTINGS: |
| 524 return "Managed User Shared Settings"; | 567 return "Managed User Shared Settings"; |
| 525 case ARTICLES: | 568 case ARTICLES: |
| 526 return "Articles"; | 569 return "Articles"; |
| 570 case WIFI_CREDENTIALS: |
| 571 return "WiFi Credentials"; |
| 527 case PROXY_TABS: | 572 case PROXY_TABS: |
| 528 return "Tabs"; | 573 return "Tabs"; |
| 529 default: | 574 default: |
| 530 break; | 575 break; |
| 531 } | 576 } |
| 532 NOTREACHED() << "No known extension for model type."; | 577 NOTREACHED() << "No known extension for model type."; |
| 533 return "INVALID"; | 578 return "INVALID"; |
| 534 } | 579 } |
| 535 | 580 |
| 536 // The normal rules about histograms apply here. Always append to the bottom of | 581 // The normal rules about histograms apply here. Always append to the bottom of |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 case SUPERVISED_USERS: | 641 case SUPERVISED_USERS: |
| 597 return 27; | 642 return 27; |
| 598 case ARTICLES: | 643 case ARTICLES: |
| 599 return 28; | 644 return 28; |
| 600 case APP_LIST: | 645 case APP_LIST: |
| 601 return 29; | 646 return 29; |
| 602 case SUPERVISED_USER_SHARED_SETTINGS: | 647 case SUPERVISED_USER_SHARED_SETTINGS: |
| 603 return 30; | 648 return 30; |
| 604 case SYNCED_NOTIFICATION_APP_INFO: | 649 case SYNCED_NOTIFICATION_APP_INFO: |
| 605 return 31; | 650 return 31; |
| 651 case WIFI_CREDENTIALS: |
| 652 return 32; |
| 606 // Silence a compiler warning. | 653 // Silence a compiler warning. |
| 607 case MODEL_TYPE_COUNT: | 654 case MODEL_TYPE_COUNT: |
| 608 return 0; | 655 return 0; |
| 609 } | 656 } |
| 610 return 0; | 657 return 0; |
| 611 } | 658 } |
| 612 | 659 |
| 613 base::StringValue* ModelTypeToValue(ModelType model_type) { | 660 base::StringValue* ModelTypeToValue(ModelType model_type) { |
| 614 if (model_type >= FIRST_REAL_MODEL_TYPE) { | 661 if (model_type >= FIRST_REAL_MODEL_TYPE) { |
| 615 return new base::StringValue(ModelTypeToString(model_type)); | 662 return new base::StringValue(ModelTypeToString(model_type)); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 else if (model_type_string == "Favicon Tracking") | 736 else if (model_type_string == "Favicon Tracking") |
| 690 return FAVICON_TRACKING; | 737 return FAVICON_TRACKING; |
| 691 else if (model_type_string == "Managed User Settings") | 738 else if (model_type_string == "Managed User Settings") |
| 692 return SUPERVISED_USER_SETTINGS; | 739 return SUPERVISED_USER_SETTINGS; |
| 693 else if (model_type_string == "Managed Users") | 740 else if (model_type_string == "Managed Users") |
| 694 return SUPERVISED_USERS; | 741 return SUPERVISED_USERS; |
| 695 else if (model_type_string == "Managed User Shared Settings") | 742 else if (model_type_string == "Managed User Shared Settings") |
| 696 return SUPERVISED_USER_SHARED_SETTINGS; | 743 return SUPERVISED_USER_SHARED_SETTINGS; |
| 697 else if (model_type_string == "Articles") | 744 else if (model_type_string == "Articles") |
| 698 return ARTICLES; | 745 return ARTICLES; |
| 746 else if (model_type_string == "WiFi Credentials") |
| 747 return WIFI_CREDENTIALS; |
| 699 else if (model_type_string == "Tabs") | 748 else if (model_type_string == "Tabs") |
| 700 return PROXY_TABS; | 749 return PROXY_TABS; |
| 701 else | 750 else |
| 702 NOTREACHED() << "No known model type corresponding to " | 751 NOTREACHED() << "No known model type corresponding to " |
| 703 << model_type_string << "."; | 752 << model_type_string << "."; |
| 704 return UNSPECIFIED; | 753 return UNSPECIFIED; |
| 705 } | 754 } |
| 706 | 755 |
| 707 std::string ModelTypeSetToString(ModelTypeSet model_types) { | 756 std::string ModelTypeSetToString(ModelTypeSet model_types) { |
| 708 std::string result; | 757 std::string result; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 case FAVICON_TRACKING: | 862 case FAVICON_TRACKING: |
| 814 return "google_chrome_favicon_tracking"; | 863 return "google_chrome_favicon_tracking"; |
| 815 case SUPERVISED_USER_SETTINGS: | 864 case SUPERVISED_USER_SETTINGS: |
| 816 return "google_chrome_managed_user_settings"; | 865 return "google_chrome_managed_user_settings"; |
| 817 case SUPERVISED_USERS: | 866 case SUPERVISED_USERS: |
| 818 return "google_chrome_managed_users"; | 867 return "google_chrome_managed_users"; |
| 819 case SUPERVISED_USER_SHARED_SETTINGS: | 868 case SUPERVISED_USER_SHARED_SETTINGS: |
| 820 return "google_chrome_managed_user_shared_settings"; | 869 return "google_chrome_managed_user_shared_settings"; |
| 821 case ARTICLES: | 870 case ARTICLES: |
| 822 return "google_chrome_articles"; | 871 return "google_chrome_articles"; |
| 872 case WIFI_CREDENTIALS: |
| 873 return "google_chrome_wifi_credentials"; |
| 823 case PROXY_TABS: | 874 case PROXY_TABS: |
| 824 return std::string(); | 875 return std::string(); |
| 825 default: | 876 default: |
| 826 break; | 877 break; |
| 827 } | 878 } |
| 828 NOTREACHED() << "No known extension for model type."; | 879 NOTREACHED() << "No known extension for model type."; |
| 829 return "INVALID"; | 880 return "INVALID"; |
| 830 } | 881 } |
| 831 | 882 |
| 832 // TODO(akalin): Figure out a better way to do these mappings. | 883 // TODO(akalin): Figure out a better way to do these mappings. |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1064 | 1115 |
| 1065 bool IsProxyType(ModelType model_type) { | 1116 bool IsProxyType(ModelType model_type) { |
| 1066 return model_type >= FIRST_PROXY_TYPE && model_type <= LAST_PROXY_TYPE; | 1117 return model_type >= FIRST_PROXY_TYPE && model_type <= LAST_PROXY_TYPE; |
| 1067 } | 1118 } |
| 1068 | 1119 |
| 1069 bool IsActOnceDataType(ModelType model_type) { | 1120 bool IsActOnceDataType(ModelType model_type) { |
| 1070 return model_type == HISTORY_DELETE_DIRECTIVES; | 1121 return model_type == HISTORY_DELETE_DIRECTIVES; |
| 1071 } | 1122 } |
| 1072 | 1123 |
| 1073 } // namespace syncer | 1124 } // namespace syncer |
| OLD | NEW |