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_Dev
& hint
) {
19 PP_HostResolver_Private_Hint private_hint
;
20 switch (hint
.family
) {
21 case PP_NETADDRESS_FAMILY_UNSPECIFIED
:
22 private_hint
.family
= PP_NETADDRESSFAMILY_UNSPECIFIED
;
24 case PP_NETADDRESS_FAMILY_IPV4
:
25 private_hint
.family
= PP_NETADDRESSFAMILY_IPV4
;
27 case PP_NETADDRESS_FAMILY_IPV6
:
28 private_hint
.family
= PP_NETADDRESSFAMILY_IPV6
;
32 private_hint
.family
= PP_NETADDRESSFAMILY_UNSPECIFIED
;
35 private_hint
.flags
= 0;
36 if (hint
.flags
& PP_HOSTRESOLVER_FLAGS_CANONNAME
)
37 private_hint
.flags
|= PP_HOST_RESOLVER_FLAGS_CANONNAME
;
38 if (hint
.flags
& PP_HOSTRESOLVER_FLAGS_LOOPBACK_ONLY
)
39 private_hint
.flags
|= PP_HOST_RESOLVER_FLAGS_LOOPBACK_ONLY
;
46 HostResolverResource::HostResolverResource(Connection connection
,
48 : HostResolverResourceBase(connection
, instance
) {
51 HostResolverResource::~HostResolverResource() {
54 thunk::PPB_HostResolver_API
* HostResolverResource::AsPPB_HostResolver_API() {
58 int32_t HostResolverResource::Resolve(const char* host
,
60 const PP_HostResolver_Hint_Dev
* hint
,
61 scoped_refptr
<TrackedCallback
> callback
) {
63 return PP_ERROR_BADARGUMENT
;
65 PP_HostResolver_Private_Hint private_hint
=
66 ConvertToHostResolverPrivateHint(*hint
);
67 return ResolveImpl(host
, port
, &private_hint
, callback
);
70 PP_Var
HostResolverResource::GetCanonicalName() {
71 return GetCanonicalNameImpl();
74 uint32_t HostResolverResource::GetNetAddressCount() {
78 PP_Resource
HostResolverResource::GetNetAddress(uint32_t index
) {
79 scoped_refptr
<NetAddressResource
> addr_resource
= GetNetAddressImpl(index
);
80 if (!addr_resource
.get())
83 return addr_resource
->GetReference();