Roll src/third_party/WebKit 1dfb44f:c96f7be (svn 183545:183546)
[chromium-blink-merge.git] / sync / protocol / sync_protocol_error.cc
blob713137d50651703a75d96a43f79ce7adab340f3e
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.
5 #include "sync/protocol/sync_protocol_error.h"
7 #include <string>
9 #include "base/logging.h"
10 #include "base/values.h"
12 namespace syncer {
13 #define ENUM_CASE(x) case x: return #x; break;
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(USER_ROLLBACK);
27 ENUM_CASE(UNKNOWN_ERROR);
29 NOTREACHED();
30 return "";
33 const 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);
45 NOTREACHED();
46 return "";
49 SyncProtocolError::SyncProtocolError()
50 : error_type(UNKNOWN_ERROR),
51 action(UNKNOWN_ACTION) {
54 SyncProtocolError::~SyncProtocolError() {
57 base::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;
67 } // namespace syncer