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"
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
,
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
);
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
);
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
);
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
);
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
);
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
);
119 const char* GetUpdatesOriginString(
120 sync_pb::SyncEnums::GetUpdatesOrigin origin
) {
121 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums
, GetUpdatesOrigin
,
122 UNKNOWN_ORIGIN
, PROGRAMMATIC
);
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
);
138 const char* GetResponseTypeString(
139 sync_pb::CommitResponse::ResponseType response_type
) {
140 ASSERT_ENUM_BOUNDS(sync_pb::CommitResponse
, ResponseType
, SUCCESS
,
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
);
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
);
176 const char* GetActionString(sync_pb::SyncEnums::Action action
) {
177 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums
, Action
,
178 UPGRADE_CLIENT
, UNKNOWN_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
);
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
);
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
);
217 const char* GetWalletCardStatusString(
218 sync_pb::WalletMaskedCreditCard::WalletCardStatus wallet_card_status
) {
219 switch (wallet_card_status
) {
220 ENUM_CASE(sync_pb::WalletMaskedCreditCard
, VALID
);
221 ENUM_CASE(sync_pb::WalletMaskedCreditCard
, EXPIRED
);
227 const char* GetWalletCardTypeString(
228 sync_pb::WalletMaskedCreditCard::WalletCardType wallet_card_type
) {
229 switch (wallet_card_type
) {
230 ENUM_CASE(sync_pb::WalletMaskedCreditCard
, UNKNOWN
);
231 ENUM_CASE(sync_pb::WalletMaskedCreditCard
, AMEX
);
232 ENUM_CASE(sync_pb::WalletMaskedCreditCard
, DISCOVER
);
233 ENUM_CASE(sync_pb::WalletMaskedCreditCard
, JCB
);
234 ENUM_CASE(sync_pb::WalletMaskedCreditCard
, MAESTRO
);
235 ENUM_CASE(sync_pb::WalletMaskedCreditCard
, MASTER_CARD
);
236 ENUM_CASE(sync_pb::WalletMaskedCreditCard
, SOLO
);
237 ENUM_CASE(sync_pb::WalletMaskedCreditCard
, SWITCH
);
238 ENUM_CASE(sync_pb::WalletMaskedCreditCard
, VISA
);
244 const char* GetDeviceTypeString(
245 sync_pb::SyncEnums::DeviceType device_type
) {
246 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums
, DeviceType
, TYPE_WIN
, TYPE_TABLET
);
247 switch (device_type
) {
248 ENUM_CASE(sync_pb::SyncEnums
, TYPE_WIN
);
249 ENUM_CASE(sync_pb::SyncEnums
, TYPE_MAC
);
250 ENUM_CASE(sync_pb::SyncEnums
, TYPE_LINUX
);
251 ENUM_CASE(sync_pb::SyncEnums
, TYPE_CROS
);
252 ENUM_CASE(sync_pb::SyncEnums
, TYPE_OTHER
);
253 ENUM_CASE(sync_pb::SyncEnums
, TYPE_PHONE
);
254 ENUM_CASE(sync_pb::SyncEnums
, TYPE_TABLET
);
260 const char* GetFaviconTypeString(
261 sync_pb::SessionTab::FaviconType favicon_type
) {
262 ASSERT_ENUM_BOUNDS(sync_pb::SessionTab
, FaviconType
, TYPE_WEB_FAVICON
,
264 switch (favicon_type
) {
265 ENUM_CASE(sync_pb::SessionTab
, TYPE_WEB_FAVICON
);
271 const char* PassphraseTypeString(
272 sync_pb::NigoriSpecifics::PassphraseType type
) {
273 ASSERT_ENUM_BOUNDS(sync_pb::NigoriSpecifics
, PassphraseType
,
274 IMPLICIT_PASSPHRASE
, CUSTOM_PASSPHRASE
);
276 ENUM_CASE(sync_pb::NigoriSpecifics
, IMPLICIT_PASSPHRASE
);
277 ENUM_CASE(sync_pb::NigoriSpecifics
, KEYSTORE_PASSPHRASE
);
278 ENUM_CASE(sync_pb::NigoriSpecifics
, FROZEN_IMPLICIT_PASSPHRASE
);
279 ENUM_CASE(sync_pb::NigoriSpecifics
, CUSTOM_PASSPHRASE
);
285 const char* SingletonDebugEventTypeString(
286 sync_pb::SyncEnums::SingletonDebugEventType type
) {
287 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums
, SingletonDebugEventType
,
288 CONNECTION_STATUS_CHANGE
, BOOTSTRAP_TOKEN_UPDATED
);
290 ENUM_CASE(sync_pb::SyncEnums
, CONNECTION_STATUS_CHANGE
);
291 ENUM_CASE(sync_pb::SyncEnums
, UPDATED_TOKEN
);
292 ENUM_CASE(sync_pb::SyncEnums
, PASSPHRASE_REQUIRED
);
293 ENUM_CASE(sync_pb::SyncEnums
, PASSPHRASE_ACCEPTED
);
294 ENUM_CASE(sync_pb::SyncEnums
, INITIALIZATION_COMPLETE
);
295 ENUM_CASE(sync_pb::SyncEnums
, STOP_SYNCING_PERMANENTLY
);
296 ENUM_CASE(sync_pb::SyncEnums
, ENCRYPTION_COMPLETE
);
297 ENUM_CASE(sync_pb::SyncEnums
, ACTIONABLE_ERROR
);
298 ENUM_CASE(sync_pb::SyncEnums
, ENCRYPTED_TYPES_CHANGED
);
299 ENUM_CASE(sync_pb::SyncEnums
, PASSPHRASE_TYPE_CHANGED
);
300 ENUM_CASE(sync_pb::SyncEnums
, KEYSTORE_TOKEN_UPDATED
);
301 ENUM_CASE(sync_pb::SyncEnums
, CONFIGURE_COMPLETE
);
302 ENUM_CASE(sync_pb::SyncEnums
, BOOTSTRAP_TOKEN_UPDATED
);
308 const char* GetBlockedStateString(
309 sync_pb::TabNavigation::BlockedState state
) {
310 ASSERT_ENUM_BOUNDS(sync_pb::TabNavigation
, BlockedState
,
311 STATE_ALLOWED
, STATE_BLOCKED
);
313 ENUM_CASE(sync_pb::TabNavigation
, STATE_ALLOWED
);
314 ENUM_CASE(sync_pb::TabNavigation
, STATE_BLOCKED
);
320 #undef ASSERT_ENUM_BOUNDS
323 } // namespace syncer