Chromium Code Reviews| Index: ppapi/cpp/dev/var_resource_dev.cc |
| diff --git a/ppapi/cpp/dev/var_resource_dev.cc b/ppapi/cpp/dev/var_resource_dev.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..09d2098e35fd99dec09072e1555559359aa8d65e |
| --- /dev/null |
| +++ b/ppapi/cpp/dev/var_resource_dev.cc |
| @@ -0,0 +1,78 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ppapi/cpp/dev/var_resource_dev.h" |
| + |
| +#include "ppapi/c/dev/ppb_var_resource_dev.h" |
| +#include "ppapi/cpp/logging.h" |
| +#include "ppapi/cpp/module_impl.h" |
| + |
| +namespace pp { |
| + |
| +namespace { |
| + |
| +template <> const char* interface_name<PPB_VarResource_Dev_0_1>() { |
| + return PPB_VAR_RESOURCE_DEV_INTERFACE_0_1; |
| +} |
| + |
| +} // namespace |
| + |
| +VarResource_Dev::VarResource_Dev(const pp::Resource& resource) : Var(Null()) { |
| + if (!has_interface<PPB_VarResource_Dev_0_1>()) { |
| + PP_NOTREACHED(); |
| + return; |
| + } |
| + |
| + // TODO(mgiuca): Think about reference counting. |
| + var_ = get_interface<PPB_VarResource_Dev_0_1>()->VarFromResource( |
| + resource.pp_resource()); |
|
dmichael (off chromium)
2013/10/30 18:03:10
This should be fine, but you also have to set "is_
yzshen1
2013/10/30 18:10:35
Var(Null) constructor sets |is_managed_| to true,
Matt Giuca
2013/10/31 06:33:46
Correct. So this code should be fine as it is.
|
| +} |
| + |
| +VarResource_Dev::VarResource_Dev(const Var& var) : Var(var) { |
| + if (!var.is_resource()) { |
| + PP_NOTREACHED(); |
| + |
| + // This takes care of releasing the reference that this object holds. |
| + Var::operator=(Var(Null())); |
| + } |
| +} |
| + |
| +VarResource_Dev::VarResource_Dev(const PP_Var& var) : Var(var) { |
|
dmichael (off chromium)
2013/10/30 18:03:10
Are you using this for anything? If you can avoid
Matt Giuca
2013/10/31 06:33:46
Done.
|
| + if (var.type != PP_VARTYPE_RESOURCE) { |
| + PP_NOTREACHED(); |
| + |
| + // This takes care of releasing the reference that this object holds. |
| + Var::operator=(Var(Null())); |
| + } |
| +} |
| + |
| +VarResource_Dev::VarResource_Dev(const VarResource_Dev& other) : Var(other) {} |
| + |
| +VarResource_Dev::~VarResource_Dev() {} |
| + |
| +VarResource_Dev& VarResource_Dev::operator=(const VarResource_Dev& other) { |
| + Var::operator=(other); |
| + return *this; |
| +} |
| + |
| +Var& VarResource_Dev::operator=(const Var& other) { |
| + if (other.is_array()) { |
|
yzshen1
2013/10/30 16:50:01
resource :)
Matt Giuca
2013/10/30 21:54:41
Oops, as you can see, I made this in a hurry and d
Matt Giuca
2013/10/31 06:33:46
Done.
|
| + Var::operator=(other); |
| + } else { |
| + PP_NOTREACHED(); |
| + Var::operator=(Var(Null())); |
| + } |
| + return *this; |
| +} |
| + |
| +pp::Resource VarResource_Dev::ToResource() { |
|
yzshen1
2013/10/30 16:50:01
Maybe we could also consider something like:
temp
Matt Giuca
2013/10/30 21:54:41
I'll have to think about this. What would the usag
Matt Giuca
2013/10/31 06:33:46
As discussed, saving for another CL, if at all. Le
|
| + if (!has_interface<PPB_VarResource_Dev_0_1>()) |
| + return pp::Resource(); |
| + |
| + // TODO(mgiuca): Think about reference counting. |
| + return pp::Resource( |
|
yzshen1
2013/10/30 16:50:01
I think you need to use Resource(PassRef, PP_Resou
dmichael (off chromium)
2013/10/30 18:03:10
+1
Matt Giuca
2013/10/31 06:33:46
Done.
|
| + get_interface<PPB_VarResource_Dev_0_1>()->VarToResource(var_)); |
| +} |
| + |
| +} // namespace pp |