Add a constructor that takes only the "interesting" args (basically the args that...
[chromium-blink-merge.git] / sync / protocol / proto_enum_conversions.cc
blobd80b4e31ad955c6b6398f25e8b228aef1d6fe73c
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, CHAIN_END);
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, START_PAGE);
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);
51 ENUM_CASE(sync_pb::SyncEnums, CHAIN_START);
52 ENUM_CASE(sync_pb::SyncEnums, CHAIN_END);
54 NOTREACHED();
55 return "";
58 const char* GetPageTransitionQualifierString(
59 sync_pb::SyncEnums::PageTransitionQualifier
60 page_transition_qualifier) {
61 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, PageTransitionQualifier,
62 CLIENT_REDIRECT, SERVER_REDIRECT);
63 switch (page_transition_qualifier) {
64 ENUM_CASE(sync_pb::SyncEnums, CLIENT_REDIRECT);
65 ENUM_CASE(sync_pb::SyncEnums, SERVER_REDIRECT);
67 NOTREACHED();
68 return "";
71 const char* GetUpdatesSourceString(
72 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source) {
73 ASSERT_ENUM_BOUNDS(sync_pb::GetUpdatesCallerInfo, GetUpdatesSource,
74 UNKNOWN, DATATYPE_REFRESH);
75 switch (updates_source) {
76 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, UNKNOWN);
77 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, FIRST_UPDATE);
78 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, LOCAL);
79 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, NOTIFICATION);
80 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, PERIODIC);
81 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, SYNC_CYCLE_CONTINUATION);
82 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, NEWLY_SUPPORTED_DATATYPE);
83 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, MIGRATION);
84 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, NEW_CLIENT);
85 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, RECONFIGURATION);
86 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, DATATYPE_REFRESH);
88 NOTREACHED();
89 return "";
92 const char* GetResponseTypeString(
93 sync_pb::CommitResponse::ResponseType response_type) {
94 ASSERT_ENUM_BOUNDS(sync_pb::CommitResponse, ResponseType, SUCCESS,
95 TRANSIENT_ERROR);
96 switch (response_type) {
97 ENUM_CASE(sync_pb::CommitResponse, SUCCESS);
98 ENUM_CASE(sync_pb::CommitResponse, CONFLICT);
99 ENUM_CASE(sync_pb::CommitResponse, RETRY);
100 ENUM_CASE(sync_pb::CommitResponse, INVALID_MESSAGE);
101 ENUM_CASE(sync_pb::CommitResponse, OVER_QUOTA);
102 ENUM_CASE(sync_pb::CommitResponse, TRANSIENT_ERROR);
104 NOTREACHED();
105 return "";
108 const char* GetErrorTypeString(sync_pb::SyncEnums::ErrorType error_type) {
109 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, ErrorType, SUCCESS, UNKNOWN);
110 switch (error_type) {
111 ENUM_CASE(sync_pb::SyncEnums, SUCCESS);
112 ENUM_CASE(sync_pb::SyncEnums, ACCESS_DENIED);
113 ENUM_CASE(sync_pb::SyncEnums, NOT_MY_BIRTHDAY);
114 ENUM_CASE(sync_pb::SyncEnums, THROTTLED);
115 ENUM_CASE(sync_pb::SyncEnums, AUTH_EXPIRED);
116 ENUM_CASE(sync_pb::SyncEnums, USER_NOT_ACTIVATED);
117 ENUM_CASE(sync_pb::SyncEnums, AUTH_INVALID);
118 ENUM_CASE(sync_pb::SyncEnums, CLEAR_PENDING);
119 ENUM_CASE(sync_pb::SyncEnums, TRANSIENT_ERROR);
120 ENUM_CASE(sync_pb::SyncEnums, MIGRATION_DONE);
121 ENUM_CASE(sync_pb::SyncEnums, UNKNOWN);
123 NOTREACHED();
124 return "";
127 const char* GetActionString(sync_pb::SyncEnums::Action action) {
128 ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, Action,
129 UPGRADE_CLIENT, UNKNOWN_ACTION);
130 switch (action) {
131 ENUM_CASE(sync_pb::SyncEnums, UPGRADE_CLIENT);
132 ENUM_CASE(sync_pb::SyncEnums, CLEAR_USER_DATA_AND_RESYNC);
133 ENUM_CASE(sync_pb::SyncEnums, ENABLE_SYNC_ON_ACCOUNT);
134 ENUM_CASE(sync_pb::SyncEnums, STOP_AND_RESTART_SYNC);
135 ENUM_CASE(sync_pb::SyncEnums, DISABLE_SYNC_ON_CLIENT);
136 ENUM_CASE(sync_pb::SyncEnums, UNKNOWN_ACTION);
138 NOTREACHED();
139 return "";
143 const char* GetDeviceTypeString(
144 sync_pb::SessionHeader::DeviceType device_type) {
145 ASSERT_ENUM_BOUNDS(sync_pb::SessionHeader, DeviceType, TYPE_WIN, TYPE_TABLET);
146 switch (device_type) {
147 ENUM_CASE(sync_pb::SessionHeader, TYPE_WIN);
148 ENUM_CASE(sync_pb::SessionHeader, TYPE_MAC);
149 ENUM_CASE(sync_pb::SessionHeader, TYPE_LINUX);
150 ENUM_CASE(sync_pb::SessionHeader, TYPE_CROS);
151 ENUM_CASE(sync_pb::SessionHeader, TYPE_OTHER);
152 ENUM_CASE(sync_pb::SessionHeader, TYPE_PHONE);
153 ENUM_CASE(sync_pb::SessionHeader, TYPE_TABLET);
155 NOTREACHED();
156 return "";
159 const char* GetFaviconTypeString(
160 sync_pb::SessionTab::FaviconType favicon_type) {
161 ASSERT_ENUM_BOUNDS(sync_pb::SessionTab, FaviconType, TYPE_WEB_FAVICON,
162 TYPE_WEB_FAVICON);
163 switch (favicon_type) {
164 ENUM_CASE(sync_pb::SessionTab, TYPE_WEB_FAVICON);
166 NOTREACHED();
167 return "";
170 #undef ASSERT_ENUM_BOUNDS
171 #undef ENUM_CASE
173 } // namespace syncer