Chromium Code Reviews| 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_address_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 IpcHostAddressRequest : public HostAddressRequest { | |
| 16 public: | |
| 17 IpcHostAddressRequest(P2PSocketDispatcher* socket_dispatcher) | |
| 18 : socket_dispatcher_(socket_dispatcher) { | |
| 19 } | |
| 20 | |
| 21 virtual ~IpcHostAddressRequest() OVERRIDE { | |
| 22 if (request_) | |
| 23 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
| |
| 24 } | |
| 25 | |
| 26 virtual void Request(const std::string& host_name) OVERRIDE { | |
| 27 request_ = new P2PHostAddressRequest(socket_dispatcher_); | |
| 28 request_->Request(host_name, base::Bind( | |
| 29 &IpcHostAddressRequest::OnDone, base::Unretained(this))); | |
| 30 } | |
| 31 | |
| 32 private: | |
| 33 void OnDone(const net::IPAddressNumber& address) { | |
| 34 talk_base::SocketAddress socket_address; | |
| 35 if (address.empty() || | |
| 36 !jingle_glue::IPEndPointToSocketAddress( | |
| 37 net::IPEndPoint(address, 0), &socket_address)) { | |
| 38 // Return nil address if the request has failed. | |
| 39 SignalDone(this, talk_base::SocketAddress()); | |
| 40 return; | |
| 41 } | |
| 42 | |
| 43 request_ = NULL; | |
| 44 SignalDone(this, socket_address); | |
| 45 } | |
| 46 | |
| 47 P2PSocketDispatcher* socket_dispatcher_; | |
| 48 scoped_refptr<P2PHostAddressRequest> request_; | |
| 49 }; | |
| 50 | |
| 51 IpcHostAddressResolver::IpcHostAddressResolver( | |
| 52 P2PSocketDispatcher* socket_dispatcher) | |
| 53 : socket_dispatcher_(socket_dispatcher) { | |
| 54 } | |
| 55 | |
| 56 IpcHostAddressResolver::~IpcHostAddressResolver() { | |
| 57 } | |
| 58 | |
| 59 HostAddressRequest* IpcHostAddressResolver::CreateRequest() { | |
| 60 return new IpcHostAddressRequest(socket_dispatcher_); | |
| 61 } | |
| 62 | |
| 63 } // namespace remoting | |
| OLD | NEW |