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