model_error.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2017 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. #ifndef COMPONENTS_SYNC_MODEL_MODEL_ERROR_H_
  5. #define COMPONENTS_SYNC_MODEL_MODEL_ERROR_H_
  6. #include <string>
  7. #include "base/callback.h"
  8. #include "base/location.h"
  9. #include "third_party/abseil-cpp/absl/types/optional.h"
  10. namespace syncer {
  11. class SyncError;
  12. // A minimal error object for use by USS model type code.
  13. class ModelError {
  14. public:
  15. // Creates a set error object with the given location and message.
  16. ModelError(const base::Location& location, const std::string& message);
  17. ~ModelError();
  18. // The location of the error this object represents. Can only be called if the
  19. // error is set.
  20. const base::Location& location() const;
  21. // The message explaining the error this object represents. Can only be called
  22. // if the error is set.
  23. const std::string& message() const;
  24. // Returns string representation of this object, appropriate for logging.
  25. std::string ToString() const;
  26. private:
  27. base::Location location_;
  28. std::string message_;
  29. };
  30. absl::optional<ModelError> ConvertToModelError(const SyncError& sync_error);
  31. // Typedef for a simple error handler callback.
  32. using ModelErrorHandler = base::RepeatingCallback<void(const ModelError&)>;
  33. using OnceModelErrorHandler = base::OnceCallback<void(const ModelError&)>;
  34. } // namespace syncer
  35. #endif // COMPONENTS_SYNC_MODEL_MODEL_ERROR_H_