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

Side by Side Diff: ppapi/shared_impl/scoped_pp_var.cc

Issue 400823004: gin (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months 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 | Annotate | Revision Log
« no previous file with comments | « ppapi/shared_impl/scoped_pp_var.h ('k') | ppapi/shared_impl/var.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/shared_impl/scoped_pp_var.h" 5 #include "ppapi/shared_impl/scoped_pp_var.h"
6 6
7 #include "ppapi/c/dev/ppb_memory_dev.h"
7 #include "ppapi/shared_impl/ppapi_globals.h" 8 #include "ppapi/shared_impl/ppapi_globals.h"
8 #include "ppapi/shared_impl/var_tracker.h" 9 #include "ppapi/shared_impl/var_tracker.h"
10 #include "ppapi/thunk/thunk.h"
9 11
10 namespace ppapi { 12 namespace ppapi {
11 13
12 namespace { 14 namespace {
13 15
14 void CallAddRef(const PP_Var& v) { 16 void CallAddRef(const PP_Var& v) {
15 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(v); 17 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(v);
16 } 18 }
17 19
18 void CallRelease(const PP_Var& v) { 20 void CallRelease(const PP_Var& v) {
(...skipping 20 matching lines...) Expand all
39 var_ = v; 41 var_ = v;
40 return *this; 42 return *this;
41 } 43 }
42 44
43 PP_Var ScopedPPVar::Release() { 45 PP_Var ScopedPPVar::Release() {
44 PP_Var result = var_; 46 PP_Var result = var_;
45 var_ = PP_MakeUndefined(); 47 var_ = PP_MakeUndefined();
46 return result; 48 return result;
47 } 49 }
48 50
51 ScopedPPVarArray::ScopedPPVarArray(const PassPPBMemoryAllocatedRef&,
52 PP_Var* array,
53 size_t size)
54 : array_(array),
55 size_(size) {}
56
57 ScopedPPVarArray::ScopedPPVarArray(size_t size)
58 : size_(size) {
59 if (size > 0) {
60 array_ = static_cast<PP_Var*>(
61 thunk::GetPPB_Memory_Dev_0_1_Thunk()->MemAlloc(sizeof(PP_Var) * size));
62 }
63 for (size_t i = 0; i < size_; ++i)
64 array_[i] = PP_MakeUndefined();
65 }
66
67 ScopedPPVarArray::~ScopedPPVarArray() {
68 for (size_t i = 0; i < size_; ++i)
69 CallRelease(array_[i]);
70 if (size_ > 0)
71 thunk::GetPPB_Memory_Dev_0_1_Thunk()->MemFree(array_);
72
73 }
74
75 PP_Var* ScopedPPVarArray::Release(size_t* size) {
76 PP_Var* result = array_;
77 *size = size_;
78 array_ = NULL;
79 size_ = 0;
80 return result;
81 }
82
83 void ScopedPPVarArray::Set(size_t index, PP_Var var) {
84 DCHECK(index < size_);
85 CallRelease(array_[index]);
86 array_[index] = var;
87 }
88
49 } // namespace ppapi 89 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/scoped_pp_var.h ('k') | ppapi/shared_impl/var.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698