Ensure app tab opens in a visible browser window.
[chromium-blink-merge.git] / sync / api / sync_error.cc
blob12090404d1670f03670b89c9deca0b829c58c238
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 const std::string& message,
21 ModelType type) {
22 Init(location, message, type);
23 PrintLogError();
26 SyncError::SyncError(const SyncError& other) {
27 Copy(other);
30 SyncError::~SyncError() {
33 SyncError& SyncError::operator=(const SyncError& other) {
34 if (this == &other) {
35 return *this;
37 Copy(other);
38 return *this;
41 void SyncError::Copy(const SyncError& other) {
42 if (other.IsSet()) {
43 Init(other.location(),
44 other.message(),
45 other.type());
46 } else {
47 Clear();
51 void SyncError::Clear() {
52 location_.reset();
53 message_ = std::string();
54 type_ = UNSPECIFIED;
57 void SyncError::Reset(const tracked_objects::Location& location,
58 const std::string& message,
59 ModelType type) {
60 Init(location, message, type);
61 PrintLogError();
64 void SyncError::Init(const tracked_objects::Location& location,
65 const std::string& message,
66 ModelType type) {
67 location_.reset(new tracked_objects::Location(location));
68 message_ = message;
69 type_ = type;
72 bool SyncError::IsSet() const {
73 return location_.get() != NULL;
77 const tracked_objects::Location& SyncError::location() const {
78 CHECK(IsSet());
79 return *location_;
82 const std::string& SyncError::message() const {
83 CHECK(IsSet());
84 return message_;
87 ModelType SyncError::type() const {
88 CHECK(IsSet());
89 return type_;
92 std::string SyncError::ToString() const {
93 if (!IsSet()) {
94 return std::string();
96 return location_->ToString() + ", " + ModelTypeToString(type_) +
97 ", Sync Error: " + message_;
100 void SyncError::PrintLogError() const {
101 LAZY_STREAM(logging::LogMessage(location_->file_name(),
102 location_->line_number(),
103 logging::LOG_ERROR).stream(),
104 LOG_IS_ON(ERROR))
105 << ModelTypeToString(type_) << ", Sync Error: " << message_;
108 void PrintTo(const SyncError& sync_error, std::ostream* os) {
109 *os << sync_error.ToString();
112 } // namespace syncer