Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: ppapi/cpp/dev/var_resource_dev.cc

Issue 52233002: [PPAPI] Added VarResource_Dev class. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix Windows compile. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ppapi/cpp/dev/var_resource_dev.h ('k') | ppapi/cpp/file_system.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // 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
OLDNEW
« no previous file with comments | « ppapi/cpp/dev/var_resource_dev.h ('k') | ppapi/cpp/file_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698