status.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2018 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_INVALIDATION_IMPL_STATUS_H_
  5. #define COMPONENTS_INVALIDATION_IMPL_STATUS_H_
  6. #include <string>
  7. namespace invalidation {
  8. // Status of the message arrived from FCM.
  9. // Used by UMA histogram, so entries shouldn't be reordered or removed.
  10. enum class InvalidationParsingStatus {
  11. kSuccess = 0,
  12. kPublicTopicEmpty = 1,
  13. kPrivateTopicEmpty = 2,
  14. kVersionEmpty = 3,
  15. kVersionInvalid = 4,
  16. kMaxValue = kVersionInvalid,
  17. };
  18. // This enum indicates how an operation was completed. These values are written
  19. // to logs. New enum values can be added, but existing enums must never be
  20. // renumbered or deleted and reused.
  21. enum class StatusCode {
  22. // The operation has been completed successfully.
  23. SUCCESS = 0,
  24. // Failed with HTTP 401.
  25. AUTH_FAILURE = 1,
  26. // The operation failed.
  27. FAILED = 2,
  28. // Something is terribly wrong and we shohuldn't retry the requests until
  29. // next startup.
  30. FAILED_NON_RETRIABLE = 3,
  31. };
  32. // This struct provides the status code of a request and an optional message
  33. // describing the status (esp. failures) in detail.
  34. struct Status {
  35. Status(StatusCode status_code, const std::string& message);
  36. ~Status();
  37. // Errors always need a message but a success does not.
  38. static Status Success();
  39. bool IsSuccess() const { return code == StatusCode::SUCCESS; }
  40. bool IsAuthFailure() const { return code == StatusCode::AUTH_FAILURE; }
  41. bool ShouldRetry() const { return code == StatusCode::FAILED; }
  42. StatusCode code;
  43. // The message is not meant to be displayed to the user.
  44. std::string message;
  45. // Copy and assignment allowed.
  46. };
  47. } // namespace invalidation
  48. #endif // COMPONENTS_INVALIDATION_IMPL_STATUS_H_