Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / sync / protocol / proto_enum_conversions.cc
blobbafe31eb3d126e6e4f9fc29bd2f82b8e43c3a35e
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
3 // found in the LICENSE file.
5 // Keep this file in sync with the .proto files in this directory.
7 #include "sync/protocol/proto_enum_conversions.h"
9 #include "base/basictypes.h"
10 #include "base/logging.h"
12 namespace syncer {
14 #define ASSERT_ENUM_BOUNDS(enum_parent, enum_type, enum_min, enum_max) \
15 static_assert(enum_parent::enum_type##_MIN == enum_parent::enum_min, \
16 #enum_type "_MIN should be " #enum_min); \
17 static_assert(enum_parent::enum_type##_MAX == enum_parent::enum_max, \
18 #enum_type "_MAX should be " #enum_max);
20 #define ENUM_CASE(enum_parent, enum_value) \
21 case enum_parent::enum_value: return #enum_value
23 const char* GetAppListItemTypeString(
24 sync_pb::AppListSpecifics::AppListItemType item_type) {
25 ASSERT_ENUM_BOUNDS(sync_pb::AppListSpecifics, AppListItemType,
26 TYPE_APP, TYPE_URL);
27 switch (item_type) {
28 ENUM_CASE(sync_pb::AppListSpecifics, TYPE_APP);
29 ENUM_CASE(sync_pb::AppListSpecifics, TYPE_REMOVE_DEFAULT_APP);
30 ENUM_CASE(sync_pb::AppListSpecifics, TYPE_FOLDER);
31 ENUM_CASE(sync_pb::AppListSpecifics, TYPE_URL);
33 NOTREACHED();
34 return "";
37 const char* GetBrowserTypeString(
38 sync_pb::SessionWindow::BrowserType browser_type) {
39 ASSERT_ENUM_BOUNDS(sync_pb::SessionWindow, BrowserType,
40 TYPE_TABBED, TYPE_POPUP);
41 switch (browser_type) {
42 ENUM_CASE(sync_pb::SessionWindow, TYPE_TABBED);
43 ENUM_CASE(sync_pb::SessionWindow, TYPE_POPUP);
45 NOTREACHED();
46 return "";
49 const char* GetPageTransitionString(
50 sync_pb::SyncEnums::PageTransition page_transition) {
51 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, PageTransition,
52 LINK, KEYWORD_GENERATED);
53 switch (page_transition) {
54 ENUM_CASE(sync_pb::SyncEnums, LINK);
55 ENUM_CASE(sync_pb::SyncEnums, TYPED);
56 ENUM_CASE(sync_pb::SyncEnums, AUTO_BOOKMARK);
57 ENUM_CASE(sync_pb::SyncEnums, AUTO_SUBFRAME);
58 ENUM_CASE(sync_pb::SyncEnums, MANUAL_SUBFRAME);
59 ENUM_CASE(sync_pb::SyncEnums, GENERATED);
60 ENUM_CASE(sync_pb::SyncEnums, AUTO_TOPLEVEL);
61 ENUM_CASE(sync_pb::SyncEnums, FORM_SUBMIT);
62 ENUM_CASE(sync_pb::SyncEnums, RELOAD);
63 ENUM_CASE(sync_pb::SyncEnums, KEYWORD);
64 ENUM_CASE(sync_pb::SyncEnums, KEYWORD_GENERATED);
66 NOTREACHED();
67 return "";
70 const char* GetPageTransitionRedirectTypeString(
71 sync_pb::SyncEnums::PageTransitionRedirectType
72 page_transition_qualifier) {
73 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, PageTransitionRedirectType,
74 CLIENT_REDIRECT, SERVER_REDIRECT);
75 switch (page_transition_qualifier) {
76 ENUM_CASE(sync_pb::SyncEnums, CLIENT_REDIRECT);
77 ENUM_CASE(sync_pb::SyncEnums, SERVER_REDIRECT);
79 NOTREACHED();
80 return "";
83 const char* GetWifiCredentialSecurityClassString(
84 sync_pb::WifiCredentialSpecifics::SecurityClass security_class) {
85 ASSERT_ENUM_BOUNDS(sync_pb::WifiCredentialSpecifics, SecurityClass,
86 SECURITY_CLASS_INVALID, SECURITY_CLASS_PSK);
87 switch (security_class) {
88 ENUM_CASE(sync_pb::WifiCredentialSpecifics, SECURITY_CLASS_INVALID);
89 ENUM_CASE(sync_pb::WifiCredentialSpecifics, SECURITY_CLASS_NONE);
90 ENUM_CASE(sync_pb::WifiCredentialSpecifics, SECURITY_CLASS_WEP);
91 ENUM_CASE(sync_pb::WifiCredentialSpecifics, SECURITY_CLASS_PSK);
93 NOTREACHED();
94 return "";
96 const char* GetUpdatesSourceString(
97 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source) {
98 ASSERT_ENUM_BOUNDS(sync_pb::GetUpdatesCallerInfo, GetUpdatesSource,
99 UNKNOWN, PROGRAMMATIC);
100 switch (updates_source) {
101 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, UNKNOWN);
102 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, FIRST_UPDATE);
103 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, LOCAL);
104 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, NOTIFICATION);
105 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, PERIODIC);
106 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, SYNC_CYCLE_CONTINUATION);
107 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, NEWLY_SUPPORTED_DATATYPE);
108 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, MIGRATION);
109 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, NEW_CLIENT);
110 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, RECONFIGURATION);
111 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, DATATYPE_REFRESH);
112 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, RETRY);
113 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, PROGRAMMATIC);
115 NOTREACHED();
116 return "";
119 const char* GetUpdatesOriginString(
120 sync_pb::SyncEnums::GetUpdatesOrigin origin) {
121 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, GetUpdatesOrigin,
122 UNKNOWN_ORIGIN, PROGRAMMATIC);
123 switch (origin) {
124 ENUM_CASE(sync_pb::SyncEnums, UNKNOWN_ORIGIN);
125 ENUM_CASE(sync_pb::SyncEnums, PERIODIC);
126 ENUM_CASE(sync_pb::SyncEnums, NEWLY_SUPPORTED_DATATYPE);
127 ENUM_CASE(sync_pb::SyncEnums, MIGRATION);
128 ENUM_CASE(sync_pb::SyncEnums, NEW_CLIENT);
129 ENUM_CASE(sync_pb::SyncEnums, RECONFIGURATION);
130 ENUM_CASE(sync_pb::SyncEnums, GU_TRIGGER);
131 ENUM_CASE(sync_pb::SyncEnums, RETRY);
132 ENUM_CASE(sync_pb::SyncEnums, PROGRAMMATIC);
134 NOTREACHED();
135 return "";
138 const char* GetResponseTypeString(
139 sync_pb::CommitResponse::ResponseType response_type) {
140 ASSERT_ENUM_BOUNDS(sync_pb::CommitResponse, ResponseType, SUCCESS,
141 TRANSIENT_ERROR);
142 switch (response_type) {
143 ENUM_CASE(sync_pb::CommitResponse, SUCCESS);
144 ENUM_CASE(sync_pb::CommitResponse, CONFLICT);
145 ENUM_CASE(sync_pb::CommitResponse, RETRY);
146 ENUM_CASE(sync_pb::CommitResponse, INVALID_MESSAGE);
147 ENUM_CASE(sync_pb::CommitResponse, OVER_QUOTA);
148 ENUM_CASE(sync_pb::CommitResponse, TRANSIENT_ERROR);
150 NOTREACHED();
151 return "";
154 const char* GetErrorTypeString(sync_pb::SyncEnums::ErrorType error_type) {
155 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, ErrorType, SUCCESS, UNKNOWN);
156 switch (error_type) {
157 ENUM_CASE(sync_pb::SyncEnums, SUCCESS);
158 ENUM_CASE(sync_pb::SyncEnums, ACCESS_DENIED);
159 ENUM_CASE(sync_pb::SyncEnums, NOT_MY_BIRTHDAY);
160 ENUM_CASE(sync_pb::SyncEnums, THROTTLED);
161 ENUM_CASE(sync_pb::SyncEnums, AUTH_EXPIRED);
162 ENUM_CASE(sync_pb::SyncEnums, USER_NOT_ACTIVATED);
163 ENUM_CASE(sync_pb::SyncEnums, AUTH_INVALID);
164 ENUM_CASE(sync_pb::SyncEnums, CLEAR_PENDING);
165 ENUM_CASE(sync_pb::SyncEnums, TRANSIENT_ERROR);
166 ENUM_CASE(sync_pb::SyncEnums, MIGRATION_DONE);
167 ENUM_CASE(sync_pb::SyncEnums, DISABLED_BY_ADMIN);
168 ENUM_CASE(sync_pb::SyncEnums, USER_ROLLBACK);
169 ENUM_CASE(sync_pb::SyncEnums, PARTIAL_FAILURE);
170 ENUM_CASE(sync_pb::SyncEnums, UNKNOWN);
172 NOTREACHED();
173 return "";
176 const char* GetActionString(sync_pb::SyncEnums::Action action) {
177 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, Action,
178 UPGRADE_CLIENT, UNKNOWN_ACTION);
179 switch (action) {
180 ENUM_CASE(sync_pb::SyncEnums, UPGRADE_CLIENT);
181 ENUM_CASE(sync_pb::SyncEnums, CLEAR_USER_DATA_AND_RESYNC);
182 ENUM_CASE(sync_pb::SyncEnums, ENABLE_SYNC_ON_ACCOUNT);
183 ENUM_CASE(sync_pb::SyncEnums, STOP_AND_RESTART_SYNC);
184 ENUM_CASE(sync_pb::SyncEnums, DISABLE_SYNC_ON_CLIENT);
185 ENUM_CASE(sync_pb::SyncEnums, UNKNOWN_ACTION);
187 NOTREACHED();
188 return "";
192 const char* GetLaunchTypeString(sync_pb::AppSpecifics::LaunchType launch_type) {
193 ASSERT_ENUM_BOUNDS(sync_pb::AppSpecifics, LaunchType, PINNED, WINDOW);
194 switch (launch_type) {
195 ENUM_CASE(sync_pb::AppSpecifics, PINNED);
196 ENUM_CASE(sync_pb::AppSpecifics, REGULAR);
197 ENUM_CASE(sync_pb::AppSpecifics, FULLSCREEN);
198 ENUM_CASE(sync_pb::AppSpecifics, WINDOW);
200 NOTREACHED();
201 return "";
204 const char* GetWalletInfoTypeString(
205 sync_pb::AutofillWalletSpecifics::WalletInfoType wallet_info_type) {
206 ASSERT_ENUM_BOUNDS(sync_pb::AutofillWalletSpecifics, WalletInfoType,
207 UNKNOWN, POSTAL_ADDRESS);
208 switch (wallet_info_type) {
209 ENUM_CASE(sync_pb::AutofillWalletSpecifics, UNKNOWN);
210 ENUM_CASE(sync_pb::AutofillWalletSpecifics, MASKED_CREDIT_CARD);
211 ENUM_CASE(sync_pb::AutofillWalletSpecifics, POSTAL_ADDRESS);
213 NOTREACHED();
214 return "";
217 const char* GetWalletMetadataTypeString(
218 sync_pb::WalletMetadataSpecifics::Type wallet_metadata_type) {
219 ASSERT_ENUM_BOUNDS(sync_pb::WalletMetadataSpecifics, Type, UNKNOWN, ADDRESS);
220 switch (wallet_metadata_type) {
221 ENUM_CASE(sync_pb::WalletMetadataSpecifics, UNKNOWN);
222 ENUM_CASE(sync_pb::WalletMetadataSpecifics, CARD);
223 ENUM_CASE(sync_pb::WalletMetadataSpecifics, ADDRESS);
225 NOTREACHED();
226 return "";
229 const char* GetWalletCardStatusString(
230 sync_pb::WalletMaskedCreditCard::WalletCardStatus wallet_card_status) {
231 switch (wallet_card_status) {
232 ENUM_CASE(sync_pb::WalletMaskedCreditCard, VALID);
233 ENUM_CASE(sync_pb::WalletMaskedCreditCard, EXPIRED);
235 NOTREACHED();
236 return "";
239 const char* GetWalletCardTypeString(
240 sync_pb::WalletMaskedCreditCard::WalletCardType wallet_card_type) {
241 switch (wallet_card_type) {
242 ENUM_CASE(sync_pb::WalletMaskedCreditCard, UNKNOWN);
243 ENUM_CASE(sync_pb::WalletMaskedCreditCard, AMEX);
244 ENUM_CASE(sync_pb::WalletMaskedCreditCard, DISCOVER);
245 ENUM_CASE(sync_pb::WalletMaskedCreditCard, JCB);
246 ENUM_CASE(sync_pb::WalletMaskedCreditCard, MAESTRO);
247 ENUM_CASE(sync_pb::WalletMaskedCreditCard, MASTER_CARD);
248 ENUM_CASE(sync_pb::WalletMaskedCreditCard, SOLO);
249 ENUM_CASE(sync_pb::WalletMaskedCreditCard, SWITCH);
250 ENUM_CASE(sync_pb::WalletMaskedCreditCard, VISA);
252 NOTREACHED();
253 return "";
256 const char* GetDeviceTypeString(
257 sync_pb::SyncEnums::DeviceType device_type) {
258 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, DeviceType, TYPE_WIN, TYPE_TABLET);
259 switch (device_type) {
260 ENUM_CASE(sync_pb::SyncEnums, TYPE_WIN);
261 ENUM_CASE(sync_pb::SyncEnums, TYPE_MAC);
262 ENUM_CASE(sync_pb::SyncEnums, TYPE_LINUX);
263 ENUM_CASE(sync_pb::SyncEnums, TYPE_CROS);
264 ENUM_CASE(sync_pb::SyncEnums, TYPE_OTHER);
265 ENUM_CASE(sync_pb::SyncEnums, TYPE_PHONE);
266 ENUM_CASE(sync_pb::SyncEnums, TYPE_TABLET);
268 NOTREACHED();
269 return "";
272 const char* GetFaviconTypeString(
273 sync_pb::SessionTab::FaviconType favicon_type) {
274 ASSERT_ENUM_BOUNDS(sync_pb::SessionTab, FaviconType, TYPE_WEB_FAVICON,
275 TYPE_WEB_FAVICON);
276 switch (favicon_type) {
277 ENUM_CASE(sync_pb::SessionTab, TYPE_WEB_FAVICON);
279 NOTREACHED();
280 return "";
283 const char* PassphraseTypeString(
284 sync_pb::NigoriSpecifics::PassphraseType type) {
285 ASSERT_ENUM_BOUNDS(sync_pb::NigoriSpecifics, PassphraseType,
286 IMPLICIT_PASSPHRASE, CUSTOM_PASSPHRASE);
287 switch (type) {
288 ENUM_CASE(sync_pb::NigoriSpecifics, IMPLICIT_PASSPHRASE);
289 ENUM_CASE(sync_pb::NigoriSpecifics, KEYSTORE_PASSPHRASE);
290 ENUM_CASE(sync_pb::NigoriSpecifics, FROZEN_IMPLICIT_PASSPHRASE);
291 ENUM_CASE(sync_pb::NigoriSpecifics, CUSTOM_PASSPHRASE);
293 NOTREACHED();
294 return "";
297 const char* SingletonDebugEventTypeString(
298 sync_pb::SyncEnums::SingletonDebugEventType type) {
299 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, SingletonDebugEventType,
300 CONNECTION_STATUS_CHANGE, BOOTSTRAP_TOKEN_UPDATED);
301 switch (type) {
302 ENUM_CASE(sync_pb::SyncEnums, CONNECTION_STATUS_CHANGE);
303 ENUM_CASE(sync_pb::SyncEnums, UPDATED_TOKEN);
304 ENUM_CASE(sync_pb::SyncEnums, PASSPHRASE_REQUIRED);
305 ENUM_CASE(sync_pb::SyncEnums, PASSPHRASE_ACCEPTED);
306 ENUM_CASE(sync_pb::SyncEnums, INITIALIZATION_COMPLETE);
307 ENUM_CASE(sync_pb::SyncEnums, STOP_SYNCING_PERMANENTLY);
308 ENUM_CASE(sync_pb::SyncEnums, ENCRYPTION_COMPLETE);
309 ENUM_CASE(sync_pb::SyncEnums, ACTIONABLE_ERROR);
310 ENUM_CASE(sync_pb::SyncEnums, ENCRYPTED_TYPES_CHANGED);
311 ENUM_CASE(sync_pb::SyncEnums, PASSPHRASE_TYPE_CHANGED);
312 ENUM_CASE(sync_pb::SyncEnums, KEYSTORE_TOKEN_UPDATED);
313 ENUM_CASE(sync_pb::SyncEnums, CONFIGURE_COMPLETE);
314 ENUM_CASE(sync_pb::SyncEnums, BOOTSTRAP_TOKEN_UPDATED);
316 NOTREACHED();
317 return "";
320 const char* GetBlockedStateString(
321 sync_pb::TabNavigation::BlockedState state) {
322 ASSERT_ENUM_BOUNDS(sync_pb::TabNavigation, BlockedState,
323 STATE_ALLOWED, STATE_BLOCKED);
324 switch (state) {
325 ENUM_CASE(sync_pb::TabNavigation, STATE_ALLOWED);
326 ENUM_CASE(sync_pb::TabNavigation, STATE_BLOCKED);
328 NOTREACHED();
329 return "";
332 #undef ASSERT_ENUM_BOUNDS
333 #undef ENUM_CASE
335 } // namespace syncer