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() { | |
akalin
2011/07/25 22:43:13
It would be good to initialize all variables, espe
Nicolas Zea
2011/07/25 23:08:19
Done.
| |
11 } | |
12 | |
13 SyncError::SyncError(const tracked_objects::Location& location, | |
14 const std::string& message, | |
15 syncable::ModelType type) { | |
16 Init(location, message, type); | |
17 PrintLogError(); | |
18 } | |
19 | |
20 SyncError::SyncError(const SyncError& other) { | |
21 Copy(other); | |
22 } | |
23 | |
24 SyncError& SyncError::operator=(const SyncError& other) { | |
25 if (this == &other) { | |
akalin
2011/07/25 22:43:13
I don't think we should bother explicitly checking
Nicolas Zea
2011/07/25 23:08:19
There's no point in copying if we're not changing
akalin
2011/07/25 23:49:32
Yeah, but it's not a very common case, so I don't
| |
26 return *this; | |
27 } | |
28 Copy(other); | |
29 return *this; | |
30 } | |
31 | |
32 void SyncError::Copy(const SyncError& other) { | |
33 if (other.IsSet()) { | |
34 Init(other.location(), | |
35 other.message(), | |
36 other.type()); | |
37 } else { | |
38 location_.reset(); | |
akalin
2011/07/25 22:43:13
Move this code to Clear() and call that here.
Nicolas Zea
2011/07/25 23:08:19
Done.
| |
39 message_ = std::string(); | |
40 type_ = syncable::UNSPECIFIED; | |
41 } | |
42 } | |
43 | |
44 void SyncError::Reset(const tracked_objects::Location& location, | |
45 const std::string& message, | |
46 syncable::ModelType type) { | |
47 Init(location, message, type); | |
48 PrintLogError(); | |
49 } | |
50 | |
51 void SyncError::Init(const tracked_objects::Location& location, | |
52 const std::string& message, | |
53 syncable::ModelType type) { | |
54 location_.reset(new tracked_objects::Location(location)); | |
55 message_ = message; | |
56 type_ = type; | |
57 } | |
58 | |
59 bool SyncError::IsSet() const { | |
60 return location_.get() != NULL; | |
61 } | |
62 | |
63 const tracked_objects::Location& SyncError::location() const { | |
64 CHECK(IsSet()); | |
65 return *location_; | |
66 } | |
67 | |
68 const std::string& SyncError::message() const { | |
69 CHECK(IsSet()); | |
70 return message_; | |
71 } | |
72 | |
73 const syncable::ModelType SyncError::type() const { | |
74 CHECK(IsSet()); | |
75 return type_; | |
76 } | |
77 | |
78 void SyncError::PrintLogError() const { | |
79 LAZY_STREAM(logging::LogMessage(location_->file_name(), | |
80 location_->line_number(), | |
81 logging::LOG_ERROR).stream(), | |
82 LOG_IS_ON(ERROR)) | |
83 << syncable::ModelTypeToString(type_) << " Sync Error: " << message_; | |
84 } | |
OLD | NEW |