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::operator=(const SyncError& other) { | |
26 if (this == &other) { | |
27 return *this; | |
28 } | |
29 Copy(other); | |
30 return *this; | |
31 } | |
32 | |
33 void SyncError::Copy(const SyncError& other) { | |
34 if (other.IsSet()) { | |
35 Init(other.location(), | |
36 other.message(), | |
37 other.type()); | |
38 } else { | |
39 Clear(); | |
40 } | |
41 } | |
42 | |
43 void SyncError::Clear() { | |
44 location_.reset(); | |
45 message_ = std::string(); | |
46 type_ = syncable::UNSPECIFIED; | |
47 } | |
48 | |
49 void SyncError::Reset(const tracked_objects::Location& location, | |
50 const std::string& message, | |
51 syncable::ModelType type) { | |
52 Init(location, message, type); | |
53 PrintLogError(); | |
54 } | |
55 | |
56 void SyncError::Init(const tracked_objects::Location& location, | |
57 const std::string& message, | |
58 syncable::ModelType type) { | |
59 location_.reset(new tracked_objects::Location(location)); | |
60 message_ = message; | |
61 type_ = type; | |
62 } | |
63 | |
64 bool SyncError::IsSet() const { | |
65 return location_.get() != NULL; | |
66 } | |
67 | |
68 const tracked_objects::Location& SyncError::location() const { | |
69 CHECK(IsSet()); | |
70 return *location_; | |
71 } | |
72 | |
73 const std::string& SyncError::message() const { | |
74 CHECK(IsSet()); | |
75 return message_; | |
76 } | |
77 | |
78 const syncable::ModelType SyncError::type() const { | |
79 CHECK(IsSet()); | |
80 return type_; | |
81 } | |
82 | |
83 void SyncError::PrintLogError() const { | |
84 LAZY_STREAM(logging::LogMessage(location_->file_name(), | |
85 location_->line_number(), | |
86 logging::LOG_ERROR).stream(), | |
87 LOG_IS_ON(ERROR)) | |
88 << syncable::ModelTypeToString(type_) << " Sync Error: " << message_; | |
89 } | |
OLD | NEW |