OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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. |
| 4 |
| 5 #include "chrome/browser/sync/api/sync_error.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/tracked.h" |
| 9 |
| 10 SyncError::SyncError() { |
| 11 Clear(); |
| 12 } |
| 13 |
| 14 SyncError::SyncError(const tracked_objects::Location& location, |
| 15 const std::string& message, |
| 16 syncable::ModelType type) { |
| 17 Init(location, message, type); |
| 18 PrintLogError(); |
| 19 } |
| 20 |
| 21 SyncError::SyncError(const SyncError& other) { |
| 22 Copy(other); |
| 23 } |
| 24 |
| 25 SyncError::~SyncError() { |
| 26 } |
| 27 |
| 28 SyncError& SyncError::operator=(const SyncError& other) { |
| 29 if (this == &other) { |
| 30 return *this; |
| 31 } |
| 32 Copy(other); |
| 33 return *this; |
| 34 } |
| 35 |
| 36 void SyncError::Copy(const SyncError& other) { |
| 37 if (other.IsSet()) { |
| 38 Init(other.location(), |
| 39 other.message(), |
| 40 other.type()); |
| 41 } else { |
| 42 Clear(); |
| 43 } |
| 44 } |
| 45 |
| 46 void SyncError::Clear() { |
| 47 location_.reset(); |
| 48 message_ = std::string(); |
| 49 type_ = syncable::UNSPECIFIED; |
| 50 } |
| 51 |
| 52 void SyncError::Reset(const tracked_objects::Location& location, |
| 53 const std::string& message, |
| 54 syncable::ModelType type) { |
| 55 Init(location, message, type); |
| 56 PrintLogError(); |
| 57 } |
| 58 |
| 59 void SyncError::Init(const tracked_objects::Location& location, |
| 60 const std::string& message, |
| 61 syncable::ModelType type) { |
| 62 location_.reset(new tracked_objects::Location(location)); |
| 63 message_ = message; |
| 64 type_ = type; |
| 65 } |
| 66 |
| 67 bool SyncError::IsSet() const { |
| 68 return location_.get() != NULL; |
| 69 } |
| 70 |
| 71 const tracked_objects::Location& SyncError::location() const { |
| 72 CHECK(IsSet()); |
| 73 return *location_; |
| 74 } |
| 75 |
| 76 const std::string& SyncError::message() const { |
| 77 CHECK(IsSet()); |
| 78 return message_; |
| 79 } |
| 80 |
| 81 syncable::ModelType SyncError::type() const { |
| 82 CHECK(IsSet()); |
| 83 return type_; |
| 84 } |
| 85 |
| 86 void SyncError::PrintLogError() const { |
| 87 LAZY_STREAM(logging::LogMessage(location_->file_name(), |
| 88 location_->line_number(), |
| 89 logging::LOG_ERROR).stream(), |
| 90 LOG_IS_ON(ERROR)) |
| 91 << syncable::ModelTypeToString(type_) << " Sync Error: " << message_; |
| 92 } |
OLD | NEW |