1 // Copyright 2014 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.
5 #include "remoting/client/plugin/pepper_address_resolver.h"
7 #include "base/logging.h"
8 #include "ppapi/cpp/net_address.h"
9 #include "remoting/client/plugin/pepper_util.h"
13 PepperAddressResolver::PepperAddressResolver(const pp::InstanceHandle
& instance
)
14 : resolver_(instance
),
16 callback_factory_(this) {
19 PepperAddressResolver::~PepperAddressResolver() {
22 void PepperAddressResolver::Start(const rtc::SocketAddress
& address
) {
23 DCHECK(!address
.hostname().empty());
25 PP_HostResolver_Hint hint
;
27 hint
.family
= PP_NETADDRESS_FAMILY_UNSPECIFIED
;
28 pp::CompletionCallback callback
=
29 callback_factory_
.NewCallback(&PepperAddressResolver::OnResolved
);
30 int result
= resolver_
.Resolve(
31 address
.hostname().c_str(), address
.port(), hint
, callback
);
32 DCHECK_EQ(result
, PP_OK_COMPLETIONPENDING
);
35 bool PepperAddressResolver::GetResolvedAddress(int family
,
36 rtc::SocketAddress
* addr
) const {
37 rtc::SocketAddress result
;
40 result
= ipv4_address_
;
43 result
= ipv6_address_
;
54 int PepperAddressResolver::GetError() const {
58 void PepperAddressResolver::Destroy(bool wait
) {
62 void PepperAddressResolver::OnResolved(int32_t result
) {
69 int count
= resolver_
.GetNetAddressCount();
70 for (int i
= 0; i
< count
; ++i
) {
71 pp::NetAddress address
= resolver_
.GetNetAddress(i
);
72 if (address
.GetFamily() == PP_NETADDRESS_FAMILY_IPV4
&&
73 ipv4_address_
.IsNil()) {
74 PpNetAddressToSocketAddress(address
, &ipv4_address_
);
75 } else if (address
.GetFamily() == PP_NETADDRESS_FAMILY_IPV6
&&
76 ipv6_address_
.IsNil()) {
77 PpNetAddressToSocketAddress(address
, &ipv6_address_
);
84 } // namespace remoting