OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SYNC_API_SYNC_ERROR_H_ | 5 #ifndef SYNC_API_SYNC_ERROR_H_ |
6 #define SYNC_API_SYNC_ERROR_H_ | 6 #define SYNC_API_SYNC_ERROR_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "sync/base/sync_export.h" | 12 #include "sync/base/sync_export.h" |
13 #include "sync/internal_api/public/base/model_type.h" | 13 #include "sync/internal_api/public/base/model_type.h" |
14 | 14 |
15 namespace tracked_objects { | 15 namespace tracked_objects { |
16 class Location; | 16 class Location; |
17 } // namespace tracked_objects | 17 } // namespace tracked_objects |
18 | 18 |
19 namespace syncer { | 19 namespace syncer { |
20 | 20 |
21 // Sync errors are used for debug purposes and handled internally and/or | 21 // Sync errors are used for debug purposes and handled internally and/or |
22 // exposed through Chrome's "about:sync" internal page. They are considered | 22 // exposed through Chrome's "about:sync" internal page. |
23 // unrecoverable for the datatype creating them, and should only be used as | |
24 // such. | |
25 // This class is copy-friendly and thread-safe. | 23 // This class is copy-friendly and thread-safe. |
26 class SYNC_EXPORT SyncError { | 24 class SYNC_EXPORT SyncError { |
27 public: | 25 public: |
| 26 // Error types are used to distinguish general datatype errors (which result |
| 27 // in the datatype being disabled) from actionable sync errors (which might |
| 28 // have more complicated results). |
| 29 enum ErrorType { |
| 30 UNSET, // No error. |
| 31 UNRECOVERABLE_ERROR, // An unrecoverable runtime error was encountered, and |
| 32 // sync should be disabled completely. |
| 33 DATATYPE_ERROR, // A datatype error was encountered, and the datatype |
| 34 // should be disabled. |
| 35 PERSISTENCE_ERROR, // A persistence error was detected, and the |
| 36 // datataype should be associated after a sync update. |
| 37 CRYPTO_ERROR, // A cryptographer error was detected, and the |
| 38 // datatype should be associated after it is resolved. |
| 39 }; |
| 40 |
28 // Default constructor refers to "no error", and IsSet() will return false. | 41 // Default constructor refers to "no error", and IsSet() will return false. |
29 SyncError(); | 42 SyncError(); |
30 | 43 |
31 // Create a new Sync error triggered by datatype |type| with debug message | 44 // Create a new Sync error of type |error_type| triggered by |model_type| |
32 // |message| from the specified location. IsSet() will return true. | 45 // from the specified location. IsSet() will return true afterward. Will |
33 // Will print the new error to LOG(ERROR). | 46 // create and print an error specific message to LOG(ERROR). |
34 SyncError(const tracked_objects::Location& location, | 47 SyncError(const tracked_objects::Location& location, |
| 48 ErrorType error_type, |
35 const std::string& message, | 49 const std::string& message, |
36 ModelType type); | 50 ModelType model_type); |
37 | 51 |
38 // Copy and assign via deep copy. | 52 // Copy and assign via deep copy. |
39 SyncError(const SyncError& other); | 53 SyncError(const SyncError& other); |
40 SyncError& operator=(const SyncError& other); | 54 SyncError& operator=(const SyncError& other); |
41 | 55 |
42 ~SyncError(); | 56 ~SyncError(); |
43 | 57 |
44 // Reset the current error to a new error. May be called irrespective of | 58 // Reset the current error to a new datatype error. May be called |
45 // whether IsSet() is true. After this is called, IsSet() will return true. | 59 // irrespective of whether IsSet() is true. After this is called, IsSet() |
| 60 // will return true. |
46 // Will print the new error to LOG(ERROR). | 61 // Will print the new error to LOG(ERROR). |
47 void Reset(const tracked_objects::Location& location, | 62 void Reset(const tracked_objects::Location& location, |
48 const std::string& message, | 63 const std::string& message, |
49 ModelType type); | 64 ModelType type); |
50 | 65 |
51 // Whether this is a valid error or not. | 66 // Whether this is a valid error or not. |
52 bool IsSet() const; | 67 bool IsSet() const; |
53 | 68 |
54 // These must only be called if IsSet() is true. | 69 // These must only be called if IsSet() is true. |
55 const tracked_objects::Location& location() const; | 70 const tracked_objects::Location& location() const; |
56 const std::string& message() const; | 71 const std::string& message() const; |
57 ModelType type() const; | 72 ModelType model_type() const; |
| 73 ErrorType error_type() const; |
58 | 74 |
59 // Returns empty string is IsSet() is false. | 75 // Returns empty string is IsSet() is false. |
60 std::string ToString() const; | 76 std::string ToString() const; |
61 private: | 77 private: |
62 // Print error information to log. | 78 // Print error information to log. |
63 void PrintLogError() const; | 79 void PrintLogError() const; |
64 | 80 |
65 // Make a copy of a SyncError. If other.IsSet() == false, this->IsSet() will | 81 // Make a copy of a SyncError. If other.IsSet() == false, this->IsSet() will |
66 // now return false. | 82 // now return false. |
67 void Copy(const SyncError& other); | 83 void Copy(const SyncError& other); |
68 | 84 |
69 // Initialize the local error data with the specified error data. After this | 85 // Initialize the local error data with the specified error data. After this |
70 // is called, IsSet() will return true. | 86 // is called, IsSet() will return true. |
71 void Init(const tracked_objects::Location& location, | 87 void Init(const tracked_objects::Location& location, |
72 const std::string& message, | 88 const std::string& message, |
73 ModelType type); | 89 ModelType model_type, |
| 90 ErrorType error_type); |
74 | 91 |
75 // Reset the error to it's default (unset) values. | 92 // Reset the error to it's default (unset) values. |
76 void Clear(); | 93 void Clear(); |
77 | 94 |
78 // scoped_ptr is necessary because Location objects aren't assignable. | 95 // scoped_ptr is necessary because Location objects aren't assignable. |
79 scoped_ptr<tracked_objects::Location> location_; | 96 scoped_ptr<tracked_objects::Location> location_; |
80 std::string message_; | 97 std::string message_; |
81 ModelType type_; | 98 ModelType model_type_; |
| 99 ErrorType error_type_; |
82 }; | 100 }; |
83 | 101 |
84 // gmock printer helper. | 102 // gmock printer helper. |
85 SYNC_EXPORT void PrintTo(const SyncError& sync_error, std::ostream* os); | 103 SYNC_EXPORT void PrintTo(const SyncError& sync_error, std::ostream* os); |
86 | 104 |
87 } // namespace syncer | 105 } // namespace syncer |
88 | 106 |
89 #endif // SYNC_API_SYNC_ERROR_H_ | 107 #endif // SYNC_API_SYNC_ERROR_H_ |
OLD | NEW |