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

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

Issue 8930010: Implement in-process PPB_VarArrayBuffer_Dev. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Some pre-review cleanup. Created 9 years 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/ppb_var_shared.h" 5 #include "ppapi/shared_impl/ppb_var_shared.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "ppapi/c/dev/ppb_var_array_buffer_dev.h"
9 #include "ppapi/c/ppb_var.h" 10 #include "ppapi/c/ppb_var.h"
10 #include "ppapi/c/pp_var.h" 11 #include "ppapi/c/pp_var.h"
11 #include "ppapi/shared_impl/ppapi_globals.h" 12 #include "ppapi/shared_impl/ppapi_globals.h"
12 #include "ppapi/shared_impl/proxy_lock.h" 13 #include "ppapi/shared_impl/proxy_lock.h"
13 #include "ppapi/shared_impl/var.h" 14 #include "ppapi/shared_impl/var.h"
14 #include "ppapi/shared_impl/var_tracker.h" 15 #include "ppapi/shared_impl/var_tracker.h"
15 16
16 using ppapi::PpapiGlobals; 17 using ppapi::PpapiGlobals;
17 using ppapi::StringVar; 18 using ppapi::StringVar;
18 19
19 namespace ppapi { 20 namespace ppapi {
21 namespace {
20 22
23 // PPB_Var methods -------------------------------------------------------------
brettw 2011/12/15 00:19:51 I'd normally put blank lines on both sides of this
21 void AddRefVar(PP_Var var) { 24 void AddRefVar(PP_Var var) {
22 ppapi::ProxyAutoLock lock; 25 ppapi::ProxyAutoLock lock;
23 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var); 26 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var);
24 } 27 }
25 28
26 void ReleaseVar(PP_Var var) { 29 void ReleaseVar(PP_Var var) {
27 ppapi::ProxyAutoLock lock; 30 ppapi::ProxyAutoLock lock;
28 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var); 31 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var);
29 } 32 }
30 33
(...skipping 10 matching lines...) Expand all
41 ppapi::ProxyAutoLock lock; 44 ppapi::ProxyAutoLock lock;
42 StringVar* str = StringVar::FromPPVar(var); 45 StringVar* str = StringVar::FromPPVar(var);
43 if (str) { 46 if (str) {
44 *len = static_cast<uint32_t>(str->value().size()); 47 *len = static_cast<uint32_t>(str->value().size());
45 return str->value().c_str(); 48 return str->value().c_str();
46 } 49 }
47 *len = 0; 50 *len = 0;
48 return NULL; 51 return NULL;
49 } 52 }
50 53
51 namespace {
52 const PPB_Var var_interface = { 54 const PPB_Var var_interface = {
53 &AddRefVar, 55 &AddRefVar,
54 &ReleaseVar, 56 &ReleaseVar,
55 &VarFromUtf8, 57 &VarFromUtf8,
56 &VarToUtf8 58 &VarToUtf8
57 }; 59 };
58 60
59 const PPB_Var_1_0 var_interface1_0 = { 61 const PPB_Var_1_0 var_interface1_0 = {
60 &AddRefVar, 62 &AddRefVar,
61 &ReleaseVar, 63 &ReleaseVar,
62 &VarFromUtf8_1_0, 64 &VarFromUtf8_1_0,
63 &VarToUtf8 65 &VarToUtf8
64 }; 66 };
67
68 // PPB_VarArrayBuffer_Dev methods ----------------------------------------------
69 PP_Var CreateArrayBufferVar(uint32_t size_in_bytes) {
70 return PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(
brettw 2011/12/15 00:19:51 Need extra space in most of these functions.
71 size_in_bytes);
72 }
73
74 uint32_t ByteLength(struct PP_Var array) {
75 ArrayBufferVar* buffer = ArrayBufferVar::FromPPVar(array);
76 if (!buffer)
77 return 0;
78 return buffer->ByteLength();
79 }
80
81 void* Map(struct PP_Var array) {
82 ArrayBufferVar* buffer = ArrayBufferVar::FromPPVar(array);
83 if (!buffer)
84 return NULL;
85 return buffer->Map();
86 }
87
88 const PPB_VarArrayBuffer_Dev var_arraybuffer_interface = {
89 &CreateArrayBufferVar,
90 &ByteLength,
91 &Map
92 };
93
65 } // namespace 94 } // namespace
66 95
67 // static 96 // static
68 const PPB_Var* PPB_Var_Shared::GetVarInterface() { 97 const PPB_Var* PPB_Var_Shared::GetVarInterface() {
69 return &var_interface; 98 return &var_interface;
70 } 99 }
71 100
72 // static 101 // static
73 const PPB_Var_1_0* PPB_Var_Shared::GetVarInterface1_0() { 102 const PPB_Var_1_0* PPB_Var_Shared::GetVarInterface1_0() {
74 return &var_interface1_0; 103 return &var_interface1_0;
75 } 104 }
76 105
106 // static
107 const PPB_VarArrayBuffer_Dev* PPB_Var_Shared::GetVarArrayBufferInterface() {
108 return &var_arraybuffer_interface;
109 }
110
77 } // namespace ppapi 111 } // namespace ppapi
78 112
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698