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