OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // source code is governed by a BSD-style license that can be found in the | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // LICENSE file. | 3 // found in the 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" |
11 #include "net/base/address_list.h" | 11 #include "net/base/address_list.h" |
12 #include "net/base/host_resolver.h" | 12 #include "net/base/host_resolver.h" |
13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 #include "net/base/net_log.h" |
14 #include "net/base/net_util.h" | 15 #include "net/base/net_util.h" |
15 #include "net/base/sys_addrinfo.h" | 16 #include "net/base/sys_addrinfo.h" |
16 | 17 |
17 namespace net { | 18 namespace net { |
18 namespace { | 19 namespace { |
19 | 20 |
20 // Wrapper around HostResolver to give a sync API while running the resolve | 21 // Wrapper around HostResolver to give a sync API while running the resolve |
21 // in async mode on |host_resolver_loop|. If |host_resolver_loop| is NULL, | 22 // in async mode on |host_resolver_loop|. If |host_resolver_loop| is NULL, |
22 // runs sync on the current thread (this mode is just used by testing). | 23 // runs sync on the current thread (this mode is just used by testing). |
23 class SyncHostResolverBridge | 24 class SyncHostResolverBridge |
(...skipping 11 matching lines...) Expand all Loading... |
35 // Run the resolve on host_resolver_loop, and wait for result. | 36 // Run the resolve on host_resolver_loop, and wait for result. |
36 int Resolve(const std::string& hostname, | 37 int Resolve(const std::string& hostname, |
37 AddressFamily address_family, | 38 AddressFamily address_family, |
38 net::AddressList* addresses) { | 39 net::AddressList* addresses) { |
39 // Port number doesn't matter. | 40 // Port number doesn't matter. |
40 HostResolver::RequestInfo info(hostname, 80); | 41 HostResolver::RequestInfo info(hostname, 80); |
41 info.set_address_family(address_family); | 42 info.set_address_family(address_family); |
42 | 43 |
43 // Hack for tests -- run synchronously on current thread. | 44 // Hack for tests -- run synchronously on current thread. |
44 if (!host_resolver_loop_) | 45 if (!host_resolver_loop_) |
45 return host_resolver_->Resolve(info, addresses, NULL, NULL, NULL); | 46 return host_resolver_->Resolve(info, addresses, NULL, NULL, |
| 47 BoundNetLog()); |
46 | 48 |
47 // Otherwise start an async resolve on the resolver's thread. | 49 // Otherwise start an async resolve on the resolver's thread. |
48 host_resolver_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 50 host_resolver_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
49 &SyncHostResolverBridge::StartResolve, info, addresses)); | 51 &SyncHostResolverBridge::StartResolve, info, addresses)); |
50 | 52 |
51 // Wait for the resolve to complete in the resolver's thread. | 53 // Wait for the resolve to complete in the resolver's thread. |
52 event_.Wait(); | 54 event_.Wait(); |
53 return err_; | 55 return err_; |
54 } | 56 } |
55 | 57 |
56 private: | 58 private: |
57 friend class base::RefCountedThreadSafe<SyncHostResolverBridge>; | 59 friend class base::RefCountedThreadSafe<SyncHostResolverBridge>; |
58 | 60 |
59 ~SyncHostResolverBridge() {} | 61 ~SyncHostResolverBridge() {} |
60 | 62 |
61 // Called on host_resolver_loop_. | 63 // Called on host_resolver_loop_. |
62 void StartResolve(const HostResolver::RequestInfo& info, | 64 void StartResolve(const HostResolver::RequestInfo& info, |
63 net::AddressList* addresses) { | 65 net::AddressList* addresses) { |
64 DCHECK_EQ(host_resolver_loop_, MessageLoop::current()); | 66 DCHECK_EQ(host_resolver_loop_, MessageLoop::current()); |
65 int error = host_resolver_->Resolve( | 67 int error = host_resolver_->Resolve( |
66 info, addresses, &callback_, NULL, NULL); | 68 info, addresses, &callback_, NULL, BoundNetLog()); |
67 if (error != ERR_IO_PENDING) | 69 if (error != ERR_IO_PENDING) |
68 OnResolveCompletion(error); // Completed synchronously. | 70 OnResolveCompletion(error); // Completed synchronously. |
69 } | 71 } |
70 | 72 |
71 // Called on host_resolver_loop_. | 73 // Called on host_resolver_loop_. |
72 void OnResolveCompletion(int result) { | 74 void OnResolveCompletion(int result) { |
73 DCHECK_EQ(host_resolver_loop_, MessageLoop::current()); | 75 DCHECK_EQ(host_resolver_loop_, MessageLoop::current()); |
74 err_ = result; | 76 err_ = result; |
75 event_.Signal(); | 77 event_.Signal(); |
76 } | 78 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 179 |
178 } // namespace | 180 } // namespace |
179 | 181 |
180 // static | 182 // static |
181 ProxyResolverJSBindings* ProxyResolverJSBindings::CreateDefault( | 183 ProxyResolverJSBindings* ProxyResolverJSBindings::CreateDefault( |
182 HostResolver* host_resolver, MessageLoop* host_resolver_loop) { | 184 HostResolver* host_resolver, MessageLoop* host_resolver_loop) { |
183 return new DefaultJSBindings(host_resolver, host_resolver_loop); | 185 return new DefaultJSBindings(host_resolver, host_resolver_loop); |
184 } | 186 } |
185 | 187 |
186 } // namespace net | 188 } // namespace net |
OLD | NEW |