Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(603)

Side by Side Diff: sync/api/sync_error.cc

Issue 15701022: [Sync] Add support for sync Persistence Errors (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update tests Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/api/sync_error.h" 5 #include "sync/api/sync_error.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "sync/internal_api/public/base/model_type.h" 11 #include "sync/internal_api/public/base/model_type.h"
12 12
13 namespace syncer { 13 namespace syncer {
14 14
15 SyncError::SyncError() { 15 SyncError::SyncError() {
16 Clear(); 16 Clear();
17 } 17 }
18 18
19 SyncError::SyncError(const tracked_objects::Location& location, 19 SyncError::SyncError(const tracked_objects::Location& location,
20 const std::string& message, 20 const std::string& message,
21 ModelType type) { 21 ModelType model_type) {
22 Init(location, message, type); 22 Init(location, message, model_type, DATATYPE_ERROR);
23 PrintLogError(); 23 PrintLogError();
24 } 24 }
25 25
26 SyncError::SyncError(const tracked_objects::Location& location,
27 ErrorType error_type,
28 ModelType model_type) {
29 std::string message;
30 switch (error_type) {
31 case UNRECOVERABLE_ERROR:
32 message = "a unrecoverable error was encountered.";
33 break;
34 case DATATYPE_ERROR:
35 message = "a datatype error was encountered.";
36 break;
37 case PERSISTENCE_ERROR:
38 message = "a persistence error was encountered.";
39 break;
40 case CRYPTO_ERROR:
41 message = "a cryptographer error was encountered.";
42 break;
43 default:
44 NOTREACHED();
45 message = "invalid error.";
46 }
47 Init(location, message, model_type, error_type);
48 PrintLogError();
49 }
50
26 SyncError::SyncError(const SyncError& other) { 51 SyncError::SyncError(const SyncError& other) {
27 Copy(other); 52 Copy(other);
28 } 53 }
29 54
30 SyncError::~SyncError() { 55 SyncError::~SyncError() {
31 } 56 }
32 57
33 SyncError& SyncError::operator=(const SyncError& other) { 58 SyncError& SyncError::operator=(const SyncError& other) {
34 if (this == &other) { 59 if (this == &other) {
35 return *this; 60 return *this;
36 } 61 }
37 Copy(other); 62 Copy(other);
38 return *this; 63 return *this;
39 } 64 }
40 65
41 void SyncError::Copy(const SyncError& other) { 66 void SyncError::Copy(const SyncError& other) {
42 if (other.IsSet()) { 67 if (other.IsSet()) {
43 Init(other.location(), 68 Init(other.location(),
44 other.message(), 69 other.message(),
45 other.type()); 70 other.model_type(),
71 other.error_type());
46 } else { 72 } else {
47 Clear(); 73 Clear();
48 } 74 }
49 } 75 }
50 76
51 void SyncError::Clear() { 77 void SyncError::Clear() {
52 location_.reset(); 78 location_.reset();
53 message_ = std::string(); 79 message_ = std::string();
54 type_ = UNSPECIFIED; 80 model_type_ = UNSPECIFIED;
81 error_type_ = UNSET;
55 } 82 }
56 83
57 void SyncError::Reset(const tracked_objects::Location& location, 84 void SyncError::Reset(const tracked_objects::Location& location,
58 const std::string& message, 85 const std::string& message,
59 ModelType type) { 86 ModelType model_type) {
60 Init(location, message, type); 87 Init(location, message, model_type, DATATYPE_ERROR);
61 PrintLogError(); 88 PrintLogError();
62 } 89 }
63 90
64 void SyncError::Init(const tracked_objects::Location& location, 91 void SyncError::Init(const tracked_objects::Location& location,
65 const std::string& message, 92 const std::string& message,
66 ModelType type) { 93 ModelType model_type,
94 ErrorType error_type) {
67 location_.reset(new tracked_objects::Location(location)); 95 location_.reset(new tracked_objects::Location(location));
68 message_ = message; 96 message_ = message;
69 type_ = type; 97 model_type_ = model_type;
98 error_type_ = error_type;
70 } 99 }
71 100
72 bool SyncError::IsSet() const { 101 bool SyncError::IsSet() const {
73 return location_.get() != NULL; 102 return error_type_ != UNSET;
74 } 103 }
75 104
76 105
77 const tracked_objects::Location& SyncError::location() const { 106 const tracked_objects::Location& SyncError::location() const {
78 CHECK(IsSet()); 107 CHECK(IsSet());
79 return *location_; 108 return *location_;
80 } 109 }
81 110
82 const std::string& SyncError::message() const { 111 const std::string& SyncError::message() const {
83 CHECK(IsSet()); 112 CHECK(IsSet());
84 return message_; 113 return message_;
85 } 114 }
86 115
87 ModelType SyncError::type() const { 116 ModelType SyncError::model_type() const {
88 CHECK(IsSet()); 117 CHECK(IsSet());
89 return type_; 118 return model_type_;
119 }
120
121 SyncError::ErrorType SyncError::error_type() const {
122 CHECK(IsSet());
123 return error_type_;
90 } 124 }
91 125
92 std::string SyncError::ToString() const { 126 std::string SyncError::ToString() const {
93 if (!IsSet()) { 127 if (!IsSet()) {
94 return std::string(); 128 return std::string();
95 } 129 }
96 return location_->ToString() + ", " + ModelTypeToString(type_) + 130 return location_->ToString() + ", " + ModelTypeToString(model_type_) +
97 ", Sync Error: " + message_; 131 ", Sync Error: " + message_;
98 } 132 }
99 133
100 void SyncError::PrintLogError() const { 134 void SyncError::PrintLogError() const {
101 LAZY_STREAM(logging::LogMessage(location_->file_name(), 135 LAZY_STREAM(logging::LogMessage(location_->file_name(),
102 location_->line_number(), 136 location_->line_number(),
103 logging::LOG_ERROR).stream(), 137 logging::LOG_ERROR).stream(),
104 LOG_IS_ON(ERROR)) 138 LOG_IS_ON(ERROR))
105 << ModelTypeToString(type_) << ", Sync Error: " << message_; 139 << ModelTypeToString(model_type_) << ", Sync Error: " << message_;
106 } 140 }
107 141
108 void PrintTo(const SyncError& sync_error, std::ostream* os) { 142 void PrintTo(const SyncError& sync_error, std::ostream* os) {
109 *os << sync_error.ToString(); 143 *os << sync_error.ToString();
110 } 144 }
111 145
112 } // namespace syncer 146 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698