| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef SYNC_API_SYNC_ERROR_H_ | |
| 6 #define SYNC_API_SYNC_ERROR_H_ | |
| 7 | |
| 8 #include <iosfwd> | |
| 9 #include <memory> | |
| 10 #include <string> | |
| 11 | |
| 12 #include "sync/base/sync_export.h" | |
| 13 #include "sync/internal_api/public/base/model_type.h" | |
| 14 | |
| 15 namespace tracked_objects { | |
| 16 class Location; | |
| 17 } // namespace tracked_objects | |
| 18 | |
| 19 namespace syncer { | |
| 20 | |
| 21 // Sync errors are used for debug purposes and handled internally and/or | |
| 22 // exposed through Chrome's "about:sync" internal page. | |
| 23 // This class is copy-friendly and thread-safe. | |
| 24 class SYNC_EXPORT SyncError { | |
| 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, | |
| 32 // and sync should be disabled and purged completely. | |
| 33 DATATYPE_ERROR, // A datatype error was encountered, and the datatype | |
| 34 // should be disabled and purged completely. Note | |
| 35 // that datatype errors may be reset, triggering a | |
| 36 // re-enable. | |
| 37 PERSISTENCE_ERROR, // A persistence error was detected, and the | |
| 38 // datataype should be associated after a sync | |
| 39 // update. | |
| 40 CRYPTO_ERROR, // A cryptographer error was detected, and the | |
| 41 // datatype should be associated after it is | |
| 42 // resolved. | |
| 43 UNREADY_ERROR, // A datatype is not ready to start yet, so should be | |
| 44 // neither purged nor enabled until it is ready. | |
| 45 DATATYPE_POLICY_ERROR // A datatype should be disabled and purged due to | |
| 46 // configuration constraints. | |
| 47 }; | |
| 48 | |
| 49 // Severity is used to indicate how an error should be logged and | |
| 50 // represented to an end user. | |
| 51 enum Severity { | |
| 52 SYNC_ERROR_SEVERITY_ERROR, // Severe unrecoverable error. | |
| 53 SYNC_ERROR_SEVERITY_INFO // Low-severity recoverable error or | |
| 54 // configuration policy issue. | |
| 55 }; | |
| 56 | |
| 57 // Default constructor refers to "no error", and IsSet() will return false. | |
| 58 SyncError(); | |
| 59 | |
| 60 // Create a new Sync error of type |error_type| triggered by |model_type| | |
| 61 // from the specified location. IsSet() will return true afterward. Will | |
| 62 // create and print an error specific message to LOG(ERROR). | |
| 63 SyncError(const tracked_objects::Location& location, | |
| 64 ErrorType error_type, | |
| 65 const std::string& message, | |
| 66 ModelType model_type); | |
| 67 | |
| 68 // Copy and assign via deep copy. | |
| 69 SyncError(const SyncError& other); | |
| 70 SyncError& operator=(const SyncError& other); | |
| 71 | |
| 72 ~SyncError(); | |
| 73 | |
| 74 // Reset the current error to a new datatype error. May be called | |
| 75 // irrespective of whether IsSet() is true. After this is called, IsSet() | |
| 76 // will return true. | |
| 77 // Will print the new error to LOG(ERROR). | |
| 78 void Reset(const tracked_objects::Location& location, | |
| 79 const std::string& message, | |
| 80 ModelType type); | |
| 81 | |
| 82 // Whether this is a valid error or not. | |
| 83 bool IsSet() const; | |
| 84 | |
| 85 // These must only be called if IsSet() is true. | |
| 86 const tracked_objects::Location& location() const; | |
| 87 const std::string& message() const; | |
| 88 ModelType model_type() const; | |
| 89 ErrorType error_type() const; | |
| 90 | |
| 91 // Error severity for logging and UI purposes. | |
| 92 Severity GetSeverity() const; | |
| 93 // Type specific message prefix for logging and UI purposes. | |
| 94 std::string GetMessagePrefix() const; | |
| 95 | |
| 96 // Returns empty string is IsSet() is false. | |
| 97 std::string ToString() const; | |
| 98 | |
| 99 private: | |
| 100 // Print error information to log. | |
| 101 void PrintLogError() const; | |
| 102 | |
| 103 // Make a copy of a SyncError. If other.IsSet() == false, this->IsSet() will | |
| 104 // now return false. | |
| 105 void Copy(const SyncError& other); | |
| 106 | |
| 107 // Initialize the local error data with the specified error data. After this | |
| 108 // is called, IsSet() will return true. | |
| 109 void Init(const tracked_objects::Location& location, | |
| 110 const std::string& message, | |
| 111 ModelType model_type, | |
| 112 ErrorType error_type); | |
| 113 | |
| 114 // Reset the error to it's default (unset) values. | |
| 115 void Clear(); | |
| 116 | |
| 117 // unique_ptr is necessary because Location objects aren't assignable. | |
| 118 std::unique_ptr<tracked_objects::Location> location_; | |
| 119 std::string message_; | |
| 120 ModelType model_type_; | |
| 121 ErrorType error_type_; | |
| 122 }; | |
| 123 | |
| 124 // gmock printer helper. | |
| 125 SYNC_EXPORT void PrintTo(const SyncError& sync_error, std::ostream* os); | |
| 126 | |
| 127 } // namespace syncer | |
| 128 | |
| 129 #endif // SYNC_API_SYNC_ERROR_H_ | |
| OLD | NEW |