| 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 "components/sync/base/model_type.h" | 5 #include "components/sync/base/model_type.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "components/reading_list/core/reading_list_enable_flags.h" | |
| 14 #include "components/sync/protocol/app_notification_specifics.pb.h" | 13 #include "components/sync/protocol/app_notification_specifics.pb.h" |
| 15 #include "components/sync/protocol/app_setting_specifics.pb.h" | 14 #include "components/sync/protocol/app_setting_specifics.pb.h" |
| 16 #include "components/sync/protocol/app_specifics.pb.h" | 15 #include "components/sync/protocol/app_specifics.pb.h" |
| 17 #include "components/sync/protocol/autofill_specifics.pb.h" | 16 #include "components/sync/protocol/autofill_specifics.pb.h" |
| 18 #include "components/sync/protocol/bookmark_specifics.pb.h" | 17 #include "components/sync/protocol/bookmark_specifics.pb.h" |
| 19 #include "components/sync/protocol/extension_setting_specifics.pb.h" | 18 #include "components/sync/protocol/extension_setting_specifics.pb.h" |
| 20 #include "components/sync/protocol/extension_specifics.pb.h" | 19 #include "components/sync/protocol/extension_specifics.pb.h" |
| 21 #include "components/sync/protocol/nigori_specifics.pb.h" | 20 #include "components/sync/protocol/nigori_specifics.pb.h" |
| 22 #include "components/sync/protocol/password_specifics.pb.h" | 21 #include "components/sync/protocol/password_specifics.pb.h" |
| 23 #include "components/sync/protocol/preference_specifics.pb.h" | 22 #include "components/sync/protocol/preference_specifics.pb.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 {PROXY_TABS, "", "", "Tabs", -1, 25}, | 144 {PROXY_TABS, "", "", "Tabs", -1, 25}, |
| 146 {NIGORI, "NIGORI", "nigori", "Encryption Keys", | 145 {NIGORI, "NIGORI", "nigori", "Encryption Keys", |
| 147 sync_pb::EntitySpecifics::kNigoriFieldNumber, 17}, | 146 sync_pb::EntitySpecifics::kNigoriFieldNumber, 17}, |
| 148 {EXPERIMENTS, "EXPERIMENTS", "experiments", "Experiments", | 147 {EXPERIMENTS, "EXPERIMENTS", "experiments", "Experiments", |
| 149 sync_pb::EntitySpecifics::kExperimentsFieldNumber, 19}, | 148 sync_pb::EntitySpecifics::kExperimentsFieldNumber, 19}, |
| 150 }; | 149 }; |
| 151 | 150 |
| 152 static_assert(arraysize(kModelTypeInfoMap) == MODEL_TYPE_COUNT, | 151 static_assert(arraysize(kModelTypeInfoMap) == MODEL_TYPE_COUNT, |
| 153 "kModelTypeInfoMap should have MODEL_TYPE_COUNT elements"); | 152 "kModelTypeInfoMap should have MODEL_TYPE_COUNT elements"); |
| 154 | 153 |
| 155 // Notes: | |
| 156 // 1) This list must contain exactly the same elements as the set returned by | |
| 157 // UserSelectableTypes(). | |
| 158 // 2) This list must be in the same order as the respective values in the | |
| 159 // ModelType enum. | |
| 160 const char* kUserSelectableDataTypeNames[] = { | |
| 161 "bookmarks", "preferences", "passwords", "autofill", | |
| 162 "themes", "typedUrls", "extensions", "apps", | |
| 163 #if BUILDFLAG(ENABLE_READING_LIST) | |
| 164 "readingList", | |
| 165 #endif | |
| 166 "tabs", | |
| 167 }; | |
| 168 | |
| 169 void AddDefaultFieldValue(ModelType type, sync_pb::EntitySpecifics* specifics) { | 154 void AddDefaultFieldValue(ModelType type, sync_pb::EntitySpecifics* specifics) { |
| 170 switch (type) { | 155 switch (type) { |
| 171 case UNSPECIFIED: | 156 case UNSPECIFIED: |
| 172 case TOP_LEVEL_FOLDER: | 157 case TOP_LEVEL_FOLDER: |
| 173 NOTREACHED() << "No default field value for " << ModelTypeToString(type); | 158 NOTREACHED() << "No default field value for " << ModelTypeToString(type); |
| 174 break; | 159 break; |
| 175 case BOOKMARKS: | 160 case BOOKMARKS: |
| 176 specifics->mutable_bookmark(); | 161 specifics->mutable_bookmark(); |
| 177 break; | 162 break; |
| 178 case PREFERENCES: | 163 case PREFERENCES: |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 if (specifics.has_user_event()) | 404 if (specifics.has_user_event()) |
| 420 return USER_EVENTS; | 405 return USER_EVENTS; |
| 421 if (specifics.has_nigori()) | 406 if (specifics.has_nigori()) |
| 422 return NIGORI; | 407 return NIGORI; |
| 423 if (specifics.has_experiments()) | 408 if (specifics.has_experiments()) |
| 424 return EXPERIMENTS; | 409 return EXPERIMENTS; |
| 425 | 410 |
| 426 return UNSPECIFIED; | 411 return UNSPECIFIED; |
| 427 } | 412 } |
| 428 | 413 |
| 429 ModelTypeSet ProtocolTypes() { | |
| 430 return Difference(ModelTypeSet::All(), ProxyTypes()); | |
| 431 } | |
| 432 | |
| 433 ModelTypeSet UserTypes() { | |
| 434 // TODO(sync): We should be able to build the actual enumset's internal | |
| 435 // bitset value here at compile time, instead of makes a new one each time. | |
| 436 return ModelTypeSet::FromRange(FIRST_USER_MODEL_TYPE, LAST_USER_MODEL_TYPE); | |
| 437 } | |
| 438 | |
| 439 ModelTypeSet UserSelectableTypes() { | |
| 440 return ModelTypeSet(BOOKMARKS, PREFERENCES, PASSWORDS, AUTOFILL, THEMES, | |
| 441 TYPED_URLS, EXTENSIONS, APPS, | |
| 442 #if BUILDFLAG(ENABLE_READING_LIST) | |
| 443 READING_LIST, | |
| 444 #endif | |
| 445 PROXY_TABS); | |
| 446 } | |
| 447 | |
| 448 bool IsUserSelectableType(ModelType model_type) { | |
| 449 return UserSelectableTypes().Has(model_type); | |
| 450 } | |
| 451 | |
| 452 ModelTypeNameMap GetUserSelectableTypeNameMap() { | 414 ModelTypeNameMap GetUserSelectableTypeNameMap() { |
| 453 ModelTypeNameMap type_names; | 415 ModelTypeNameMap type_names; |
| 454 ModelTypeSet type_set = UserSelectableTypes(); | 416 ModelTypeSet type_set = UserSelectableTypes(); |
| 455 ModelTypeSet::Iterator it = type_set.First(); | 417 ModelTypeSet::Iterator it = type_set.First(); |
| 456 DCHECK_EQ(arraysize(kUserSelectableDataTypeNames), type_set.Size()); | 418 DCHECK_EQ(arraysize(kUserSelectableDataTypeNames), type_set.Size()); |
| 457 for (size_t i = 0; i < arraysize(kUserSelectableDataTypeNames) && it.Good(); | 419 for (size_t i = 0; i < arraysize(kUserSelectableDataTypeNames) && it.Good(); |
| 458 ++i, it.Inc()) { | 420 ++i, it.Inc()) { |
| 459 type_names[it.Get()] = kUserSelectableDataTypeNames[i]; | 421 type_names[it.Get()] = kUserSelectableDataTypeNames[i]; |
| 460 } | 422 } |
| 461 return type_names; | 423 return type_names; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 encryptable_user_types.Remove(SUPERVISED_USER_WHITELISTS); | 455 encryptable_user_types.Remove(SUPERVISED_USER_WHITELISTS); |
| 494 // User events are not encrypted since they are consumed server-side. | 456 // User events are not encrypted since they are consumed server-side. |
| 495 encryptable_user_types.Remove(USER_EVENTS); | 457 encryptable_user_types.Remove(USER_EVENTS); |
| 496 // Proxy types have no sync representation and are therefore not encrypted. | 458 // Proxy types have no sync representation and are therefore not encrypted. |
| 497 // Note however that proxy types map to one or more protocol types, which | 459 // Note however that proxy types map to one or more protocol types, which |
| 498 // may or may not be encrypted themselves. | 460 // may or may not be encrypted themselves. |
| 499 encryptable_user_types.RemoveAll(ProxyTypes()); | 461 encryptable_user_types.RemoveAll(ProxyTypes()); |
| 500 return encryptable_user_types; | 462 return encryptable_user_types; |
| 501 } | 463 } |
| 502 | 464 |
| 503 ModelTypeSet PriorityUserTypes() { | |
| 504 return ModelTypeSet(DEVICE_INFO, PRIORITY_PREFERENCES); | |
| 505 } | |
| 506 | |
| 507 ModelTypeSet ControlTypes() { | |
| 508 // TODO(sync): We should be able to build the actual enumset's internal | |
| 509 // bitset value here at compile time, instead of makes a new one each time. | |
| 510 return ModelTypeSet::FromRange(FIRST_CONTROL_MODEL_TYPE, | |
| 511 LAST_CONTROL_MODEL_TYPE); | |
| 512 } | |
| 513 | |
| 514 ModelTypeSet ProxyTypes() { | |
| 515 return ModelTypeSet::FromRange(FIRST_PROXY_TYPE, LAST_PROXY_TYPE); | |
| 516 } | |
| 517 | |
| 518 bool IsControlType(ModelType model_type) { | |
| 519 return ControlTypes().Has(model_type); | |
| 520 } | |
| 521 | |
| 522 ModelTypeSet CoreTypes() { | |
| 523 ModelTypeSet result = PriorityCoreTypes(); | |
| 524 | |
| 525 // The following are low priority core types. | |
| 526 result.Put(SYNCED_NOTIFICATIONS); | |
| 527 result.Put(SYNCED_NOTIFICATION_APP_INFO); | |
| 528 result.Put(SUPERVISED_USER_SHARED_SETTINGS); | |
| 529 result.Put(SUPERVISED_USER_WHITELISTS); | |
| 530 | |
| 531 return result; | |
| 532 } | |
| 533 | |
| 534 ModelTypeSet PriorityCoreTypes() { | |
| 535 ModelTypeSet result = ControlTypes(); | |
| 536 | |
| 537 // The following are non-control core types. | |
| 538 result.Put(SUPERVISED_USERS); | |
| 539 result.Put(SUPERVISED_USER_SETTINGS); | |
| 540 | |
| 541 return result; | |
| 542 } | |
| 543 | |
| 544 ModelTypeSet CommitOnlyTypes() { | |
| 545 return ModelTypeSet(USER_EVENTS); | |
| 546 } | |
| 547 | |
| 548 const char* ModelTypeToString(ModelType model_type) { | 465 const char* ModelTypeToString(ModelType model_type) { |
| 549 // This is used in serialization routines as well as for displaying debug | 466 // This is used in serialization routines as well as for displaying debug |
| 550 // information. Do not attempt to change these string values unless you know | 467 // information. Do not attempt to change these string values unless you know |
| 551 // what you're doing. | 468 // what you're doing. |
| 552 if (model_type >= UNSPECIFIED && model_type < MODEL_TYPE_COUNT) | 469 if (model_type >= UNSPECIFIED && model_type < MODEL_TYPE_COUNT) |
| 553 return kModelTypeInfoMap[model_type].model_type_string; | 470 return kModelTypeInfoMap[model_type].model_type_string; |
| 554 NOTREACHED() << "No known extension for model type."; | 471 NOTREACHED() << "No known extension for model type."; |
| 555 return "Invalid"; | 472 return "Invalid"; |
| 556 } | 473 } |
| 557 | 474 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 bool TypeSupportsHierarchy(ModelType model_type) { | 647 bool TypeSupportsHierarchy(ModelType model_type) { |
| 731 // TODO(stanisc): crbug/438313: Should this also include TOP_LEVEL_FOLDER? | 648 // TODO(stanisc): crbug/438313: Should this also include TOP_LEVEL_FOLDER? |
| 732 return model_type == BOOKMARKS; | 649 return model_type == BOOKMARKS; |
| 733 } | 650 } |
| 734 | 651 |
| 735 bool TypeSupportsOrdering(ModelType model_type) { | 652 bool TypeSupportsOrdering(ModelType model_type) { |
| 736 return model_type == BOOKMARKS; | 653 return model_type == BOOKMARKS; |
| 737 } | 654 } |
| 738 | 655 |
| 739 } // namespace syncer | 656 } // namespace syncer |
| OLD | NEW |