prune resources in MemoryCache
[chromium-blink-merge.git] / ppapi / proxy / host_resolver_resource.cc
bloba2898566f7f9527579cc7408c46f98df2202b070
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& 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;
23 break;
24 case PP_NETADDRESS_FAMILY_IPV4:
25 private_hint.family = PP_NETADDRESSFAMILY_PRIVATE_IPV4;
26 break;
27 case PP_NETADDRESS_FAMILY_IPV6:
28 private_hint.family = PP_NETADDRESSFAMILY_PRIVATE_IPV6;
29 break;
30 default:
31 NOTREACHED();
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;
39 return private_hint;
42 } // namespace
44 HostResolverResource::HostResolverResource(Connection connection,
45 PP_Instance instance)
46 : HostResolverResourceBase(connection, instance, false) {
49 HostResolverResource::~HostResolverResource() {
52 thunk::PPB_HostResolver_API* HostResolverResource::AsPPB_HostResolver_API() {
53 return this;
56 int32_t HostResolverResource::Resolve(const char* host,
57 uint16_t port,
58 const PP_HostResolver_Hint* hint,
59 scoped_refptr<TrackedCallback> callback) {
60 if (!hint)
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() {
73 return GetSizeImpl();
76 PP_Resource HostResolverResource::GetNetAddress(uint32_t index) {
77 scoped_refptr<NetAddressResource> addr_resource = GetNetAddressImpl(index);
78 if (!addr_resource.get())
79 return 0;
81 return addr_resource->GetReference();
84 } // namespace proxy
85 } // namespace ppapi