OLD | NEW |
| (Empty) |
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. | |
4 | |
5 // Keep this file in sync with the .proto files in this directory. | |
6 | |
7 #include "chrome/browser/sync/protocol/proto_enum_conversions.h" | |
8 | |
9 #include "base/basictypes.h" | |
10 #include "base/logging.h" | |
11 | |
12 namespace browser_sync { | |
13 | |
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); | |
19 | |
20 #define ENUM_CASE(enum_parent, enum_value) \ | |
21 case enum_parent::enum_value: return #enum_value | |
22 | |
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); | |
30 } | |
31 NOTREACHED(); | |
32 return ""; | |
33 } | |
34 | |
35 const char* GetPageTransitionString( | |
36 sync_pb::TabNavigation::PageTransition page_transition) { | |
37 ASSERT_ENUM_BOUNDS(sync_pb::TabNavigation, PageTransition, | |
38 LINK, CHAIN_END); | |
39 switch (page_transition) { | |
40 ENUM_CASE(sync_pb::TabNavigation, LINK); | |
41 ENUM_CASE(sync_pb::TabNavigation, TYPED); | |
42 ENUM_CASE(sync_pb::TabNavigation, AUTO_BOOKMARK); | |
43 ENUM_CASE(sync_pb::TabNavigation, AUTO_SUBFRAME); | |
44 ENUM_CASE(sync_pb::TabNavigation, MANUAL_SUBFRAME); | |
45 ENUM_CASE(sync_pb::TabNavigation, GENERATED); | |
46 ENUM_CASE(sync_pb::TabNavigation, START_PAGE); | |
47 ENUM_CASE(sync_pb::TabNavigation, FORM_SUBMIT); | |
48 ENUM_CASE(sync_pb::TabNavigation, RELOAD); | |
49 ENUM_CASE(sync_pb::TabNavigation, KEYWORD); | |
50 ENUM_CASE(sync_pb::TabNavigation, KEYWORD_GENERATED); | |
51 ENUM_CASE(sync_pb::TabNavigation, CHAIN_START); | |
52 ENUM_CASE(sync_pb::TabNavigation, CHAIN_END); | |
53 } | |
54 NOTREACHED(); | |
55 return ""; | |
56 } | |
57 | |
58 const char* GetPageTransitionQualifierString( | |
59 sync_pb::TabNavigation::PageTransitionQualifier | |
60 page_transition_qualifier) { | |
61 ASSERT_ENUM_BOUNDS(sync_pb::TabNavigation, PageTransitionQualifier, | |
62 CLIENT_REDIRECT, SERVER_REDIRECT); | |
63 switch (page_transition_qualifier) { | |
64 ENUM_CASE(sync_pb::TabNavigation, CLIENT_REDIRECT); | |
65 ENUM_CASE(sync_pb::TabNavigation, SERVER_REDIRECT); | |
66 } | |
67 NOTREACHED(); | |
68 return ""; | |
69 } | |
70 | |
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, CLEAR_PRIVATE_DATA); | |
83 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, NEWLY_SUPPORTED_DATATYPE); | |
84 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, MIGRATION); | |
85 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, NEW_CLIENT); | |
86 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, RECONFIGURATION); | |
87 ENUM_CASE(sync_pb::GetUpdatesCallerInfo, DATATYPE_REFRESH); | |
88 } | |
89 NOTREACHED(); | |
90 return ""; | |
91 } | |
92 | |
93 const char* GetDeviceTypeString( | |
94 sync_pb::SessionHeader::DeviceType device_type) { | |
95 ASSERT_ENUM_BOUNDS(sync_pb::SessionHeader, DeviceType, TYPE_WIN, TYPE_TABLET); | |
96 switch (device_type) { | |
97 ENUM_CASE(sync_pb::SessionHeader, TYPE_WIN); | |
98 ENUM_CASE(sync_pb::SessionHeader, TYPE_MAC); | |
99 ENUM_CASE(sync_pb::SessionHeader, TYPE_LINUX); | |
100 ENUM_CASE(sync_pb::SessionHeader, TYPE_CROS); | |
101 ENUM_CASE(sync_pb::SessionHeader, TYPE_OTHER); | |
102 ENUM_CASE(sync_pb::SessionHeader, TYPE_PHONE); | |
103 ENUM_CASE(sync_pb::SessionHeader, TYPE_TABLET); | |
104 } | |
105 NOTREACHED(); | |
106 return ""; | |
107 } | |
108 | |
109 #undef ASSERT_ENUM_BOUNDS | |
110 #undef ENUM_CASE | |
111 | |
112 } // namespace | |
OLD | NEW |