Home | History | Annotate | Download | only in protocol
      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 "sync/protocol/proto_enum_conversions.h"
      8 
      9 #include "base/basictypes.h"
     10 #include "base/logging.h"
     11 
     12 namespace syncer {
     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* 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);
     32   }
     33   NOTREACHED();
     34   return "";
     35 }
     36 
     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);
     44   }
     45   NOTREACHED();
     46   return "";
     47 }
     48 
     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);
     65   }
     66   NOTREACHED();
     67   return "";
     68 }
     69 
     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);
     78   }
     79   NOTREACHED();
     80   return "";
     81 }
     82 
     83 const char* GetUpdatesSourceString(
     84     sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source) {
     85   ASSERT_ENUM_BOUNDS(sync_pb::GetUpdatesCallerInfo, GetUpdatesSource,
     86                      UNKNOWN, DATATYPE_REFRESH);
     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   }
    100   NOTREACHED();
    101   return "";
    102 }
    103 
    104 const char* GetUpdatesOriginString(
    105     sync_pb::SyncEnums::GetUpdatesOrigin origin) {
    106   ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, GetUpdatesOrigin,
    107                      UNKNOWN_ORIGIN, GU_TRIGGER);
    108   switch (origin) {
    109     ENUM_CASE(sync_pb::SyncEnums, UNKNOWN_ORIGIN);
    110     ENUM_CASE(sync_pb::SyncEnums, PERIODIC);
    111     ENUM_CASE(sync_pb::SyncEnums, NEWLY_SUPPORTED_DATATYPE);
    112     ENUM_CASE(sync_pb::SyncEnums, MIGRATION);
    113     ENUM_CASE(sync_pb::SyncEnums, NEW_CLIENT);
    114     ENUM_CASE(sync_pb::SyncEnums, RECONFIGURATION);
    115     ENUM_CASE(sync_pb::SyncEnums, GU_TRIGGER);
    116   }
    117   NOTREACHED();
    118   return "";
    119 }
    120 
    121 const char* GetResponseTypeString(
    122     sync_pb::CommitResponse::ResponseType response_type) {
    123   ASSERT_ENUM_BOUNDS(sync_pb::CommitResponse, ResponseType, SUCCESS,
    124                      TRANSIENT_ERROR);
    125   switch (response_type) {
    126     ENUM_CASE(sync_pb::CommitResponse, SUCCESS);
    127     ENUM_CASE(sync_pb::CommitResponse, CONFLICT);
    128     ENUM_CASE(sync_pb::CommitResponse, RETRY);
    129     ENUM_CASE(sync_pb::CommitResponse, INVALID_MESSAGE);
    130     ENUM_CASE(sync_pb::CommitResponse, OVER_QUOTA);
    131     ENUM_CASE(sync_pb::CommitResponse, TRANSIENT_ERROR);
    132   }
    133   NOTREACHED();
    134   return "";
    135 }
    136 
    137 const char* GetErrorTypeString(sync_pb::SyncEnums::ErrorType error_type) {
    138   ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, ErrorType, SUCCESS, UNKNOWN);
    139   switch (error_type) {
    140     ENUM_CASE(sync_pb::SyncEnums, SUCCESS);
    141     ENUM_CASE(sync_pb::SyncEnums, ACCESS_DENIED);
    142     ENUM_CASE(sync_pb::SyncEnums, NOT_MY_BIRTHDAY);
    143     ENUM_CASE(sync_pb::SyncEnums, THROTTLED);
    144     ENUM_CASE(sync_pb::SyncEnums, AUTH_EXPIRED);
    145     ENUM_CASE(sync_pb::SyncEnums, USER_NOT_ACTIVATED);
    146     ENUM_CASE(sync_pb::SyncEnums, AUTH_INVALID);
    147     ENUM_CASE(sync_pb::SyncEnums, CLEAR_PENDING);
    148     ENUM_CASE(sync_pb::SyncEnums, TRANSIENT_ERROR);
    149     ENUM_CASE(sync_pb::SyncEnums, MIGRATION_DONE);
    150     ENUM_CASE(sync_pb::SyncEnums, DISABLED_BY_ADMIN);
    151     ENUM_CASE(sync_pb::SyncEnums, UNKNOWN);
    152   }
    153   NOTREACHED();
    154   return "";
    155 }
    156 
    157 const char* GetActionString(sync_pb::SyncEnums::Action action) {
    158   ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, Action,
    159                      UPGRADE_CLIENT, UNKNOWN_ACTION);
    160   switch (action) {
    161     ENUM_CASE(sync_pb::SyncEnums, UPGRADE_CLIENT);
    162     ENUM_CASE(sync_pb::SyncEnums, CLEAR_USER_DATA_AND_RESYNC);
    163     ENUM_CASE(sync_pb::SyncEnums, ENABLE_SYNC_ON_ACCOUNT);
    164     ENUM_CASE(sync_pb::SyncEnums, STOP_AND_RESTART_SYNC);
    165     ENUM_CASE(sync_pb::SyncEnums, DISABLE_SYNC_ON_CLIENT);
    166     ENUM_CASE(sync_pb::SyncEnums, UNKNOWN_ACTION);
    167   }
    168   NOTREACHED();
    169   return "";
    170 
    171 }
    172 
    173 const char* GetDeviceTypeString(
    174     sync_pb::SyncEnums::DeviceType device_type) {
    175   ASSERT_ENUM_BOUNDS(sync_pb::SyncEnums, DeviceType, TYPE_WIN, TYPE_TABLET);
    176   switch (device_type) {
    177     ENUM_CASE(sync_pb::SyncEnums, TYPE_WIN);
    178     ENUM_CASE(sync_pb::SyncEnums, TYPE_MAC);
    179     ENUM_CASE(sync_pb::SyncEnums, TYPE_LINUX);
    180     ENUM_CASE(sync_pb::SyncEnums, TYPE_CROS);
    181     ENUM_CASE(sync_pb::SyncEnums, TYPE_OTHER);
    182     ENUM_CASE(sync_pb::SyncEnums, TYPE_PHONE);
    183     ENUM_CASE(sync_pb::SyncEnums, TYPE_TABLET);
    184   }
    185   NOTREACHED();
    186   return "";
    187 }
    188 
    189 const char* GetFaviconTypeString(
    190     sync_pb::SessionTab::FaviconType favicon_type) {
    191   ASSERT_ENUM_BOUNDS(sync_pb::SessionTab, FaviconType, TYPE_WEB_FAVICON,
    192                      TYPE_WEB_FAVICON);
    193   switch (favicon_type) {
    194     ENUM_CASE(sync_pb::SessionTab, TYPE_WEB_FAVICON);
    195   }
    196   NOTREACHED();
    197   return "";
    198 }
    199 
    200 const char* PassphraseTypeString(
    201     sync_pb::NigoriSpecifics::PassphraseType type) {
    202   ASSERT_ENUM_BOUNDS(sync_pb::NigoriSpecifics, PassphraseType,
    203                      IMPLICIT_PASSPHRASE, CUSTOM_PASSPHRASE);
    204   switch (type) {
    205     ENUM_CASE(sync_pb::NigoriSpecifics, IMPLICIT_PASSPHRASE);
    206     ENUM_CASE(sync_pb::NigoriSpecifics, KEYSTORE_PASSPHRASE);
    207     ENUM_CASE(sync_pb::NigoriSpecifics, FROZEN_IMPLICIT_PASSPHRASE);
    208     ENUM_CASE(sync_pb::NigoriSpecifics, CUSTOM_PASSPHRASE);
    209   }
    210   NOTREACHED();
    211   return "";
    212 }
    213 
    214 const char* SingletonEventTypeString(
    215     sync_pb::DebugEventInfo::SingletonEventType type) {
    216   ASSERT_ENUM_BOUNDS(sync_pb::DebugEventInfo, SingletonEventType,
    217                      CONNECTION_STATUS_CHANGE, BOOTSTRAP_TOKEN_UPDATED);
    218   switch (type) {
    219     ENUM_CASE(sync_pb::DebugEventInfo, CONNECTION_STATUS_CHANGE);
    220     ENUM_CASE(sync_pb::DebugEventInfo, UPDATED_TOKEN);
    221     ENUM_CASE(sync_pb::DebugEventInfo, PASSPHRASE_REQUIRED);
    222     ENUM_CASE(sync_pb::DebugEventInfo, PASSPHRASE_ACCEPTED);
    223     ENUM_CASE(sync_pb::DebugEventInfo, INITIALIZATION_COMPLETE);
    224     ENUM_CASE(sync_pb::DebugEventInfo, STOP_SYNCING_PERMANENTLY);
    225     ENUM_CASE(sync_pb::DebugEventInfo, ENCRYPTION_COMPLETE);
    226     ENUM_CASE(sync_pb::DebugEventInfo, ACTIONABLE_ERROR);
    227     ENUM_CASE(sync_pb::DebugEventInfo, ENCRYPTED_TYPES_CHANGED);
    228     ENUM_CASE(sync_pb::DebugEventInfo, PASSPHRASE_TYPE_CHANGED);
    229     ENUM_CASE(sync_pb::DebugEventInfo, KEYSTORE_TOKEN_UPDATED);
    230     ENUM_CASE(sync_pb::DebugEventInfo, CONFIGURE_COMPLETE);
    231     ENUM_CASE(sync_pb::DebugEventInfo, BOOTSTRAP_TOKEN_UPDATED);
    232   }
    233   NOTREACHED();
    234   return "";
    235 }
    236 
    237 const char* GetBlockedStateString(
    238     sync_pb::TabNavigation::BlockedState state) {
    239   ASSERT_ENUM_BOUNDS(sync_pb::TabNavigation, BlockedState,
    240                      STATE_ALLOWED, STATE_BLOCKED);
    241   switch (state) {
    242     ENUM_CASE(sync_pb::TabNavigation, STATE_ALLOWED);
    243     ENUM_CASE(sync_pb::TabNavigation, STATE_BLOCKED);
    244   }
    245   NOTREACHED();
    246   return "";
    247 }
    248 
    249 #undef ASSERT_ENUM_BOUNDS
    250 #undef ENUM_CASE
    251 
    252 }  // namespace syncer
    253