[email protected] | aa166d0 | 2012-12-11 23:47:42 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors. All rights reserved. |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 895a1e5 | 2012-05-15 02:50:12 | [diff] [blame] | 5 | #ifndef SYNC_API_SYNC_ERROR_H_ |
| 6 | #define SYNC_API_SYNC_ERROR_H_ |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 7 | |
[email protected] | 2d05d148 | 2011-09-23 00:34:36 | [diff] [blame] | 8 | #include <iosfwd> |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 9 | #include <string> |
| 10 | |
| 11 | #include "base/memory/scoped_ptr.h" |
[email protected] | aa166d0 | 2012-12-11 23:47:42 | [diff] [blame] | 12 | #include "sync/base/sync_export.h" |
[email protected] | 002d3919 | 2012-07-03 01:30:56 | [diff] [blame] | 13 | #include "sync/internal_api/public/base/model_type.h" |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 14 | |
| 15 | namespace tracked_objects { |
| 16 | class Location; |
| 17 | } // namespace tracked_objects |
| 18 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 19 | namespace syncer { |
[email protected] | cb02f61 | 2012-06-27 03:15:50 | [diff] [blame] | 20 | |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 21 | // Sync errors are used for debug purposes and handled internally and/or |
[email protected] | 651da62 | 2013-07-02 23:24:04 | [diff] [blame] | 22 | // exposed through Chrome's "about:sync" internal page. |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 23 | // This class is copy-friendly and thread-safe. |
[email protected] | aa166d0 | 2012-12-11 23:47:42 | [diff] [blame] | 24 | class SYNC_EXPORT SyncError { |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 25 | public: |
[email protected] | 651da62 | 2013-07-02 23:24:04 | [diff] [blame] | 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 | |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 41 | // Default constructor refers to "no error", and IsSet() will return false. |
| 42 | SyncError(); |
| 43 | |
[email protected] | 651da62 | 2013-07-02 23:24:04 | [diff] [blame] | 44 | // Create a new Sync error of type |error_type| triggered by |model_type| |
| 45 | // from the specified location. IsSet() will return true afterward. Will |
| 46 | // create and print an error specific message to LOG(ERROR). |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 47 | SyncError(const tracked_objects::Location& location, |
[email protected] | 651da62 | 2013-07-02 23:24:04 | [diff] [blame] | 48 | ErrorType error_type, |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 49 | const std::string& message, |
[email protected] | 651da62 | 2013-07-02 23:24:04 | [diff] [blame] | 50 | ModelType model_type); |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 51 | |
| 52 | // Copy and assign via deep copy. |
| 53 | SyncError(const SyncError& other); |
| 54 | SyncError& operator=(const SyncError& other); |
| 55 | |
| 56 | ~SyncError(); |
| 57 | |
[email protected] | 651da62 | 2013-07-02 23:24:04 | [diff] [blame] | 58 | // Reset the current error to a new datatype error. May be called |
| 59 | // irrespective of whether IsSet() is true. After this is called, IsSet() |
| 60 | // will return true. |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 61 | // Will print the new error to LOG(ERROR). |
| 62 | void Reset(const tracked_objects::Location& location, |
| 63 | const std::string& message, |
[email protected] | d45f0d9 | 2012-07-20 17:25:41 | [diff] [blame] | 64 | ModelType type); |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 65 | |
| 66 | // Whether this is a valid error or not. |
| 67 | bool IsSet() const; |
| 68 | |
| 69 | // These must only be called if IsSet() is true. |
| 70 | const tracked_objects::Location& location() const; |
| 71 | const std::string& message() const; |
[email protected] | 651da62 | 2013-07-02 23:24:04 | [diff] [blame] | 72 | ModelType model_type() const; |
| 73 | ErrorType error_type() const; |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 74 | |
[email protected] | 8b0a57a | 2011-09-28 01:06:08 | [diff] [blame] | 75 | // Returns empty string is IsSet() is false. |
[email protected] | 2d05d148 | 2011-09-23 00:34:36 | [diff] [blame] | 76 | std::string ToString() const; |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 77 | private: |
| 78 | // Print error information to log. |
| 79 | void PrintLogError() const; |
| 80 | |
| 81 | // Make a copy of a SyncError. If other.IsSet() == false, this->IsSet() will |
| 82 | // now return false. |
| 83 | void Copy(const SyncError& other); |
| 84 | |
| 85 | // Initialize the local error data with the specified error data. After this |
| 86 | // is called, IsSet() will return true. |
| 87 | void Init(const tracked_objects::Location& location, |
| 88 | const std::string& message, |
[email protected] | 651da62 | 2013-07-02 23:24:04 | [diff] [blame] | 89 | ModelType model_type, |
| 90 | ErrorType error_type); |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 91 | |
| 92 | // Reset the error to it's default (unset) values. |
| 93 | void Clear(); |
| 94 | |
| 95 | // scoped_ptr is necessary because Location objects aren't assignable. |
| 96 | scoped_ptr<tracked_objects::Location> location_; |
| 97 | std::string message_; |
[email protected] | 651da62 | 2013-07-02 23:24:04 | [diff] [blame] | 98 | ModelType model_type_; |
| 99 | ErrorType error_type_; |
[email protected] | de7d78c7 | 2011-07-26 23:41:50 | [diff] [blame] | 100 | }; |
| 101 | |
[email protected] | 2d05d148 | 2011-09-23 00:34:36 | [diff] [blame] | 102 | // gmock printer helper. |
[email protected] | cc7a544c | 2013-01-02 08:31:51 | [diff] [blame] | 103 | SYNC_EXPORT void PrintTo(const SyncError& sync_error, std::ostream* os); |
[email protected] | 2d05d148 | 2011-09-23 00:34:36 | [diff] [blame] | 104 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 105 | } // namespace syncer |
[email protected] | cb02f61 | 2012-06-27 03:15:50 | [diff] [blame] | 106 | |
[email protected] | 895a1e5 | 2012-05-15 02:50:12 | [diff] [blame] | 107 | #endif // SYNC_API_SYNC_ERROR_H_ |