diff options
author | Zeno Albisser <zeno.albisser@digia.com> | 2013-08-15 21:46:11 +0200 |
---|---|---|
committer | Zeno Albisser <zeno.albisser@digia.com> | 2013-08-15 21:46:11 +0200 |
commit | 679147eead574d186ebf3069647b4c23e8ccace6 (patch) | |
tree | fc247a0ac8ff119f7c8550879ebb6d3dd8d1ff69 /chromium/net/base/net_errors.cc |
Initial import.
Diffstat (limited to 'chromium/net/base/net_errors.cc')
-rw-r--r-- | chromium/net/base/net_errors.cc | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/chromium/net/base/net_errors.cc b/chromium/net/base/net_errors.cc new file mode 100644 index 00000000000..01fda3908ca --- /dev/null +++ b/chromium/net/base/net_errors.cc @@ -0,0 +1,63 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/base/net_errors.h" + +#include "base/basictypes.h" +#include "base/metrics/histogram.h" +#include "base/strings/stringize_macros.h" + +namespace { + +// Get all valid error codes into an array as positive numbers, for use in the +// |GetAllErrorCodesForUma| function below. +#define NET_ERROR(label, value) -(value), +const int kAllErrorCodes[] = { +#include "net/base/net_error_list.h" +}; +#undef NET_ERROR + +} // namespace + +namespace net { + +const char kErrorDomain[] = "net"; + +const char* ErrorToString(int error) { + if (error == 0) + return "net::OK"; + + switch (error) { +#define NET_ERROR(label, value) \ + case ERR_ ## label: \ + return "net::" STRINGIZE_NO_EXPANSION(ERR_ ## label); +#include "net/base/net_error_list.h" +#undef NET_ERROR + default: + return "net::<unknown>"; + } +} + +std::vector<int> GetAllErrorCodesForUma() { + return base::CustomHistogram::ArrayToCustomRanges( + kAllErrorCodes, arraysize(kAllErrorCodes)); +} + +Error PlatformFileErrorToNetError( + base::PlatformFileError file_error) { + switch (file_error) { + case base::PLATFORM_FILE_OK: + return net::OK; + case base::PLATFORM_FILE_ERROR_ACCESS_DENIED: + return net::ERR_ACCESS_DENIED; + case base::PLATFORM_FILE_ERROR_INVALID_URL: + return net::ERR_INVALID_URL; + case base::PLATFORM_FILE_ERROR_NOT_FOUND: + return net::ERR_FILE_NOT_FOUND; + default: + return net::ERR_FAILED; + } +} + +} // namespace net |