Home | History | Annotate | Download | only in thunk
      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.
      4 
      5 // From ppb_host_resolver.idl modified Thu Jun 20 15:36:07 2013.
      6 
      7 #include "ppapi/c/pp_completion_callback.h"
      8 #include "ppapi/c/pp_errors.h"
      9 #include "ppapi/c/ppb_host_resolver.h"
     10 #include "ppapi/shared_impl/tracked_callback.h"
     11 #include "ppapi/thunk/enter.h"
     12 #include "ppapi/thunk/ppb_host_resolver_api.h"
     13 #include "ppapi/thunk/ppb_instance_api.h"
     14 #include "ppapi/thunk/resource_creation_api.h"
     15 #include "ppapi/thunk/thunk.h"
     16 
     17 namespace ppapi {
     18 namespace thunk {
     19 
     20 namespace {
     21 
     22 PP_Resource Create(PP_Instance instance) {
     23   VLOG(4) << "PPB_HostResolver::Create()";
     24   EnterResourceCreation enter(instance);
     25   if (enter.failed())
     26     return 0;
     27   return enter.functions()->CreateHostResolver(instance);
     28 }
     29 
     30 PP_Bool IsHostResolver(PP_Resource resource) {
     31   VLOG(4) << "PPB_HostResolver::IsHostResolver()";
     32   EnterResource<PPB_HostResolver_API> enter(resource, false);
     33   return PP_FromBool(enter.succeeded());
     34 }
     35 
     36 int32_t Resolve(PP_Resource host_resolver,
     37                 const char* host,
     38                 uint16_t port,
     39                 const struct PP_HostResolver_Hint* hint,
     40                 struct PP_CompletionCallback callback) {
     41   VLOG(4) << "PPB_HostResolver::Resolve()";
     42   EnterResource<PPB_HostResolver_API> enter(host_resolver, callback, true);
     43   if (enter.failed())
     44     return enter.retval();
     45   return enter.SetResult(enter.object()->Resolve(host,
     46                                                  port,
     47                                                  hint,
     48                                                  enter.callback()));
     49 }
     50 
     51 struct PP_Var GetCanonicalName(PP_Resource host_resolver) {
     52   VLOG(4) << "PPB_HostResolver::GetCanonicalName()";
     53   EnterResource<PPB_HostResolver_API> enter(host_resolver, true);
     54   if (enter.failed())
     55     return PP_MakeUndefined();
     56   return enter.object()->GetCanonicalName();
     57 }
     58 
     59 uint32_t GetNetAddressCount(PP_Resource host_resolver) {
     60   VLOG(4) << "PPB_HostResolver::GetNetAddressCount()";
     61   EnterResource<PPB_HostResolver_API> enter(host_resolver, true);
     62   if (enter.failed())
     63     return 0;
     64   return enter.object()->GetNetAddressCount();
     65 }
     66 
     67 PP_Resource GetNetAddress(PP_Resource host_resolver, uint32_t index) {
     68   VLOG(4) << "PPB_HostResolver::GetNetAddress()";
     69   EnterResource<PPB_HostResolver_API> enter(host_resolver, true);
     70   if (enter.failed())
     71     return 0;
     72   return enter.object()->GetNetAddress(index);
     73 }
     74 
     75 const PPB_HostResolver_1_0 g_ppb_hostresolver_thunk_1_0 = {
     76   &Create,
     77   &IsHostResolver,
     78   &Resolve,
     79   &GetCanonicalName,
     80   &GetNetAddressCount,
     81   &GetNetAddress
     82 };
     83 
     84 }  // namespace
     85 
     86 const PPB_HostResolver_1_0* GetPPB_HostResolver_1_0_Thunk() {
     87   return &g_ppb_hostresolver_thunk_1_0;
     88 }
     89 
     90 }  // namespace thunk
     91 }  // namespace ppapi
     92