Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 // TODO(mgiuca): Think about reference counting. | |
| 28 var_ = get_interface<PPB_VarResource_Dev_0_1>()->VarFromResource( | |
| 29 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.
| |
| 30 } | |
| 31 | |
| 32 VarResource_Dev::VarResource_Dev(const Var& var) : Var(var) { | |
| 33 if (!var.is_resource()) { | |
| 34 PP_NOTREACHED(); | |
| 35 | |
| 36 // This takes care of releasing the reference that this object holds. | |
| 37 Var::operator=(Var(Null())); | |
| 38 } | |
| 39 } | |
| 40 | |
| 41 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.
| |
| 42 if (var.type != PP_VARTYPE_RESOURCE) { | |
| 43 PP_NOTREACHED(); | |
| 44 | |
| 45 // This takes care of releasing the reference that this object holds. | |
| 46 Var::operator=(Var(Null())); | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 VarResource_Dev::VarResource_Dev(const VarResource_Dev& other) : Var(other) {} | |
| 51 | |
| 52 VarResource_Dev::~VarResource_Dev() {} | |
| 53 | |
| 54 VarResource_Dev& VarResource_Dev::operator=(const VarResource_Dev& other) { | |
| 55 Var::operator=(other); | |
| 56 return *this; | |
| 57 } | |
| 58 | |
| 59 Var& VarResource_Dev::operator=(const Var& other) { | |
| 60 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.
| |
| 61 Var::operator=(other); | |
| 62 } else { | |
| 63 PP_NOTREACHED(); | |
| 64 Var::operator=(Var(Null())); | |
| 65 } | |
| 66 return *this; | |
| 67 } | |
| 68 | |
| 69 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
| |
| 70 if (!has_interface<PPB_VarResource_Dev_0_1>()) | |
| 71 return pp::Resource(); | |
| 72 | |
| 73 // TODO(mgiuca): Think about reference counting. | |
| 74 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.
| |
| 75 get_interface<PPB_VarResource_Dev_0_1>()->VarToResource(var_)); | |
| 76 } | |
| 77 | |
| 78 } // namespace pp | |
| OLD | NEW |