OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "remoting/client/ipc_host_resolver.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "content/renderer/p2p/host_address_request.h" |
| 9 #include "content/renderer/p2p/socket_dispatcher.h" |
| 10 #include "net/base/ip_endpoint.h" |
| 11 #include "jingle/glue/utils.h" |
| 12 |
| 13 namespace remoting { |
| 14 |
| 15 class IpcHostResolver : public HostResolver { |
| 16 public: |
| 17 IpcHostResolver(P2PSocketDispatcher* socket_dispatcher) |
| 18 : socket_dispatcher_(socket_dispatcher) { |
| 19 } |
| 20 |
| 21 virtual ~IpcHostResolver() { |
| 22 if (request_) |
| 23 request_->Cancel(); |
| 24 } |
| 25 |
| 26 virtual void Resolve(const talk_base::SocketAddress& address) OVERRIDE { |
| 27 if (address.IsUnresolved()) { |
| 28 port_ = address.port(); |
| 29 request_ = new P2PHostAddressRequest(socket_dispatcher_); |
| 30 request_->Request(address.hostname(), base::Bind( |
| 31 &IpcHostResolver::OnDone, base::Unretained(this))); |
| 32 } else { |
| 33 SignalDone(this, address); |
| 34 } |
| 35 } |
| 36 |
| 37 private: |
| 38 void OnDone(const net::IPAddressNumber& address) { |
| 39 talk_base::SocketAddress socket_address; |
| 40 if (address.empty() || |
| 41 !jingle_glue::IPEndPointToSocketAddress( |
| 42 net::IPEndPoint(address, port_), &socket_address)) { |
| 43 // Return nil address if the request has failed. |
| 44 SignalDone(this, talk_base::SocketAddress()); |
| 45 return; |
| 46 } |
| 47 |
| 48 request_ = NULL; |
| 49 SignalDone(this, socket_address); |
| 50 } |
| 51 |
| 52 P2PSocketDispatcher* socket_dispatcher_; |
| 53 scoped_refptr<P2PHostAddressRequest> request_; |
| 54 uint16 port_; |
| 55 }; |
| 56 |
| 57 IpcHostResolverFactory::IpcHostResolverFactory( |
| 58 P2PSocketDispatcher* socket_dispatcher) |
| 59 : socket_dispatcher_(socket_dispatcher) { |
| 60 } |
| 61 |
| 62 IpcHostResolverFactory::~IpcHostResolverFactory() { |
| 63 } |
| 64 |
| 65 HostResolver* IpcHostResolverFactory::CreateHostResolver() { |
| 66 return new IpcHostResolver(socket_dispatcher_); |
| 67 } |
| 68 |
| 69 } // namespace remoting |
OLD | NEW |