1 // Copyright (c) 2011 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_NORMAL, TYPE_POPUP); 27 switch (browser_type) { 28 ENUM_CASE(sync_pb::SessionWindow, TYPE_NORMAL); 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, CLEAR_PRIVATE_DATA); 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 } 84 NOTREACHED(); 85 return ""; 86 } 87 88 #undef ASSERT_ENUM_BOUNDS 89 #undef ENUM_CASE 90 91 } // namespace 92