[GCM] Persistence of account mappings.
[chromium-blink-merge.git] / sync / protocol / proto_enum_conversions.cc
blob213a0961b028e3d0c711bdf8911b01ec816eafa3
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 COMPILE_ASSERT(enum_parent::enum_type##_MIN == enum_parent::enum_min, \
16 enum_type##_MIN_not_##enum_min); \
17 COMPILE_ASSERT(enum_parent::enum_type##_MAX == enum_parent::enum_max, \
18 enum_type##_MAX_not_##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* GetUpdatesSourceString(
84 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source) {
85 ASSERT_ENUM_BOUNDS(sync_pb::GetUpdatesCallerInfo, GetUpdatesSource,
86 UNKNOWN, RETRY);
87 switch (updates_source) {
88 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, UNKNOWN);
89 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, FIRST_UPDATE);
90 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, LOCAL);
91 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, NOTIFICATION);
92 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, PERIODIC);
93 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, SYNC_CYCLE_CONTINUATION);
94 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, NEWLY_SUPPORTED_DATATYPE);
95 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, MIGRATION);
96 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, NEW_CLIENT);
97 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, RECONFIGURATION);
98 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, DATATYPE_REFRESH);
99 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, RETRY);
101 NOTREACHED();
102 return "";
105 const char* GetUpdatesOriginString(
106 sync_pb::SyncEnums::GetUpdatesOrigin origin) {
107 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, GetUpdatesOrigin,
108 UNKNOWN_ORIGIN, RETRY);
109 switch (origin) {
110 ENUM_CASE(sync_pb::SyncEnums, UNKNOWN_ORIGIN);
111 ENUM_CASE(sync_pb::SyncEnums, PERIODIC);
112 ENUM_CASE(sync_pb::SyncEnums, NEWLY_SUPPORTED_DATATYPE);
113 ENUM_CASE(sync_pb::SyncEnums, MIGRATION);
114 ENUM_CASE(sync_pb::SyncEnums, NEW_CLIENT);
115 ENUM_CASE(sync_pb::SyncEnums, RECONFIGURATION);
116 ENUM_CASE(sync_pb::SyncEnums, GU_TRIGGER);
117 ENUM_CASE(sync_pb::SyncEnums, RETRY);
119 NOTREACHED();
120 return "";
123 const char* GetResponseTypeString(
124 sync_pb::CommitResponse::ResponseType response_type) {
125 ASSERT_ENUM_BOUNDS(sync_pb::CommitResponse, ResponseType, SUCCESS,
126 TRANSIENT_ERROR);
127 switch (response_type) {
128 ENUM_CASE(sync_pb::CommitResponse, SUCCESS);
129 ENUM_CASE(sync_pb::CommitResponse, CONFLICT);
130 ENUM_CASE(sync_pb::CommitResponse, RETRY);
131 ENUM_CASE(sync_pb::CommitResponse, INVALID_MESSAGE);
132 ENUM_CASE(sync_pb::CommitResponse, OVER_QUOTA);
133 ENUM_CASE(sync_pb::CommitResponse, TRANSIENT_ERROR);
135 NOTREACHED();
136 return "";
139 const char* GetErrorTypeString(sync_pb::SyncEnums::ErrorType error_type) {
140 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, ErrorType, SUCCESS, UNKNOWN);
141 switch (error_type) {
142 ENUM_CASE(sync_pb::SyncEnums, SUCCESS);
143 ENUM_CASE(sync_pb::SyncEnums, ACCESS_DENIED);
144 ENUM_CASE(sync_pb::SyncEnums, NOT_MY_BIRTHDAY);
145 ENUM_CASE(sync_pb::SyncEnums, THROTTLED);
146 ENUM_CASE(sync_pb::SyncEnums, AUTH_EXPIRED);
147 ENUM_CASE(sync_pb::SyncEnums, USER_NOT_ACTIVATED);
148 ENUM_CASE(sync_pb::SyncEnums, AUTH_INVALID);
149 ENUM_CASE(sync_pb::SyncEnums, CLEAR_PENDING);
150 ENUM_CASE(sync_pb::SyncEnums, TRANSIENT_ERROR);
151 ENUM_CASE(sync_pb::SyncEnums, MIGRATION_DONE);
152 ENUM_CASE(sync_pb::SyncEnums, DISABLED_BY_ADMIN);
153 ENUM_CASE(sync_pb::SyncEnums, USER_ROLLBACK);
154 ENUM_CASE(sync_pb::SyncEnums, UNKNOWN);
156 NOTREACHED();
157 return "";
160 const char* GetActionString(sync_pb::SyncEnums::Action action) {
161 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, Action,
162 UPGRADE_CLIENT, UNKNOWN_ACTION);
163 switch (action) {
164 ENUM_CASE(sync_pb::SyncEnums, UPGRADE_CLIENT);
165 ENUM_CASE(sync_pb::SyncEnums, CLEAR_USER_DATA_AND_RESYNC);
166 ENUM_CASE(sync_pb::SyncEnums, ENABLE_SYNC_ON_ACCOUNT);
167 ENUM_CASE(sync_pb::SyncEnums, STOP_AND_RESTART_SYNC);
168 ENUM_CASE(sync_pb::SyncEnums, DISABLE_SYNC_ON_CLIENT);
169 ENUM_CASE(sync_pb::SyncEnums, UNKNOWN_ACTION);
171 NOTREACHED();
172 return "";
176 const char* GetLaunchTypeString(sync_pb::AppSpecifics::LaunchType launch_type) {
177 ASSERT_ENUM_BOUNDS(sync_pb::AppSpecifics, LaunchType, PINNED, WINDOW);
178 switch (launch_type) {
179 ENUM_CASE(sync_pb::AppSpecifics, PINNED);
180 ENUM_CASE(sync_pb::AppSpecifics, REGULAR);
181 ENUM_CASE(sync_pb::AppSpecifics, FULLSCREEN);
182 ENUM_CASE(sync_pb::AppSpecifics, WINDOW);
184 NOTREACHED();
185 return "";
188 const char* GetDeviceTypeString(
189 sync_pb::SyncEnums::DeviceType device_type) {
190 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, DeviceType, TYPE_WIN, TYPE_TABLET);
191 switch (device_type) {
192 ENUM_CASE(sync_pb::SyncEnums, TYPE_WIN);
193 ENUM_CASE(sync_pb::SyncEnums, TYPE_MAC);
194 ENUM_CASE(sync_pb::SyncEnums, TYPE_LINUX);
195 ENUM_CASE(sync_pb::SyncEnums, TYPE_CROS);
196 ENUM_CASE(sync_pb::SyncEnums, TYPE_OTHER);
197 ENUM_CASE(sync_pb::SyncEnums, TYPE_PHONE);
198 ENUM_CASE(sync_pb::SyncEnums, TYPE_TABLET);
200 NOTREACHED();
201 return "";
204 const char* GetFaviconTypeString(
205 sync_pb::SessionTab::FaviconType favicon_type) {
206 ASSERT_ENUM_BOUNDS(sync_pb::SessionTab, FaviconType, TYPE_WEB_FAVICON,
207 TYPE_WEB_FAVICON);
208 switch (favicon_type) {
209 ENUM_CASE(sync_pb::SessionTab, TYPE_WEB_FAVICON);
211 NOTREACHED();
212 return "";
215 const char* PassphraseTypeString(
216 sync_pb::NigoriSpecifics::PassphraseType type) {
217 ASSERT_ENUM_BOUNDS(sync_pb::NigoriSpecifics, PassphraseType,
218 IMPLICIT_PASSPHRASE, CUSTOM_PASSPHRASE);
219 switch (type) {
220 ENUM_CASE(sync_pb::NigoriSpecifics, IMPLICIT_PASSPHRASE);
221 ENUM_CASE(sync_pb::NigoriSpecifics, KEYSTORE_PASSPHRASE);
222 ENUM_CASE(sync_pb::NigoriSpecifics, FROZEN_IMPLICIT_PASSPHRASE);
223 ENUM_CASE(sync_pb::NigoriSpecifics, CUSTOM_PASSPHRASE);
225 NOTREACHED();
226 return "";
229 const char* SingletonDebugEventTypeString(
230 sync_pb::SyncEnums::SingletonDebugEventType type) {
231 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, SingletonDebugEventType,
232 CONNECTION_STATUS_CHANGE, BOOTSTRAP_TOKEN_UPDATED);
233 switch (type) {
234 ENUM_CASE(sync_pb::SyncEnums, CONNECTION_STATUS_CHANGE);
235 ENUM_CASE(sync_pb::SyncEnums, UPDATED_TOKEN);
236 ENUM_CASE(sync_pb::SyncEnums, PASSPHRASE_REQUIRED);
237 ENUM_CASE(sync_pb::SyncEnums, PASSPHRASE_ACCEPTED);
238 ENUM_CASE(sync_pb::SyncEnums, INITIALIZATION_COMPLETE);
239 ENUM_CASE(sync_pb::SyncEnums, STOP_SYNCING_PERMANENTLY);
240 ENUM_CASE(sync_pb::SyncEnums, ENCRYPTION_COMPLETE);
241 ENUM_CASE(sync_pb::SyncEnums, ACTIONABLE_ERROR);
242 ENUM_CASE(sync_pb::SyncEnums, ENCRYPTED_TYPES_CHANGED);
243 ENUM_CASE(sync_pb::SyncEnums, PASSPHRASE_TYPE_CHANGED);
244 ENUM_CASE(sync_pb::SyncEnums, KEYSTORE_TOKEN_UPDATED);
245 ENUM_CASE(sync_pb::SyncEnums, CONFIGURE_COMPLETE);
246 ENUM_CASE(sync_pb::SyncEnums, BOOTSTRAP_TOKEN_UPDATED);
248 NOTREACHED();
249 return "";
252 const char* GetBlockedStateString(
253 sync_pb::TabNavigation::BlockedState state) {
254 ASSERT_ENUM_BOUNDS(sync_pb::TabNavigation, BlockedState,
255 STATE_ALLOWED, STATE_BLOCKED);
256 switch (state) {
257 ENUM_CASE(sync_pb::TabNavigation, STATE_ALLOWED);
258 ENUM_CASE(sync_pb::TabNavigation, STATE_BLOCKED);
260 NOTREACHED();
261 return "";
264 #undef ASSERT_ENUM_BOUNDS
265 #undef ENUM_CASE
267 } // namespace syncer