| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/host_resolver_impl.h" | 5 #include "net/base/host_resolver_impl.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <Winsock2.h> | 8 #include <Winsock2.h> |
| 9 #elif defined(OS_POSIX) | 9 #elif defined(OS_POSIX) |
| 10 #include <netdb.h> | 10 #include <netdb.h> |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include <cmath> | 13 #include <cmath> |
| 14 #include <deque> | 14 #include <deque> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
| 18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
| 19 #include "base/debug_util.h" | 19 #include "base/debug_util.h" |
| 20 #include "base/histogram.h" | 20 #include "base/histogram.h" |
| 21 #include "base/lock.h" | 21 #include "base/lock.h" |
| 22 #include "base/message_loop.h" | 22 #include "base/message_loop.h" |
| 23 #include "base/stl_util-inl.h" | 23 #include "base/stl_util-inl.h" |
| 24 #include "base/string_util.h" | 24 #include "base/string_util.h" |
| 25 #include "base/time.h" | 25 #include "base/time.h" |
| 26 #include "base/utf_string_conversions.h" |
| 26 #include "base/values.h" | 27 #include "base/values.h" |
| 27 #include "base/worker_pool.h" | 28 #include "base/worker_pool.h" |
| 28 #include "net/base/address_list.h" | 29 #include "net/base/address_list.h" |
| 29 #include "net/base/host_resolver_proc.h" | 30 #include "net/base/host_resolver_proc.h" |
| 30 #include "net/base/net_log.h" | 31 #include "net/base/net_log.h" |
| 31 #include "net/base/net_errors.h" | 32 #include "net/base/net_errors.h" |
| 32 #include "net/base/net_util.h" | 33 #include "net/base/net_util.h" |
| 33 | 34 |
| 34 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
| 35 #include "net/base/winsock_init.h" | 36 #include "net/base/winsock_init.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 class HostResolveFailedParams : public NetLog::EventParameters { | 89 class HostResolveFailedParams : public NetLog::EventParameters { |
| 89 public: | 90 public: |
| 90 HostResolveFailedParams(int net_error, int os_error, bool was_from_cache) | 91 HostResolveFailedParams(int net_error, int os_error, bool was_from_cache) |
| 91 : net_error_(net_error), | 92 : net_error_(net_error), |
| 92 os_error_(os_error), | 93 os_error_(os_error), |
| 93 was_from_cache_(was_from_cache) { | 94 was_from_cache_(was_from_cache) { |
| 94 } | 95 } |
| 95 | 96 |
| 96 virtual Value* ToValue() const { | 97 virtual Value* ToValue() const { |
| 97 DictionaryValue* dict = new DictionaryValue(); | 98 DictionaryValue* dict = new DictionaryValue(); |
| 98 dict->SetInteger(L"net_error", net_error_); | 99 dict->SetInteger("net_error", net_error_); |
| 99 dict->SetBoolean(L"was_from_cache", was_from_cache_); | 100 dict->SetBoolean("was_from_cache", was_from_cache_); |
| 100 | 101 |
| 101 if (os_error_) { | 102 if (os_error_) { |
| 102 dict->SetInteger(L"os_error", os_error_); | 103 dict->SetInteger("os_error", os_error_); |
| 103 #if defined(OS_POSIX) | 104 #if defined(OS_POSIX) |
| 104 dict->SetString(L"os_error_string", gai_strerror(os_error_)); | 105 dict->SetString("os_error_string", gai_strerror(os_error_)); |
| 105 #elif defined(OS_WIN) | 106 #elif defined(OS_WIN) |
| 106 // Map the error code to a human-readable string. | 107 // Map the error code to a human-readable string. |
| 107 LPWSTR error_string = NULL; | 108 LPWSTR error_string = NULL; |
| 108 int size = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | | 109 int size = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
| 109 FORMAT_MESSAGE_FROM_SYSTEM, | 110 FORMAT_MESSAGE_FROM_SYSTEM, |
| 110 0, // Use the internal message table. | 111 0, // Use the internal message table. |
| 111 os_error_, | 112 os_error_, |
| 112 0, // Use default language. | 113 0, // Use default language. |
| 113 (LPWSTR)&error_string, | 114 (LPWSTR)&error_string, |
| 114 0, // Buffer size. | 115 0, // Buffer size. |
| 115 0); // Arguments (unused). | 116 0); // Arguments (unused). |
| 116 dict->SetString(L"os_error_string", error_string); | 117 dict->SetString("os_error_string", WideToUTF8(error_string)); |
| 117 LocalFree(error_string); | 118 LocalFree(error_string); |
| 118 #endif | 119 #endif |
| 119 } | 120 } |
| 120 | 121 |
| 121 return dict; | 122 return dict; |
| 122 } | 123 } |
| 123 | 124 |
| 124 private: | 125 private: |
| 125 const int net_error_; | 126 const int net_error_; |
| 126 const int os_error_; | 127 const int os_error_; |
| (...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 if (r == req) | 1167 if (r == req) |
| 1167 return error; | 1168 return error; |
| 1168 | 1169 |
| 1169 r->OnComplete(error, AddressList()); | 1170 r->OnComplete(error, AddressList()); |
| 1170 } | 1171 } |
| 1171 | 1172 |
| 1172 return ERR_IO_PENDING; | 1173 return ERR_IO_PENDING; |
| 1173 } | 1174 } |
| 1174 | 1175 |
| 1175 } // namespace net | 1176 } // namespace net |
| OLD | NEW |