1 // Copyright 2020 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 CHROME_BROWSER_NEARBY_SHARING_COMMON_NEARBY_SHARE_HTTP_RESULT_H_
6 #define CHROME_BROWSER_NEARBY_SHARING_COMMON_NEARBY_SHARE_HTTP_RESULT_H_
7 
8 #include <ostream>
9 
10 enum class NearbyShareHttpError {
11   // Request could not be completed because the device is offline or has issues
12   // sending the HTTP request.
13   kOffline,
14 
15   // Server endpoint could not be found.
16   kEndpointNotFound,
17 
18   // Authentication error contacting back-end.
19   kAuthenticationError,
20 
21   // Request was invalid.
22   kBadRequest,
23 
24   // The server responded, but the response was not formatted correctly.
25   kResponseMalformed,
26 
27   // Internal server error.
28   kInternalServerError,
29 
30   // Unknown result.
31   kUnknown
32 };
33 
34 // These values are persisted to logs. Entries should not be renumbered and
35 // numeric values should never be reused.
36 enum class NearbyShareHttpResult {
37   kSuccess = 0,
38   kTimeout = 1,
39   kHttpErrorOffline = 2,
40   kHttpErrorEndpointNotFound = 3,
41   kHttpErrorAuthenticationError = 4,
42   kHttpErrorBadRequest = 5,
43   kHttpErrorResponseMalformed = 6,
44   kHttpErrorInternalServerError = 7,
45   kHttpErrorUnknown = 8,
46   kMaxValue = kHttpErrorUnknown
47 };
48 
49 NearbyShareHttpError NearbyShareHttpErrorForHttpResponseCode(int response_code);
50 NearbyShareHttpResult NearbyShareHttpErrorToResult(NearbyShareHttpError error);
51 
52 std::ostream& operator<<(std::ostream& stream,
53                          const NearbyShareHttpResult& error);
54 std::ostream& operator<<(std::ostream& stream,
55                          const NearbyShareHttpError& error);
56 
57 #endif  // CHROME_BROWSER_NEARBY_SHARING_COMMON_NEARBY_SHARE_HTTP_RESULT_H_
58