Index: remoting/client/ipc_host_address_resolver.cc |
diff --git a/remoting/client/ipc_host_address_resolver.cc b/remoting/client/ipc_host_address_resolver.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..51fe291ab760d36480b17f60de80d7953e38740d |
--- /dev/null |
+++ b/remoting/client/ipc_host_address_resolver.cc |
@@ -0,0 +1,63 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "remoting/client/ipc_host_address_resolver.h" |
+ |
+#include "base/bind.h" |
+#include "content/renderer/p2p/host_address_request.h" |
+#include "content/renderer/p2p/socket_dispatcher.h" |
+#include "net/base/ip_endpoint.h" |
+#include "jingle/glue/utils.h" |
+ |
+namespace remoting { |
+ |
+class IpcHostAddressRequest : public HostAddressRequest { |
+ public: |
+ IpcHostAddressRequest(P2PSocketDispatcher* socket_dispatcher) |
+ : socket_dispatcher_(socket_dispatcher) { |
+ } |
+ |
+ virtual ~IpcHostAddressRequest() OVERRIDE { |
+ if (request_) |
+ request_->Cancel(); |
Wez
2011/08/08 23:07:59
nit: I don't recall the other CL guaranteeing that
Sergey Ulanov
2011/08/09 01:42:16
It does guarantee it, otherwise what's the point o
|
+ } |
+ |
+ virtual void Request(const std::string& host_name) OVERRIDE { |
+ request_ = new P2PHostAddressRequest(socket_dispatcher_); |
+ request_->Request(host_name, base::Bind( |
+ &IpcHostAddressRequest::OnDone, base::Unretained(this))); |
+ } |
+ |
+ private: |
+ void OnDone(const net::IPAddressNumber& address) { |
+ talk_base::SocketAddress socket_address; |
+ if (address.empty() || |
+ !jingle_glue::IPEndPointToSocketAddress( |
+ net::IPEndPoint(address, 0), &socket_address)) { |
+ // Return nil address if the request has failed. |
+ SignalDone(this, talk_base::SocketAddress()); |
+ return; |
+ } |
+ |
+ request_ = NULL; |
+ SignalDone(this, socket_address); |
+ } |
+ |
+ P2PSocketDispatcher* socket_dispatcher_; |
+ scoped_refptr<P2PHostAddressRequest> request_; |
+}; |
+ |
+IpcHostAddressResolver::IpcHostAddressResolver( |
+ P2PSocketDispatcher* socket_dispatcher) |
+ : socket_dispatcher_(socket_dispatcher) { |
+} |
+ |
+IpcHostAddressResolver::~IpcHostAddressResolver() { |
+} |
+ |
+HostAddressRequest* IpcHostAddressResolver::CreateRequest() { |
+ return new IpcHostAddressRequest(socket_dispatcher_); |
+} |
+ |
+} // namespace remoting |