1 // Copyright 2013 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 "ppapi/proxy/host_resolver_resource.h"
7 #include "base/logging.h"
8 #include "ppapi/c/private/ppb_host_resolver_private.h"
9 #include "ppapi/proxy/net_address_resource.h"
10 #include "ppapi/shared_impl/tracked_callback.h"
17 PP_HostResolver_Private_Hint
ConvertToHostResolverPrivateHint(
18 const PP_HostResolver_Hint
& hint
) {
19 PP_HostResolver_Private_Hint private_hint
;
20 switch (hint
.family
) {
21 case PP_NETADDRESS_FAMILY_UNSPECIFIED
:
22 private_hint
.family
= PP_NETADDRESSFAMILY_PRIVATE_UNSPECIFIED
;
24 case PP_NETADDRESS_FAMILY_IPV4
:
25 private_hint
.family
= PP_NETADDRESSFAMILY_PRIVATE_IPV4
;
27 case PP_NETADDRESS_FAMILY_IPV6
:
28 private_hint
.family
= PP_NETADDRESSFAMILY_PRIVATE_IPV6
;
32 private_hint
.family
= PP_NETADDRESSFAMILY_PRIVATE_UNSPECIFIED
;
35 private_hint
.flags
= 0;
36 if (hint
.flags
& PP_HOSTRESOLVER_FLAG_CANONNAME
)
37 private_hint
.flags
|= PP_HOST_RESOLVER_PRIVATE_FLAGS_CANONNAME
;
44 HostResolverResource::HostResolverResource(Connection connection
,
46 : HostResolverResourceBase(connection
, instance
, false) {
49 HostResolverResource::~HostResolverResource() {
52 thunk::PPB_HostResolver_API
* HostResolverResource::AsPPB_HostResolver_API() {
56 int32_t HostResolverResource::Resolve(const char* host
,
58 const PP_HostResolver_Hint
* hint
,
59 scoped_refptr
<TrackedCallback
> callback
) {
61 return PP_ERROR_BADARGUMENT
;
63 PP_HostResolver_Private_Hint private_hint
=
64 ConvertToHostResolverPrivateHint(*hint
);
65 return ResolveImpl(host
, port
, &private_hint
, callback
);
68 PP_Var
HostResolverResource::GetCanonicalName() {
69 return GetCanonicalNameImpl();
72 uint32_t HostResolverResource::GetNetAddressCount() {
76 PP_Resource
HostResolverResource::GetNetAddress(uint32_t index
) {
77 scoped_refptr
<NetAddressResource
> addr_resource
= GetNetAddressImpl(index
);
78 if (!addr_resource
.get())
81 return addr_resource
->GetReference();