OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
3 // LICENSE file. | 3 // LICENSE file. |
4 | 4 |
5 #include "net/proxy/proxy_resolver_js_bindings.h" | 5 #include "net/proxy/proxy_resolver_js_bindings.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/waitable_event.h" | 10 #include "base/waitable_event.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 SyncHostResolverBridge(HostResolver* host_resolver, | 25 SyncHostResolverBridge(HostResolver* host_resolver, |
26 MessageLoop* host_resolver_loop) | 26 MessageLoop* host_resolver_loop) |
27 : host_resolver_(host_resolver), | 27 : host_resolver_(host_resolver), |
28 host_resolver_loop_(host_resolver_loop), | 28 host_resolver_loop_(host_resolver_loop), |
29 event_(false, false), | 29 event_(false, false), |
30 ALLOW_THIS_IN_INITIALIZER_LIST( | 30 ALLOW_THIS_IN_INITIALIZER_LIST( |
31 callback_(this, &SyncHostResolverBridge::OnResolveCompletion)) { | 31 callback_(this, &SyncHostResolverBridge::OnResolveCompletion)) { |
32 } | 32 } |
33 | 33 |
34 // Run the resolve on host_resolver_loop, and wait for result. | 34 // Run the resolve on host_resolver_loop, and wait for result. |
35 int Resolve(const std::string& hostname, net::AddressList* addresses) { | 35 int Resolve(const std::string& hostname, |
36 AddressFamily address_family, | |
37 net::AddressList* addresses) { | |
36 // Port number doesn't matter. | 38 // Port number doesn't matter. |
37 HostResolver::RequestInfo info(hostname, 80); | 39 HostResolver::RequestInfo info(hostname, 80); |
40 info.set_address_family(address_family); | |
38 | 41 |
39 // Hack for tests -- run synchronously on current thread. | 42 // Hack for tests -- run synchronously on current thread. |
40 if (!host_resolver_loop_) | 43 if (!host_resolver_loop_) |
41 return host_resolver_->Resolve(info, addresses, NULL, NULL, NULL); | 44 return host_resolver_->Resolve(info, addresses, NULL, NULL, NULL); |
42 | 45 |
43 // Otherwise start an async resolve on the resolver's thread. | 46 // Otherwise start an async resolve on the resolver's thread. |
44 host_resolver_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 47 host_resolver_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
45 &SyncHostResolverBridge::StartResolve, info, addresses)); | 48 &SyncHostResolverBridge::StartResolve, info, addresses)); |
46 | 49 |
47 // Wait for the resolve to complete in the resolver's thread. | 50 // Wait for the resolve to complete in the resolver's thread. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 } | 103 } |
101 | 104 |
102 // Handler for "dnsResolve(host)". Returns empty string on failure. | 105 // Handler for "dnsResolve(host)". Returns empty string on failure. |
103 virtual std::string DnsResolve(const std::string& host) { | 106 virtual std::string DnsResolve(const std::string& host) { |
104 // TODO(eroman): Should this return our IP address, or fail, or | 107 // TODO(eroman): Should this return our IP address, or fail, or |
105 // simply be unspecified (works differently on windows and mac os x). | 108 // simply be unspecified (works differently on windows and mac os x). |
106 if (host.empty()) | 109 if (host.empty()) |
107 return std::string(); | 110 return std::string(); |
108 | 111 |
109 // Do a sync resolve of the hostname. | 112 // Do a sync resolve of the hostname. |
113 // Disable IPv6 results, see http://crbug.com/24641 for motivation. | |
wtc
2009/10/22 21:53:54
The motivation is short (dnsResolve is IPv4 only).
| |
110 net::AddressList address_list; | 114 net::AddressList address_list; |
111 int result = host_resolver_->Resolve(host, &address_list); | 115 int result = host_resolver_->Resolve(host, |
116 ADDRESS_FAMILY_IPV4_ONLY, | |
wtc
2009/10/22 21:53:54
Nit: do we really need _ONLY in the enum constant
| |
117 &address_list); | |
112 | 118 |
113 if (result != OK) | 119 if (result != OK) |
114 return std::string(); // Failed. | 120 return std::string(); // Failed. |
115 | 121 |
116 if (!address_list.head()) | 122 if (!address_list.head()) |
117 return std::string(); | 123 return std::string(); |
118 | 124 |
119 // There may be multiple results; we will just use the first one. | 125 // There may be multiple results; we will just use the first one. |
120 // This returns empty string on failure. | 126 // This returns empty string on failure. |
121 return net::NetAddressToString(address_list.head()); | 127 return net::NetAddressToString(address_list.head()); |
(...skipping 13 matching lines...) Expand all Loading... | |
135 | 141 |
136 } // namespace | 142 } // namespace |
137 | 143 |
138 // static | 144 // static |
139 ProxyResolverJSBindings* ProxyResolverJSBindings::CreateDefault( | 145 ProxyResolverJSBindings* ProxyResolverJSBindings::CreateDefault( |
140 HostResolver* host_resolver, MessageLoop* host_resolver_loop) { | 146 HostResolver* host_resolver, MessageLoop* host_resolver_loop) { |
141 return new DefaultJSBindings(host_resolver, host_resolver_loop); | 147 return new DefaultJSBindings(host_resolver, host_resolver_loop); |
142 } | 148 } |
143 | 149 |
144 } // namespace net | 150 } // namespace net |
OLD | NEW |