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

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

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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
« no previous file with comments | « components/sync/api/sync_error.h ('k') | components/sync/api/sync_error_factory.h » ('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 "components/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 "components/sync/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 ErrorType error_type, 20 ErrorType error_type,
21 const std::string& message, 21 const std::string& message,
22 ModelType model_type) { 22 ModelType model_type) {
23 DCHECK(error_type != UNSET); 23 DCHECK(error_type != UNSET);
24 Init(location, message, model_type, error_type); 24 Init(location, message, model_type, error_type);
25 PrintLogError(); 25 PrintLogError();
26 } 26 }
27 27
28 SyncError::SyncError(const SyncError& other) { 28 SyncError::SyncError(const SyncError& other) {
29 Copy(other); 29 Copy(other);
30 } 30 }
31 31
32 SyncError::~SyncError() { 32 SyncError::~SyncError() {}
33 }
34 33
35 SyncError& SyncError::operator=(const SyncError& other) { 34 SyncError& SyncError::operator=(const SyncError& other) {
36 if (this == &other) { 35 if (this == &other) {
37 return *this; 36 return *this;
38 } 37 }
39 Copy(other); 38 Copy(other);
40 return *this; 39 return *this;
41 } 40 }
42 41
43 void SyncError::Copy(const SyncError& other) { 42 void SyncError::Copy(const SyncError& other) {
44 if (other.IsSet()) { 43 if (other.IsSet()) {
45 Init(other.location(), 44 Init(other.location(), other.message(), other.model_type(),
46 other.message(),
47 other.model_type(),
48 other.error_type()); 45 other.error_type());
49 } else { 46 } else {
50 Clear(); 47 Clear();
51 } 48 }
52 } 49 }
53 50
54 void SyncError::Clear() { 51 void SyncError::Clear() {
55 location_.reset(); 52 location_.reset();
56 message_ = std::string(); 53 message_ = std::string();
57 model_type_ = UNSPECIFIED; 54 model_type_ = UNSPECIFIED;
(...skipping 14 matching lines...) Expand all
72 location_.reset(new tracked_objects::Location(location)); 69 location_.reset(new tracked_objects::Location(location));
73 message_ = message; 70 message_ = message;
74 model_type_ = model_type; 71 model_type_ = model_type;
75 error_type_ = error_type; 72 error_type_ = error_type;
76 } 73 }
77 74
78 bool SyncError::IsSet() const { 75 bool SyncError::IsSet() const {
79 return error_type_ != UNSET; 76 return error_type_ != UNSET;
80 } 77 }
81 78
82
83 const tracked_objects::Location& SyncError::location() const { 79 const tracked_objects::Location& SyncError::location() const {
84 CHECK(IsSet()); 80 CHECK(IsSet());
85 return *location_; 81 return *location_;
86 } 82 }
87 83
88 const std::string& SyncError::message() const { 84 const std::string& SyncError::message() const {
89 CHECK(IsSet()); 85 CHECK(IsSet());
90 return message_; 86 return message_;
91 } 87 }
92 88
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 NOTREACHED() << "Invalid error type"; 131 NOTREACHED() << "Invalid error type";
136 break; 132 break;
137 } 133 }
138 return type_message; 134 return type_message;
139 } 135 }
140 136
141 std::string SyncError::ToString() const { 137 std::string SyncError::ToString() const {
142 if (!IsSet()) { 138 if (!IsSet()) {
143 return std::string(); 139 return std::string();
144 } 140 }
145 return location_->ToString() + ", " + ModelTypeToString(model_type_) + 141 return location_->ToString() + ", " + ModelTypeToString(model_type_) + " " +
146 " " + GetMessagePrefix() + message_; 142 GetMessagePrefix() + message_;
147 } 143 }
148 144
149 void SyncError::PrintLogError() const { 145 void SyncError::PrintLogError() const {
150 logging::LogSeverity logSeverity = 146 logging::LogSeverity logSeverity = (GetSeverity() == SYNC_ERROR_SEVERITY_INFO)
151 (GetSeverity() == SYNC_ERROR_SEVERITY_INFO) 147 ? logging::LOG_VERBOSE
152 ? logging::LOG_VERBOSE : logging::LOG_ERROR; 148 : logging::LOG_ERROR;
153 149
154 LAZY_STREAM(logging::LogMessage(location_->file_name(), 150 LAZY_STREAM(logging::LogMessage(location_->file_name(),
155 location_->line_number(), 151 location_->line_number(), logSeverity)
156 logSeverity).stream(), 152 .stream(),
157 logSeverity >= ::logging::GetMinLogLevel()) 153 logSeverity >= ::logging::GetMinLogLevel())
158 << ModelTypeToString(model_type_) << " " 154 << ModelTypeToString(model_type_) << " " << GetMessagePrefix()
159 << GetMessagePrefix() << message_; 155 << message_;
160 } 156 }
161 157
162 void PrintTo(const SyncError& sync_error, std::ostream* os) { 158 void PrintTo(const SyncError& sync_error, std::ostream* os) {
163 *os << sync_error.ToString(); 159 *os << sync_error.ToString();
164 } 160 }
165 161
166 } // namespace syncer 162 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/api/sync_error.h ('k') | components/sync/api/sync_error_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698