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