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 #ifndef CHROME_BROWSER_SYNC_API_SYNC_ERROR_H_ | |
6 #define CHROME_BROWSER_SYNC_API_SYNC_ERROR_H_ | |
7 #pragma once | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "chrome/browser/sync/syncable/model_type.h" | |
13 | |
14 namespace tracked_objects { | |
15 class Location; | |
16 } // namespace tracked_objects | |
17 | |
18 // Sync errors are used for debug purposes and handled internally and/or | |
19 // exposed through Chrome's "about:sync" internal page. They are considered | |
20 // unrecoverable for the datatype creating them, and should only be used as | |
21 // such. | |
22 // This class is copy-friendly and thread-safe. | |
23 class SyncError { | |
24 public: | |
25 // Default constructor refers to "no error", and IsSet() will return false. | |
26 SyncError(); | |
27 | |
28 // Create a new Sync error triggered by datatype |type| with debug message | |
29 // |message| from the specified location. IsSet() will return true. | |
30 // Will print the new error to LOG(ERROR). | |
31 SyncError(const tracked_objects::Location& location, | |
32 const std::string& message, | |
33 syncable::ModelType type); | |
34 | |
35 // Copy and assign via deep copy. | |
36 SyncError(const SyncError& other); | |
37 SyncError& operator=(const SyncError& other); | |
38 | |
39 // Reset the current error to a new error. May be called irrespective of | |
40 // whether IsSet() is true. After this is called, IsSet() will return true. | |
41 // Will print the new error to LOG(ERROR). | |
42 void Reset(const tracked_objects::Location& location, | |
43 const std::string& message, | |
44 syncable::ModelType type); | |
45 | |
46 // Whether this is a valid error or not. | |
47 bool IsSet() const; | |
48 | |
49 // These must only be called if IsSet() is true. | |
50 const tracked_objects::Location& location() const; | |
51 const std::string& message() const; | |
52 const syncable::ModelType type() const; | |
53 | |
54 private: | |
55 // Print error information to log. | |
56 void PrintLogError() const; | |
57 | |
58 // Make a copy of a SyncError. If other.IsSet() == false, this->IsSet() will | |
59 // now return false. | |
60 void Copy(const SyncError& other); | |
61 | |
62 // Initialize the local error data with the specified error data. After this | |
63 // is called, IsSet() will return true. | |
64 void Init(const tracked_objects::Location& location, | |
65 const std::string& message, | |
66 syncable::ModelType type); | |
67 | |
68 // Reset the error to it's default (unset) values. | |
69 void Clear(); | |
70 | |
71 // scoped_ptr is necessary because Location objects aren't assignable. | |
72 scoped_ptr<tracked_objects::Location> location_; | |
73 std::string message_; | |
74 syncable::ModelType type_; | |
75 }; | |
76 | |
77 #endif // CHROME_BROWSER_SYNC_API_SYNC_ERROR_H_ | |
OLD | NEW |