OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/stringize_macros.h" | 9 #include "base/stringize_macros.h" |
9 | 10 |
| 11 namespace { |
| 12 |
| 13 // Get all valid error codes into an array as positive numbers, for use in the |
| 14 // |GetAllErrorCodesForUma| function below. |
| 15 #define NET_ERROR(label, value) -(value), |
| 16 const int kAllErrorCodes[] = { |
| 17 #include "net/base/net_error_list.h" |
| 18 }; |
| 19 #undef NET_ERROR |
| 20 |
| 21 } // namespace |
| 22 |
10 namespace net { | 23 namespace net { |
11 | 24 |
12 const char kErrorDomain[] = "net"; | 25 const char kErrorDomain[] = "net"; |
13 | 26 |
14 const char* ErrorToString(int error) { | 27 const char* ErrorToString(int error) { |
15 if (error == 0) | 28 if (error == 0) |
16 return "net::OK"; | 29 return "net::OK"; |
17 | 30 |
18 switch (error) { | 31 switch (error) { |
19 #define NET_ERROR(label, value) \ | 32 #define NET_ERROR(label, value) \ |
20 case ERR_ ## label: \ | 33 case ERR_ ## label: \ |
21 return "net::" STRINGIZE_NO_EXPANSION(ERR_ ## label); | 34 return "net::" STRINGIZE_NO_EXPANSION(ERR_ ## label); |
22 #include "net/base/net_error_list.h" | 35 #include "net/base/net_error_list.h" |
23 #undef NET_ERROR | 36 #undef NET_ERROR |
24 default: | 37 default: |
25 return "net::<unknown>"; | 38 return "net::<unknown>"; |
26 } | 39 } |
27 } | 40 } |
28 | 41 |
| 42 std::vector<int> GetAllErrorCodesForUma() { |
| 43 return base::CustomHistogram::ArrayToCustomRanges( |
| 44 kAllErrorCodes, arraysize(kAllErrorCodes)); |
| 45 } |
| 46 |
29 } // namespace net | 47 } // namespace net |
OLD | NEW |