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 3 // found in the LICENSE file. 4 5 #include "net/base/net_errors.h" 6 7 #include "base/basictypes.h" 8 #include "base/metrics/histogram.h" 9 #include "base/strings/stringize_macros.h" 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 23 namespace net { 24 25 const char kErrorDomain[] = "net"; 26 27 const char* ErrorToString(int error) { 28 if (error == 0) 29 return "net::OK"; 30 31 switch (error) { 32 #define NET_ERROR(label, value) \ 33 case ERR_ ## label: \ 34 return "net::" STRINGIZE_NO_EXPANSION(ERR_ ## label); 35 #include "net/base/net_error_list.h" 36 #undef NET_ERROR 37 default: 38 return "net::<unknown>"; 39 } 40 } 41 42 std::vector<int> GetAllErrorCodesForUma() { 43 return base::CustomHistogram::ArrayToCustomRanges( 44 kAllErrorCodes, arraysize(kAllErrorCodes)); 45 } 46 47 Error PlatformFileErrorToNetError( 48 base::PlatformFileError file_error) { 49 switch (file_error) { 50 case base::PLATFORM_FILE_OK: 51 return net::OK; 52 case base::PLATFORM_FILE_ERROR_ACCESS_DENIED: 53 return net::ERR_ACCESS_DENIED; 54 case base::PLATFORM_FILE_ERROR_INVALID_URL: 55 return net::ERR_INVALID_URL; 56 case base::PLATFORM_FILE_ERROR_NOT_FOUND: 57 return net::ERR_FILE_NOT_FOUND; 58 default: 59 return net::ERR_FAILED; 60 } 61 } 62 63 } // namespace net 64