Roll leveldb from r73 to r75.
[chromium-blink-merge.git] / ppapi / proxy / host_resolver_resource.cc
blobf41d751cb206ab2be3808ae5265749c6cec64901
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"
12 namespace ppapi {
13 namespace proxy {
15 namespace {
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;
23 break;
24 case PP_NETADDRESS_FAMILY_IPV4:
25 private_hint.family = PP_NETADDRESSFAMILY_IPV4;
26 break;
27 case PP_NETADDRESS_FAMILY_IPV6:
28 private_hint.family = PP_NETADDRESSFAMILY_IPV6;
29 break;
30 default:
31 NOTREACHED();
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;
41 return private_hint;
44 } // namespace
46 HostResolverResource::HostResolverResource(Connection connection,
47 PP_Instance instance)
48 : HostResolverResourceBase(connection, instance) {
51 HostResolverResource::~HostResolverResource() {
54 thunk::PPB_HostResolver_API* HostResolverResource::AsPPB_HostResolver_API() {
55 return this;
58 int32_t HostResolverResource::Resolve(const char* host,
59 uint16_t port,
60 const PP_HostResolver_Hint_Dev* hint,
61 scoped_refptr<TrackedCallback> callback) {
62 if (!hint)
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() {
75 return GetSizeImpl();
78 PP_Resource HostResolverResource::GetNetAddress(uint32_t index) {
79 scoped_refptr<NetAddressResource> addr_resource = GetNetAddressImpl(index);
80 if (!addr_resource.get())
81 return 0;
83 return addr_resource->GetReference();
86 } // namespace proxy
87 } // namespace ppapi