| 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 20 matching lines...) Expand all Loading... |
| 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, net::AddressList* addresses) { |
| 36 // Port number doesn't matter. | 36 // Port number doesn't matter. |
| 37 HostResolver::RequestInfo info(hostname, 80); | 37 HostResolver::RequestInfo info(hostname, 80); |
| 38 | 38 |
| 39 // Hack for tests -- run synchronously on current thread. | 39 // Hack for tests -- run synchronously on current thread. |
| 40 if (!host_resolver_loop_) | 40 if (!host_resolver_loop_) |
| 41 return host_resolver_->Resolve(info, addresses, NULL, NULL); | 41 return host_resolver_->Resolve(NULL, info, addresses, NULL, NULL); |
| 42 | 42 |
| 43 // Otherwise start an async resolve on the resolver's thread. | 43 // Otherwise start an async resolve on the resolver's thread. |
| 44 host_resolver_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 44 host_resolver_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
| 45 &SyncHostResolverBridge::StartResolve, info, addresses)); | 45 &SyncHostResolverBridge::StartResolve, info, addresses)); |
| 46 | 46 |
| 47 // Wait for the resolve to complete in the resolver's thread. | 47 // Wait for the resolve to complete in the resolver's thread. |
| 48 event_.Wait(); | 48 event_.Wait(); |
| 49 return err_; | 49 return err_; |
| 50 } | 50 } |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 // Called on host_resolver_loop_. | 53 // Called on host_resolver_loop_. |
| 54 void StartResolve(const HostResolver::RequestInfo& info, | 54 void StartResolve(const HostResolver::RequestInfo& info, |
| 55 net::AddressList* addresses) { | 55 net::AddressList* addresses) { |
| 56 DCHECK_EQ(host_resolver_loop_, MessageLoop::current()); | 56 DCHECK_EQ(host_resolver_loop_, MessageLoop::current()); |
| 57 int error = host_resolver_->Resolve(info, addresses, &callback_, NULL); | 57 int error = host_resolver_->Resolve( |
| 58 NULL, info, addresses, &callback_, NULL); |
| 58 if (error != ERR_IO_PENDING) | 59 if (error != ERR_IO_PENDING) |
| 59 OnResolveCompletion(error); // Completed synchronously. | 60 OnResolveCompletion(error); // Completed synchronously. |
| 60 } | 61 } |
| 61 | 62 |
| 62 // Called on host_resolver_loop_. | 63 // Called on host_resolver_loop_. |
| 63 void OnResolveCompletion(int result) { | 64 void OnResolveCompletion(int result) { |
| 64 DCHECK_EQ(host_resolver_loop_, MessageLoop::current()); | 65 DCHECK_EQ(host_resolver_loop_, MessageLoop::current()); |
| 65 err_ = result; | 66 err_ = result; |
| 66 event_.Signal(); | 67 event_.Signal(); |
| 67 } | 68 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 135 |
| 135 } // namespace | 136 } // namespace |
| 136 | 137 |
| 137 // static | 138 // static |
| 138 ProxyResolverJSBindings* ProxyResolverJSBindings::CreateDefault( | 139 ProxyResolverJSBindings* ProxyResolverJSBindings::CreateDefault( |
| 139 HostResolver* host_resolver, MessageLoop* host_resolver_loop) { | 140 HostResolver* host_resolver, MessageLoop* host_resolver_loop) { |
| 140 return new DefaultJSBindings(host_resolver, host_resolver_loop); | 141 return new DefaultJSBindings(host_resolver, host_resolver_loop); |
| 141 } | 142 } |
| 142 | 143 |
| 143 } // namespace net | 144 } // namespace net |
| OLD | NEW |