| OLD | NEW |
| 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 syncer::ModelType type) { | 21 ModelType type) { |
| 22 Init(location, message, type); | 22 Init(location, message, type); |
| 23 PrintLogError(); | 23 PrintLogError(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 SyncError::SyncError(const SyncError& other) { | 26 SyncError::SyncError(const SyncError& other) { |
| 27 Copy(other); | 27 Copy(other); |
| 28 } | 28 } |
| 29 | 29 |
| 30 SyncError::~SyncError() { | 30 SyncError::~SyncError() { |
| 31 } | 31 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 44 other.message(), | 44 other.message(), |
| 45 other.type()); | 45 other.type()); |
| 46 } else { | 46 } else { |
| 47 Clear(); | 47 Clear(); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 void SyncError::Clear() { | 51 void SyncError::Clear() { |
| 52 location_.reset(); | 52 location_.reset(); |
| 53 message_ = std::string(); | 53 message_ = std::string(); |
| 54 type_ = syncer::UNSPECIFIED; | 54 type_ = UNSPECIFIED; |
| 55 } | 55 } |
| 56 | 56 |
| 57 void SyncError::Reset(const tracked_objects::Location& location, | 57 void SyncError::Reset(const tracked_objects::Location& location, |
| 58 const std::string& message, | 58 const std::string& message, |
| 59 syncer::ModelType type) { | 59 ModelType type) { |
| 60 Init(location, message, type); | 60 Init(location, message, type); |
| 61 PrintLogError(); | 61 PrintLogError(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void SyncError::Init(const tracked_objects::Location& location, | 64 void SyncError::Init(const tracked_objects::Location& location, |
| 65 const std::string& message, | 65 const std::string& message, |
| 66 syncer::ModelType type) { | 66 ModelType type) { |
| 67 location_.reset(new tracked_objects::Location(location)); | 67 location_.reset(new tracked_objects::Location(location)); |
| 68 message_ = message; | 68 message_ = message; |
| 69 type_ = type; | 69 type_ = type; |
| 70 } | 70 } |
| 71 | 71 |
| 72 bool SyncError::IsSet() const { | 72 bool SyncError::IsSet() const { |
| 73 return location_.get() != NULL; | 73 return location_.get() != NULL; |
| 74 } | 74 } |
| 75 | 75 |
| 76 | 76 |
| 77 const tracked_objects::Location& SyncError::location() const { | 77 const tracked_objects::Location& SyncError::location() const { |
| 78 CHECK(IsSet()); | 78 CHECK(IsSet()); |
| 79 return *location_; | 79 return *location_; |
| 80 } | 80 } |
| 81 | 81 |
| 82 const std::string& SyncError::message() const { | 82 const std::string& SyncError::message() const { |
| 83 CHECK(IsSet()); | 83 CHECK(IsSet()); |
| 84 return message_; | 84 return message_; |
| 85 } | 85 } |
| 86 | 86 |
| 87 syncer::ModelType SyncError::type() const { | 87 ModelType SyncError::type() const { |
| 88 CHECK(IsSet()); | 88 CHECK(IsSet()); |
| 89 return type_; | 89 return type_; |
| 90 } | 90 } |
| 91 | 91 |
| 92 std::string SyncError::ToString() const { | 92 std::string SyncError::ToString() const { |
| 93 if (!IsSet()) { | 93 if (!IsSet()) { |
| 94 return std::string(); | 94 return std::string(); |
| 95 } | 95 } |
| 96 return location_->ToString() + ", " + syncer::ModelTypeToString(type_) + | 96 return location_->ToString() + ", " + ModelTypeToString(type_) + |
| 97 ", Sync Error: " + message_; | 97 ", Sync Error: " + message_; |
| 98 } | 98 } |
| 99 | 99 |
| 100 void SyncError::PrintLogError() const { | 100 void SyncError::PrintLogError() const { |
| 101 LAZY_STREAM(logging::LogMessage(location_->file_name(), | 101 LAZY_STREAM(logging::LogMessage(location_->file_name(), |
| 102 location_->line_number(), | 102 location_->line_number(), |
| 103 logging::LOG_ERROR).stream(), | 103 logging::LOG_ERROR).stream(), |
| 104 LOG_IS_ON(ERROR)) | 104 LOG_IS_ON(ERROR)) |
| 105 << syncer::ModelTypeToString(type_) << ", Sync Error: " << message_; | 105 << ModelTypeToString(type_) << ", Sync Error: " << message_; |
| 106 } | 106 } |
| 107 | 107 |
| 108 void PrintTo(const SyncError& sync_error, std::ostream* os) { | 108 void PrintTo(const SyncError& sync_error, std::ostream* os) { |
| 109 *os << sync_error.ToString(); | 109 *os << sync_error.ToString(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 } // namespace syncer | 112 } // namespace syncer |
| OLD | NEW |