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 15 const 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(UNKNOWN_ERROR); 27 } 28 NOTREACHED(); 29 return ""; 30 } 31 32 const char* GetClientActionString(ClientAction action) { 33 switch (action) { 34 ENUM_CASE(UPGRADE_CLIENT); 35 ENUM_CASE(CLEAR_USER_DATA_AND_RESYNC); 36 ENUM_CASE(ENABLE_SYNC_ON_ACCOUNT); 37 ENUM_CASE(STOP_AND_RESTART_SYNC); 38 ENUM_CASE(DISABLE_SYNC_ON_CLIENT); 39 ENUM_CASE(STOP_SYNC_FOR_DISABLED_ACCOUNT); 40 ENUM_CASE(UNKNOWN_ACTION); 41 } 42 NOTREACHED(); 43 return ""; 44 } 45 46 SyncProtocolError::SyncProtocolError() 47 : error_type(UNKNOWN_ERROR), 48 action(UNKNOWN_ACTION) { 49 } 50 51 SyncProtocolError::~SyncProtocolError() { 52 } 53 54 base::DictionaryValue* SyncProtocolError::ToValue() const { 55 base::DictionaryValue* value = new base::DictionaryValue(); 56 value->SetString("ErrorType", 57 GetSyncErrorTypeString(error_type)); 58 value->SetString("ErrorDescription", error_description); 59 value->SetString("url", url); 60 value->SetString("action", GetClientActionString(action)); 61 return value; 62 } 63 64 } // namespace syncer 65 66