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 #include "sync/protocol/sync_protocol_error.h" 6 7 #include <string> 8 9 #include "base/logging.h" 10 #include "base/values.h" 11 12 namespace syncer { 13 #define ENUM_CASE(x) case x: return #x; break; 14 GetSyncErrorTypeString(SyncProtocolErrorType type)15const char* GetSyncErrorTypeString(SyncProtocolErrorType type) { 16 switch (type) { 17 ENUM_CASE(SYNC_SUCCESS); 18 ENUM_CASE(NOT_MY_BIRTHDAY); 19 ENUM_CASE(THROTTLED); 20 ENUM_CASE(CLEAR_PENDING); 21 ENUM_CASE(TRANSIENT_ERROR); 22 ENUM_CASE(NON_RETRIABLE_ERROR); 23 ENUM_CASE(MIGRATION_DONE); 24 ENUM_CASE(INVALID_CREDENTIAL); 25 ENUM_CASE(DISABLED_BY_ADMIN); 26 ENUM_CASE(USER_ROLLBACK); 27 ENUM_CASE(UNKNOWN_ERROR); 28 } 29 NOTREACHED(); 30 return ""; 31 } 32 GetClientActionString(ClientAction action)33const char* GetClientActionString(ClientAction action) { 34 switch (action) { 35 ENUM_CASE(UPGRADE_CLIENT); 36 ENUM_CASE(CLEAR_USER_DATA_AND_RESYNC); 37 ENUM_CASE(ENABLE_SYNC_ON_ACCOUNT); 38 ENUM_CASE(STOP_AND_RESTART_SYNC); 39 ENUM_CASE(DISABLE_SYNC_ON_CLIENT); 40 ENUM_CASE(STOP_SYNC_FOR_DISABLED_ACCOUNT); 41 ENUM_CASE(DISABLE_SYNC_AND_ROLLBACK); 42 ENUM_CASE(ROLLBACK_DONE); 43 ENUM_CASE(UNKNOWN_ACTION); 44 } 45 NOTREACHED(); 46 return ""; 47 } 48 SyncProtocolError()49SyncProtocolError::SyncProtocolError() 50 : error_type(UNKNOWN_ERROR), 51 action(UNKNOWN_ACTION) { 52 } 53 ~SyncProtocolError()54SyncProtocolError::~SyncProtocolError() { 55 } 56 ToValue() const57base::DictionaryValue* SyncProtocolError::ToValue() const { 58 base::DictionaryValue* value = new base::DictionaryValue(); 59 value->SetString("ErrorType", 60 GetSyncErrorTypeString(error_type)); 61 value->SetString("ErrorDescription", error_description); 62 value->SetString("url", url); 63 value->SetString("action", GetClientActionString(action)); 64 return value; 65 } 66 67 } // namespace syncer 68 69