Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: components/sync/syncable/model_type.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "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/strings/string_split.h" 10 #include "base/strings/string_split.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "sync/protocol/app_notification_specifics.pb.h" 12 #include "components/sync/protocol/app_notification_specifics.pb.h"
13 #include "sync/protocol/app_setting_specifics.pb.h" 13 #include "components/sync/protocol/app_setting_specifics.pb.h"
14 #include "sync/protocol/app_specifics.pb.h" 14 #include "components/sync/protocol/app_specifics.pb.h"
15 #include "sync/protocol/autofill_specifics.pb.h" 15 #include "components/sync/protocol/autofill_specifics.pb.h"
16 #include "sync/protocol/bookmark_specifics.pb.h" 16 #include "components/sync/protocol/bookmark_specifics.pb.h"
17 #include "sync/protocol/extension_setting_specifics.pb.h" 17 #include "components/sync/protocol/extension_setting_specifics.pb.h"
18 #include "sync/protocol/extension_specifics.pb.h" 18 #include "components/sync/protocol/extension_specifics.pb.h"
19 #include "sync/protocol/nigori_specifics.pb.h" 19 #include "components/sync/protocol/nigori_specifics.pb.h"
20 #include "sync/protocol/password_specifics.pb.h" 20 #include "components/sync/protocol/password_specifics.pb.h"
21 #include "sync/protocol/preference_specifics.pb.h" 21 #include "components/sync/protocol/preference_specifics.pb.h"
22 #include "sync/protocol/search_engine_specifics.pb.h" 22 #include "components/sync/protocol/search_engine_specifics.pb.h"
23 #include "sync/protocol/session_specifics.pb.h" 23 #include "components/sync/protocol/session_specifics.pb.h"
24 #include "sync/protocol/sync.pb.h" 24 #include "components/sync/protocol/sync.pb.h"
25 #include "sync/protocol/theme_specifics.pb.h" 25 #include "components/sync/protocol/theme_specifics.pb.h"
26 #include "sync/protocol/typed_url_specifics.pb.h" 26 #include "components/sync/protocol/typed_url_specifics.pb.h"
27 #include "sync/syncable/syncable_proto_util.h" 27 #include "components/sync/syncable/syncable_proto_util.h"
28 28
29 namespace syncer { 29 namespace syncer {
30 30
31 struct ModelTypeInfo { 31 struct ModelTypeInfo {
32 const ModelType model_type; 32 const ModelType model_type;
33 // Model Type notification string. 33 // Model Type notification string.
34 // This needs to match the corresponding proto message name in sync.proto 34 // This needs to match the corresponding proto message name in sync.proto
35 const char* const notification_type; 35 const char* const notification_type;
36 // Root tag for Model Type 36 // Root tag for Model Type
37 // This should be the same as the model type but all lowercase. 37 // This should be the same as the model type but all lowercase.
(...skipping 24 matching lines...) Expand all
62 {PASSWORDS, "PASSWORD", "passwords", "Passwords", 62 {PASSWORDS, "PASSWORD", "passwords", "Passwords",
63 sync_pb::EntitySpecifics::kPasswordFieldNumber, 4}, 63 sync_pb::EntitySpecifics::kPasswordFieldNumber, 4},
64 {AUTOFILL_PROFILE, "AUTOFILL_PROFILE", "autofill_profiles", 64 {AUTOFILL_PROFILE, "AUTOFILL_PROFILE", "autofill_profiles",
65 "Autofill Profiles", sync_pb::EntitySpecifics::kAutofillProfileFieldNumber, 65 "Autofill Profiles", sync_pb::EntitySpecifics::kAutofillProfileFieldNumber,
66 5}, 66 5},
67 {AUTOFILL, "AUTOFILL", "autofill", "Autofill", 67 {AUTOFILL, "AUTOFILL", "autofill", "Autofill",
68 sync_pb::EntitySpecifics::kAutofillFieldNumber, 6}, 68 sync_pb::EntitySpecifics::kAutofillFieldNumber, 6},
69 {AUTOFILL_WALLET_DATA, "AUTOFILL_WALLET", "autofill_wallet", 69 {AUTOFILL_WALLET_DATA, "AUTOFILL_WALLET", "autofill_wallet",
70 "Autofill Wallet", sync_pb::EntitySpecifics::kAutofillWalletFieldNumber, 70 "Autofill Wallet", sync_pb::EntitySpecifics::kAutofillWalletFieldNumber,
71 34}, 71 34},
72 {AUTOFILL_WALLET_METADATA, "WALLET_METADATA", 72 {AUTOFILL_WALLET_METADATA, "WALLET_METADATA", "autofill_wallet_metadata",
73 "autofill_wallet_metadata", "Autofill Wallet Metadata", 73 "Autofill Wallet Metadata",
74 sync_pb::EntitySpecifics::kWalletMetadataFieldNumber, 35}, 74 sync_pb::EntitySpecifics::kWalletMetadataFieldNumber, 35},
75 {THEMES, "THEME", "themes", "Themes", 75 {THEMES, "THEME", "themes", "Themes",
76 sync_pb::EntitySpecifics::kThemeFieldNumber, 7}, 76 sync_pb::EntitySpecifics::kThemeFieldNumber, 7},
77 {TYPED_URLS, "TYPED_URL", "typed_urls", "Typed URLs", 77 {TYPED_URLS, "TYPED_URL", "typed_urls", "Typed URLs",
78 sync_pb::EntitySpecifics::kTypedUrlFieldNumber, 8}, 78 sync_pb::EntitySpecifics::kTypedUrlFieldNumber, 8},
79 {EXTENSIONS, "EXTENSION", "extensions", "Extensions", 79 {EXTENSIONS, "EXTENSION", "extensions", "Extensions",
80 sync_pb::EntitySpecifics::kExtensionFieldNumber, 9}, 80 sync_pb::EntitySpecifics::kExtensionFieldNumber, 9},
81 {SEARCH_ENGINES, "SEARCH_ENGINE", "search_engines", "Search Engines", 81 {SEARCH_ENGINES, "SEARCH_ENGINE", "search_engines", "Search Engines",
82 sync_pb::EntitySpecifics::kSearchEngineFieldNumber, 10}, 82 sync_pb::EntitySpecifics::kSearchEngineFieldNumber, 10},
83 {SESSIONS, "SESSION", "sessions", "Sessions", 83 {SESSIONS, "SESSION", "sessions", "Sessions",
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 142
143 static_assert(arraysize(kModelTypeInfoMap) == MODEL_TYPE_COUNT, 143 static_assert(arraysize(kModelTypeInfoMap) == MODEL_TYPE_COUNT,
144 "kModelTypeInfoMap should have MODEL_TYPE_COUNT elements"); 144 "kModelTypeInfoMap should have MODEL_TYPE_COUNT elements");
145 145
146 // Notes: 146 // Notes:
147 // 1) This list must contain exactly the same elements as the set returned by 147 // 1) This list must contain exactly the same elements as the set returned by
148 // UserSelectableTypes(). 148 // UserSelectableTypes().
149 // 2) This list must be in the same order as the respective values in the 149 // 2) This list must be in the same order as the respective values in the
150 // ModelType enum. 150 // ModelType enum.
151 const char* kUserSelectableDataTypeNames[] = { 151 const char* kUserSelectableDataTypeNames[] = {
152 "bookmarks", 152 "bookmarks", "preferences", "passwords", "autofill", "themes",
153 "preferences", 153 "typedUrls", "extensions", "apps", "tabs",
154 "passwords",
155 "autofill",
156 "themes",
157 "typedUrls",
158 "extensions",
159 "apps",
160 "tabs",
161 }; 154 };
162 155
163 static_assert( 156 static_assert(
164 37 == MODEL_TYPE_COUNT, 157 37 == MODEL_TYPE_COUNT,
165 "update kUserSelectableDataTypeName to match UserSelectableTypes"); 158 "update kUserSelectableDataTypeName to match UserSelectableTypes");
166 159
167 void AddDefaultFieldValue(ModelType datatype, 160 void AddDefaultFieldValue(ModelType datatype,
168 sync_pb::EntitySpecifics* specifics) { 161 sync_pb::EntitySpecifics* specifics) {
169 if (!ProtocolTypes().Has(datatype)) { 162 if (!ProtocolTypes().Has(datatype)) {
170 NOTREACHED() << "Only protocol types have field values."; 163 NOTREACHED() << "Only protocol types have field values.";
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 std::unique_ptr<base::ListValue> ModelTypeSetToValue(ModelTypeSet model_types) { 667 std::unique_ptr<base::ListValue> ModelTypeSetToValue(ModelTypeSet model_types) {
675 std::unique_ptr<base::ListValue> value(new base::ListValue()); 668 std::unique_ptr<base::ListValue> value(new base::ListValue());
676 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { 669 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) {
677 value->AppendString(ModelTypeToString(it.Get())); 670 value->AppendString(ModelTypeToString(it.Get()));
678 } 671 }
679 return value; 672 return value;
680 } 673 }
681 674
682 ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value) { 675 ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value) {
683 ModelTypeSet result; 676 ModelTypeSet result;
684 for (base::ListValue::const_iterator i = value.begin(); 677 for (base::ListValue::const_iterator i = value.begin(); i != value.end();
685 i != value.end(); ++i) { 678 ++i) {
686 result.Put(ModelTypeFromValue(**i)); 679 result.Put(ModelTypeFromValue(**i));
687 } 680 }
688 return result; 681 return result;
689 } 682 }
690 683
691 // TODO(zea): remove all hardcoded tags in model associators and have them use 684 // TODO(zea): remove all hardcoded tags in model associators and have them use
692 // this instead. 685 // this instead.
693 // NOTE: Proxy types should return empty strings (so that we don't NOTREACHED 686 // NOTE: Proxy types should return empty strings (so that we don't NOTREACHED
694 // in tests when we verify they have no root node). 687 // in tests when we verify they have no root node).
695 std::string ModelTypeToRootTag(ModelType type) { 688 std::string ModelTypeToRootTag(ModelType type) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 bool TypeSupportsHierarchy(ModelType model_type) { 748 bool TypeSupportsHierarchy(ModelType model_type) {
756 // TODO(stanisc): crbug/438313: Should this also include TOP_LEVEL_FOLDER? 749 // TODO(stanisc): crbug/438313: Should this also include TOP_LEVEL_FOLDER?
757 return model_type == BOOKMARKS; 750 return model_type == BOOKMARKS;
758 } 751 }
759 752
760 bool TypeSupportsOrdering(ModelType model_type) { 753 bool TypeSupportsOrdering(ModelType model_type) {
761 return model_type == BOOKMARKS; 754 return model_type == BOOKMARKS;
762 } 755 }
763 756
764 } // namespace syncer 757 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/syncable/model_neutral_mutable_entry.cc ('k') | components/sync/syncable/model_type_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698