Home | History | Annotate | Download | only in dev
      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 #include "ppapi/cpp/dev/var_resource_dev.h"
      6 
      7 #include "ppapi/c/dev/ppb_var_resource_dev.h"
      8 #include "ppapi/cpp/logging.h"
      9 #include "ppapi/cpp/module_impl.h"
     10 
     11 namespace pp {
     12 
     13 namespace {
     14 
     15 template <> const char* interface_name<PPB_VarResource_Dev_0_1>() {
     16   return PPB_VAR_RESOURCE_DEV_INTERFACE_0_1;
     17 }
     18 
     19 }  // namespace
     20 
     21 VarResource_Dev::VarResource_Dev(const pp::Resource& resource) : Var(Null()) {
     22   if (!has_interface<PPB_VarResource_Dev_0_1>()) {
     23     PP_NOTREACHED();
     24     return;
     25   }
     26 
     27   // Note: Var(Null()) sets is_managed_ to true, so |var_| will be properly
     28   // released upon destruction.
     29   var_ = get_interface<PPB_VarResource_Dev_0_1>()->VarFromResource(
     30       resource.pp_resource());
     31 }
     32 
     33 VarResource_Dev::VarResource_Dev(const Var& var) : Var(var) {
     34   if (!var.is_resource()) {
     35     PP_NOTREACHED();
     36 
     37     // This takes care of releasing the reference that this object holds.
     38     Var::operator=(Var(Null()));
     39   }
     40 }
     41 
     42 VarResource_Dev::VarResource_Dev(const VarResource_Dev& other) : Var(other) {}
     43 
     44 VarResource_Dev::~VarResource_Dev() {}
     45 
     46 VarResource_Dev& VarResource_Dev::operator=(const VarResource_Dev& other) {
     47   Var::operator=(other);
     48   return *this;
     49 }
     50 
     51 Var& VarResource_Dev::operator=(const Var& other) {
     52   if (other.is_resource()) {
     53     Var::operator=(other);
     54   } else {
     55     PP_NOTREACHED();
     56     Var::operator=(Var(Null()));
     57   }
     58   return *this;
     59 }
     60 
     61 pp::Resource VarResource_Dev::AsResource() {
     62   if (!has_interface<PPB_VarResource_Dev_0_1>())
     63     return pp::Resource();
     64 
     65   return pp::Resource(
     66       pp::PASS_REF,
     67       get_interface<PPB_VarResource_Dev_0_1>()->VarToResource(var_));
     68 }
     69 
     70 }  // namespace pp
     71