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

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: Move bookmark change into separate patch Created 7 years, 5 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
« no previous file with comments | « sync/api/sync_error.h ('k') | sync/api/sync_error_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ErrorType error_type,
21 ModelType type) { 21 const std::string& custom_message,
22 Init(location, message, type); 22 ModelType model_type) {
23 std::string type_message;
24 switch (error_type) {
25 case UNRECOVERABLE_ERROR:
26 type_message = "unrecoverable error was encountered: ";
27 break;
28 case DATATYPE_ERROR:
29 type_message = "datatype error was encountered: ";
30 break;
31 case PERSISTENCE_ERROR:
32 type_message = "persistence error was encountered: ";
33 break;
34 case CRYPTO_ERROR:
35 type_message = "cryptographer error was encountered: ";
36 break;
37 default:
38 NOTREACHED();
39 type_message = "invalid error: ";
40 }
41 Init(location, type_message + custom_message, model_type, error_type);
23 PrintLogError(); 42 PrintLogError();
24 } 43 }
25 44
26 SyncError::SyncError(const SyncError& other) { 45 SyncError::SyncError(const SyncError& other) {
27 Copy(other); 46 Copy(other);
28 } 47 }
29 48
30 SyncError::~SyncError() { 49 SyncError::~SyncError() {
31 } 50 }
32 51
33 SyncError& SyncError::operator=(const SyncError& other) { 52 SyncError& SyncError::operator=(const SyncError& other) {
34 if (this == &other) { 53 if (this == &other) {
35 return *this; 54 return *this;
36 } 55 }
37 Copy(other); 56 Copy(other);
38 return *this; 57 return *this;
39 } 58 }
40 59
41 void SyncError::Copy(const SyncError& other) { 60 void SyncError::Copy(const SyncError& other) {
42 if (other.IsSet()) { 61 if (other.IsSet()) {
43 Init(other.location(), 62 Init(other.location(),
44 other.message(), 63 other.message(),
45 other.type()); 64 other.model_type(),
65 other.error_type());
46 } else { 66 } else {
47 Clear(); 67 Clear();
48 } 68 }
49 } 69 }
50 70
51 void SyncError::Clear() { 71 void SyncError::Clear() {
52 location_.reset(); 72 location_.reset();
53 message_ = std::string(); 73 message_ = std::string();
54 type_ = UNSPECIFIED; 74 model_type_ = UNSPECIFIED;
75 error_type_ = UNSET;
55 } 76 }
56 77
57 void SyncError::Reset(const tracked_objects::Location& location, 78 void SyncError::Reset(const tracked_objects::Location& location,
58 const std::string& message, 79 const std::string& message,
59 ModelType type) { 80 ModelType model_type) {
60 Init(location, message, type); 81 Init(location, message, model_type, DATATYPE_ERROR);
61 PrintLogError(); 82 PrintLogError();
62 } 83 }
63 84
64 void SyncError::Init(const tracked_objects::Location& location, 85 void SyncError::Init(const tracked_objects::Location& location,
65 const std::string& message, 86 const std::string& message,
66 ModelType type) { 87 ModelType model_type,
88 ErrorType error_type) {
67 location_.reset(new tracked_objects::Location(location)); 89 location_.reset(new tracked_objects::Location(location));
68 message_ = message; 90 message_ = message;
69 type_ = type; 91 model_type_ = model_type;
92 error_type_ = error_type;
70 } 93 }
71 94
72 bool SyncError::IsSet() const { 95 bool SyncError::IsSet() const {
73 return location_.get() != NULL; 96 return error_type_ != UNSET;
74 } 97 }
75 98
76 99
77 const tracked_objects::Location& SyncError::location() const { 100 const tracked_objects::Location& SyncError::location() const {
78 CHECK(IsSet()); 101 CHECK(IsSet());
79 return *location_; 102 return *location_;
80 } 103 }
81 104
82 const std::string& SyncError::message() const { 105 const std::string& SyncError::message() const {
83 CHECK(IsSet()); 106 CHECK(IsSet());
84 return message_; 107 return message_;
85 } 108 }
86 109
87 ModelType SyncError::type() const { 110 ModelType SyncError::model_type() const {
88 CHECK(IsSet()); 111 CHECK(IsSet());
89 return type_; 112 return model_type_;
113 }
114
115 SyncError::ErrorType SyncError::error_type() const {
116 CHECK(IsSet());
117 return error_type_;
90 } 118 }
91 119
92 std::string SyncError::ToString() const { 120 std::string SyncError::ToString() const {
93 if (!IsSet()) { 121 if (!IsSet()) {
94 return std::string(); 122 return std::string();
95 } 123 }
96 return location_->ToString() + ", " + ModelTypeToString(type_) + 124 return location_->ToString() + ", " + ModelTypeToString(model_type_) +
97 ", Sync Error: " + message_; 125 " " + message_;
98 } 126 }
99 127
100 void SyncError::PrintLogError() const { 128 void SyncError::PrintLogError() const {
101 LAZY_STREAM(logging::LogMessage(location_->file_name(), 129 LAZY_STREAM(logging::LogMessage(location_->file_name(),
102 location_->line_number(), 130 location_->line_number(),
103 logging::LOG_ERROR).stream(), 131 logging::LOG_ERROR).stream(),
104 LOG_IS_ON(ERROR)) 132 LOG_IS_ON(ERROR))
105 << ModelTypeToString(type_) << ", Sync Error: " << message_; 133 << ModelTypeToString(model_type_) << " " << message_;
106 } 134 }
107 135
108 void PrintTo(const SyncError& sync_error, std::ostream* os) { 136 void PrintTo(const SyncError& sync_error, std::ostream* os) {
109 *os << sync_error.ToString(); 137 *os << sync_error.ToString();
110 } 138 }
111 139
112 } // namespace syncer 140 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/api/sync_error.h ('k') | sync/api/sync_error_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698