Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/base/net_errors.h" | 5 #include "net/base/net_errors.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/strings/stringize_macros.h" | 9 #include "base/strings/stringize_macros.h" |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 // Get all valid error codes into an array as positive numbers, for use in the | 13 // Get all valid error codes into an array as positive numbers, for use in the |
| 14 // |GetAllErrorCodesForUma| function below. | 14 // |GetAllErrorCodesForUma| function below. |
| 15 #define NET_ERROR(label, value) -(value), | 15 #define NET_ERROR(label, value) -(value), |
| 16 const int kAllErrorCodes[] = { | 16 const int kAllErrorCodes[] = { |
| 17 #include "net/base/net_error_list.h" | 17 #include "net/base/net_error_list.h" |
| 18 }; | 18 }; |
| 19 #undef NET_ERROR | 19 #undef NET_ERROR |
| 20 | 20 |
| 21 } // namespace | 21 } // namespace |
| 22 | 22 |
| 23 namespace net { | 23 namespace net { |
| 24 | 24 |
| 25 const char kErrorDomain[] = "net"; | 25 const char kErrorDomain[] = "net"; |
| 26 | 26 |
| 27 const char* ErrorToString(int error) { | 27 std::string ErrorToShortString(int error) { |
| 28 if (error == 0) | 28 if (error == 0) |
| 29 return "net::OK"; | 29 return "OK"; |
| 30 | 30 |
| 31 const char* error_string; | |
| 31 switch (error) { | 32 switch (error) { |
| 32 #define NET_ERROR(label, value) \ | 33 #define NET_ERROR(label, value) \ |
| 33 case ERR_ ## label: \ | 34 case ERR_ ## label: \ |
| 34 return "net::" STRINGIZE_NO_EXPANSION(ERR_ ## label); | 35 error_string = # label; \ |
| 36 break; | |
| 35 #include "net/base/net_error_list.h" | 37 #include "net/base/net_error_list.h" |
| 36 #undef NET_ERROR | 38 #undef NET_ERROR |
| 37 default: | 39 default: |
| 38 return "net::<unknown>"; | 40 return "<unknown>"; |
|
eroman
2014/08/05 22:54:51
Should this be prefixed with ERR_ too?
mmenke
2014/08/06 16:40:56
Done. I did that initially, but it looks kinda we
| |
| 39 } | 41 } |
| 42 return std::string("ERR_").append(error_string); | |
|
eroman
2014/08/05 22:54:50
nit: below you use operator+ to concatenate string
mmenke
2014/08/06 16:40:56
Done.
| |
| 43 } | |
| 44 | |
| 45 std::string ErrorToString(int error) { | |
| 46 return "net::" + ErrorToShortString(error); | |
| 47 } | |
| 48 | |
| 49 bool IsCertificateError(int error) { | |
| 50 // Certificate errors are negative integers from net::ERR_CERT_BEGIN | |
| 51 // (inclusive) to net::ERR_CERT_END (exclusive) in *decreasing* order. | |
| 52 // ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN is currently an exception to this | |
| 53 // rule. | |
| 54 return (error <= ERR_CERT_BEGIN && error > ERR_CERT_END) || | |
|
eroman
2014/08/05 22:54:50
I presume this is unchanged, did not review.
mmenke
2014/08/06 16:40:56
Correct. I just moved it, since it was incorrectl
| |
| 55 (error == ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN); | |
| 40 } | 56 } |
| 41 | 57 |
| 42 std::vector<int> GetAllErrorCodesForUma() { | 58 std::vector<int> GetAllErrorCodesForUma() { |
| 43 return base::CustomHistogram::ArrayToCustomRanges( | 59 return base::CustomHistogram::ArrayToCustomRanges( |
| 44 kAllErrorCodes, arraysize(kAllErrorCodes)); | 60 kAllErrorCodes, arraysize(kAllErrorCodes)); |
| 45 } | 61 } |
| 46 | 62 |
| 47 Error FileErrorToNetError(base::File::Error file_error) { | 63 Error FileErrorToNetError(base::File::Error file_error) { |
| 48 switch (file_error) { | 64 switch (file_error) { |
| 49 case base::File::FILE_OK: | 65 case base::File::FILE_OK: |
| 50 return net::OK; | 66 return net::OK; |
| 51 case base::File::FILE_ERROR_ACCESS_DENIED: | 67 case base::File::FILE_ERROR_ACCESS_DENIED: |
| 52 return net::ERR_ACCESS_DENIED; | 68 return net::ERR_ACCESS_DENIED; |
| 53 case base::File::FILE_ERROR_INVALID_URL: | 69 case base::File::FILE_ERROR_INVALID_URL: |
| 54 return net::ERR_INVALID_URL; | 70 return net::ERR_INVALID_URL; |
| 55 case base::File::FILE_ERROR_NOT_FOUND: | 71 case base::File::FILE_ERROR_NOT_FOUND: |
| 56 return net::ERR_FILE_NOT_FOUND; | 72 return net::ERR_FILE_NOT_FOUND; |
| 57 default: | 73 default: |
| 58 return net::ERR_FAILED; | 74 return net::ERR_FAILED; |
| 59 } | 75 } |
| 60 } | 76 } |
| 61 | 77 |
| 62 } // namespace net | 78 } // namespace net |
| OLD | NEW |