Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / sync / api / sync_error.cc
blobee6885cb229285f479b8bc57284dda35d5068bb2
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/api/sync_error.h"
7 #include <ostream>
9 #include "base/location.h"
10 #include "base/logging.h"
11 #include "sync/internal_api/public/base/model_type.h"
13 namespace syncer {
15 SyncError::SyncError() {
16 Clear();
19 SyncError::SyncError(const tracked_objects::Location& location,
20 ErrorType error_type,
21 const std::string& custom_message,
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: ";
41 Init(location, type_message + custom_message, model_type, error_type);
42 PrintLogError();
45 SyncError::SyncError(const SyncError& other) {
46 Copy(other);
49 SyncError::~SyncError() {
52 SyncError& SyncError::operator=(const SyncError& other) {
53 if (this == &other) {
54 return *this;
56 Copy(other);
57 return *this;
60 void SyncError::Copy(const SyncError& other) {
61 if (other.IsSet()) {
62 Init(other.location(),
63 other.message(),
64 other.model_type(),
65 other.error_type());
66 } else {
67 Clear();
71 void SyncError::Clear() {
72 location_.reset();
73 message_ = std::string();
74 model_type_ = UNSPECIFIED;
75 error_type_ = UNSET;
78 void SyncError::Reset(const tracked_objects::Location& location,
79 const std::string& message,
80 ModelType model_type) {
81 Init(location, message, model_type, DATATYPE_ERROR);
82 PrintLogError();
85 void SyncError::Init(const tracked_objects::Location& location,
86 const std::string& message,
87 ModelType model_type,
88 ErrorType error_type) {
89 location_.reset(new tracked_objects::Location(location));
90 message_ = message;
91 model_type_ = model_type;
92 error_type_ = error_type;
95 bool SyncError::IsSet() const {
96 return error_type_ != UNSET;
100 const tracked_objects::Location& SyncError::location() const {
101 CHECK(IsSet());
102 return *location_;
105 const std::string& SyncError::message() const {
106 CHECK(IsSet());
107 return message_;
110 ModelType SyncError::model_type() const {
111 CHECK(IsSet());
112 return model_type_;
115 SyncError::ErrorType SyncError::error_type() const {
116 CHECK(IsSet());
117 return error_type_;
120 std::string SyncError::ToString() const {
121 if (!IsSet()) {
122 return std::string();
124 return location_->ToString() + ", " + ModelTypeToString(model_type_) +
125 " " + message_;
128 void SyncError::PrintLogError() const {
129 LAZY_STREAM(logging::LogMessage(location_->file_name(),
130 location_->line_number(),
131 logging::LOG_ERROR).stream(),
132 LOG_IS_ON(ERROR))
133 << ModelTypeToString(model_type_) << " " << message_;
136 void PrintTo(const SyncError& sync_error, std::ostream* os) {
137 *os << sync_error.ToString();
140 } // namespace syncer