Get foreground tab on Android
[chromium-blink-merge.git] / sync / protocol / proto_enum_conversions.cc
blob3183633d6e2d12452e3866662aa61f0ed9c4446d
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* GetBrowserTypeString(
24 sync_pb::SessionWindow::BrowserType browser_type) {
25 ASSERT_ENUM_BOUNDS(sync_pb::SessionWindow, BrowserType,
26 TYPE_TABBED, TYPE_POPUP);
27 switch (browser_type) {
28 ENUM_CASE(sync_pb::SessionWindow, TYPE_TABBED);
29 ENUM_CASE(sync_pb::SessionWindow, TYPE_POPUP);
31 NOTREACHED();
32 return "";
35 const char* GetPageTransitionString(
36 sync_pb::SyncEnums::PageTransition page_transition) {
37 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, PageTransition,
38 LINK, KEYWORD_GENERATED);
39 switch (page_transition) {
40 ENUM_CASE(sync_pb::SyncEnums, LINK);
41 ENUM_CASE(sync_pb::SyncEnums, TYPED);
42 ENUM_CASE(sync_pb::SyncEnums, AUTO_BOOKMARK);
43 ENUM_CASE(sync_pb::SyncEnums, AUTO_SUBFRAME);
44 ENUM_CASE(sync_pb::SyncEnums, MANUAL_SUBFRAME);
45 ENUM_CASE(sync_pb::SyncEnums, GENERATED);
46 ENUM_CASE(sync_pb::SyncEnums, AUTO_TOPLEVEL);
47 ENUM_CASE(sync_pb::SyncEnums, FORM_SUBMIT);
48 ENUM_CASE(sync_pb::SyncEnums, RELOAD);
49 ENUM_CASE(sync_pb::SyncEnums, KEYWORD);
50 ENUM_CASE(sync_pb::SyncEnums, KEYWORD_GENERATED);
52 NOTREACHED();
53 return "";
56 const char* GetPageTransitionRedirectTypeString(
57 sync_pb::SyncEnums::PageTransitionRedirectType
58 page_transition_qualifier) {
59 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, PageTransitionRedirectType,
60 CLIENT_REDIRECT, SERVER_REDIRECT);
61 switch (page_transition_qualifier) {
62 ENUM_CASE(sync_pb::SyncEnums, CLIENT_REDIRECT);
63 ENUM_CASE(sync_pb::SyncEnums, SERVER_REDIRECT);
65 NOTREACHED();
66 return "";
69 const char* GetUpdatesSourceString(
70 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source) {
71 ASSERT_ENUM_BOUNDS(sync_pb::GetUpdatesCallerInfo, GetUpdatesSource,
72 UNKNOWN, DATATYPE_REFRESH);
73 switch (updates_source) {
74 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, UNKNOWN);
75 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, FIRST_UPDATE);
76 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, LOCAL);
77 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, NOTIFICATION);
78 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, PERIODIC);
79 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, SYNC_CYCLE_CONTINUATION);
80 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, NEWLY_SUPPORTED_DATATYPE);
81 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, MIGRATION);
82 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, NEW_CLIENT);
83 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, RECONFIGURATION);
84 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, DATATYPE_REFRESH);
86 NOTREACHED();
87 return "";
90 const char* GetUpdatesOriginString(
91 sync_pb::SyncEnums::GetUpdatesOrigin origin) {
92 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, GetUpdatesOrigin,
93 UNKNOWN_ORIGIN, GU_TRIGGER);
94 switch (origin) {
95 ENUM_CASE(sync_pb::SyncEnums, UNKNOWN_ORIGIN);
96 ENUM_CASE(sync_pb::SyncEnums, PERIODIC);
97 ENUM_CASE(sync_pb::SyncEnums, NEWLY_SUPPORTED_DATATYPE);
98 ENUM_CASE(sync_pb::SyncEnums, MIGRATION);
99 ENUM_CASE(sync_pb::SyncEnums, NEW_CLIENT);
100 ENUM_CASE(sync_pb::SyncEnums, RECONFIGURATION);
101 ENUM_CASE(sync_pb::SyncEnums, GU_TRIGGER);
103 NOTREACHED();
104 return "";
107 const char* GetResponseTypeString(
108 sync_pb::CommitResponse::ResponseType response_type) {
109 ASSERT_ENUM_BOUNDS(sync_pb::CommitResponse, ResponseType, SUCCESS,
110 TRANSIENT_ERROR);
111 switch (response_type) {
112 ENUM_CASE(sync_pb::CommitResponse, SUCCESS);
113 ENUM_CASE(sync_pb::CommitResponse, CONFLICT);
114 ENUM_CASE(sync_pb::CommitResponse, RETRY);
115 ENUM_CASE(sync_pb::CommitResponse, INVALID_MESSAGE);
116 ENUM_CASE(sync_pb::CommitResponse, OVER_QUOTA);
117 ENUM_CASE(sync_pb::CommitResponse, TRANSIENT_ERROR);
119 NOTREACHED();
120 return "";
123 const char* GetErrorTypeString(sync_pb::SyncEnums::ErrorType error_type) {
124 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, ErrorType, SUCCESS, UNKNOWN);
125 switch (error_type) {
126 ENUM_CASE(sync_pb::SyncEnums, SUCCESS);
127 ENUM_CASE(sync_pb::SyncEnums, ACCESS_DENIED);
128 ENUM_CASE(sync_pb::SyncEnums, NOT_MY_BIRTHDAY);
129 ENUM_CASE(sync_pb::SyncEnums, THROTTLED);
130 ENUM_CASE(sync_pb::SyncEnums, AUTH_EXPIRED);
131 ENUM_CASE(sync_pb::SyncEnums, USER_NOT_ACTIVATED);
132 ENUM_CASE(sync_pb::SyncEnums, AUTH_INVALID);
133 ENUM_CASE(sync_pb::SyncEnums, CLEAR_PENDING);
134 ENUM_CASE(sync_pb::SyncEnums, TRANSIENT_ERROR);
135 ENUM_CASE(sync_pb::SyncEnums, MIGRATION_DONE);
136 ENUM_CASE(sync_pb::SyncEnums, DISABLED_BY_ADMIN);
137 ENUM_CASE(sync_pb::SyncEnums, UNKNOWN);
139 NOTREACHED();
140 return "";
143 const char* GetActionString(sync_pb::SyncEnums::Action action) {
144 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, Action,
145 UPGRADE_CLIENT, UNKNOWN_ACTION);
146 switch (action) {
147 ENUM_CASE(sync_pb::SyncEnums, UPGRADE_CLIENT);
148 ENUM_CASE(sync_pb::SyncEnums, CLEAR_USER_DATA_AND_RESYNC);
149 ENUM_CASE(sync_pb::SyncEnums, ENABLE_SYNC_ON_ACCOUNT);
150 ENUM_CASE(sync_pb::SyncEnums, STOP_AND_RESTART_SYNC);
151 ENUM_CASE(sync_pb::SyncEnums, DISABLE_SYNC_ON_CLIENT);
152 ENUM_CASE(sync_pb::SyncEnums, UNKNOWN_ACTION);
154 NOTREACHED();
155 return "";
159 const char* GetDeviceTypeString(
160 sync_pb::SyncEnums::DeviceType device_type) {
161 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, DeviceType, TYPE_WIN, TYPE_TABLET);
162 switch (device_type) {
163 ENUM_CASE(sync_pb::SyncEnums, TYPE_WIN);
164 ENUM_CASE(sync_pb::SyncEnums, TYPE_MAC);
165 ENUM_CASE(sync_pb::SyncEnums, TYPE_LINUX);
166 ENUM_CASE(sync_pb::SyncEnums, TYPE_CROS);
167 ENUM_CASE(sync_pb::SyncEnums, TYPE_OTHER);
168 ENUM_CASE(sync_pb::SyncEnums, TYPE_PHONE);
169 ENUM_CASE(sync_pb::SyncEnums, TYPE_TABLET);
171 NOTREACHED();
172 return "";
175 const char* GetFaviconTypeString(
176 sync_pb::SessionTab::FaviconType favicon_type) {
177 ASSERT_ENUM_BOUNDS(sync_pb::SessionTab, FaviconType, TYPE_WEB_FAVICON,
178 TYPE_WEB_FAVICON);
179 switch (favicon_type) {
180 ENUM_CASE(sync_pb::SessionTab, TYPE_WEB_FAVICON);
182 NOTREACHED();
183 return "";
186 const char* PassphraseTypeString(
187 sync_pb::NigoriSpecifics::PassphraseType type) {
188 ASSERT_ENUM_BOUNDS(sync_pb::NigoriSpecifics, PassphraseType,
189 IMPLICIT_PASSPHRASE, CUSTOM_PASSPHRASE);
190 switch (type) {
191 ENUM_CASE(sync_pb::NigoriSpecifics, IMPLICIT_PASSPHRASE);
192 ENUM_CASE(sync_pb::NigoriSpecifics, KEYSTORE_PASSPHRASE);
193 ENUM_CASE(sync_pb::NigoriSpecifics, FROZEN_IMPLICIT_PASSPHRASE);
194 ENUM_CASE(sync_pb::NigoriSpecifics, CUSTOM_PASSPHRASE);
196 NOTREACHED();
197 return "";
200 const char* SingletonEventTypeString(
201 sync_pb::DebugEventInfo::SingletonEventType type) {
202 ASSERT_ENUM_BOUNDS(sync_pb::DebugEventInfo, SingletonEventType,
203 CONNECTION_STATUS_CHANGE, BOOTSTRAP_TOKEN_UPDATED);
204 switch (type) {
205 ENUM_CASE(sync_pb::DebugEventInfo, CONNECTION_STATUS_CHANGE);
206 ENUM_CASE(sync_pb::DebugEventInfo, UPDATED_TOKEN);
207 ENUM_CASE(sync_pb::DebugEventInfo, PASSPHRASE_REQUIRED);
208 ENUM_CASE(sync_pb::DebugEventInfo, PASSPHRASE_ACCEPTED);
209 ENUM_CASE(sync_pb::DebugEventInfo, INITIALIZATION_COMPLETE);
210 ENUM_CASE(sync_pb::DebugEventInfo, STOP_SYNCING_PERMANENTLY);
211 ENUM_CASE(sync_pb::DebugEventInfo, ENCRYPTION_COMPLETE);
212 ENUM_CASE(sync_pb::DebugEventInfo, ACTIONABLE_ERROR);
213 ENUM_CASE(sync_pb::DebugEventInfo, ENCRYPTED_TYPES_CHANGED);
214 ENUM_CASE(sync_pb::DebugEventInfo, PASSPHRASE_TYPE_CHANGED);
215 ENUM_CASE(sync_pb::DebugEventInfo, KEYSTORE_TOKEN_UPDATED);
216 ENUM_CASE(sync_pb::DebugEventInfo, CONFIGURE_COMPLETE);
217 ENUM_CASE(sync_pb::DebugEventInfo, BOOTSTRAP_TOKEN_UPDATED);
219 NOTREACHED();
220 return "";
223 const char* GetBlockedStateString(
224 sync_pb::TabNavigation::BlockedState state) {
225 ASSERT_ENUM_BOUNDS(sync_pb::TabNavigation, BlockedState,
226 STATE_ALLOWED, STATE_BLOCKED);
227 switch (state) {
228 ENUM_CASE(sync_pb::TabNavigation, STATE_ALLOWED);
229 ENUM_CASE(sync_pb::TabNavigation, STATE_BLOCKED);
231 NOTREACHED();
232 return "";
235 #undef ASSERT_ENUM_BOUNDS
236 #undef ENUM_CASE
238 } // namespace syncer