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

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

Issue 9169052: Tweaks to PPB_VarArrayBuffer in preperation for taking out of Dev. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes based on reviews Created 8 years, 11 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/cpp/dev/var_array_buffer_dev.h ('k') | ppapi/cpp/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) 2011 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/cpp/dev/var_array_buffer_dev.h" 5 #include "ppapi/cpp/dev/var_array_buffer_dev.h"
6 6
7 #include <limits>
8
7 #include "ppapi/c/dev/ppb_var_array_buffer_dev.h" 9 #include "ppapi/c/dev/ppb_var_array_buffer_dev.h"
8 #include "ppapi/cpp/logging.h" 10 #include "ppapi/cpp/logging.h"
9 #include "ppapi/cpp/module_impl.h" 11 #include "ppapi/cpp/module_impl.h"
10 12
11 namespace pp { 13 namespace pp {
12 14
13 namespace { 15 namespace {
14 16
15 template <> const char* interface_name<PPB_VarArrayBuffer_Dev>() { 17 template <> const char* interface_name<PPB_VarArrayBuffer_Dev>() {
16 return PPB_VAR_ARRAY_BUFFER_DEV_INTERFACE; 18 return PPB_VAR_ARRAY_BUFFER_DEV_INTERFACE;
17 } 19 }
18 20
19 } // namespace 21 } // namespace
20 22
21 VarArrayBuffer_Dev::VarArrayBuffer_Dev(const Var& var) 23 VarArrayBuffer_Dev::VarArrayBuffer_Dev(const Var& var) : Var(var) {
22 : Var(var), buffer_(NULL) { 24 if (!var.is_array_buffer()) {
23 if (var.is_array_buffer()) { 25 PP_NOTREACHED();
24 buffer_ = Map(); 26 var_ = PP_MakeNull();
27 }
28 }
29
30 VarArrayBuffer_Dev::VarArrayBuffer_Dev(uint32_t size_in_bytes) {
31 if (has_interface<PPB_VarArrayBuffer_Dev>()) {
32 var_ = get_interface<PPB_VarArrayBuffer_Dev>()->Create(size_in_bytes);
33 needs_release_ = true;
25 } else { 34 } else {
26 PP_NOTREACHED(); 35 PP_NOTREACHED();
27 var_ = PP_MakeNull(); 36 var_ = PP_MakeNull();
28 } 37 }
29 } 38 }
30 39
31 VarArrayBuffer_Dev::VarArrayBuffer_Dev(uint32_t size_in_bytes) 40 pp::VarArrayBuffer_Dev& VarArrayBuffer_Dev::operator=(
32 : buffer_(NULL) { 41 const VarArrayBuffer_Dev& other) {
33 if (has_interface<PPB_VarArrayBuffer_Dev>()) { 42 Var::operator=(other);
34 var_ = get_interface<PPB_VarArrayBuffer_Dev>()->Create(size_in_bytes); 43 return *this;
35 needs_release_ = true; 44 }
36 buffer_ = Map(); 45
46 pp::Var& VarArrayBuffer_Dev::operator=(const Var& other) {
47 if (other.is_array_buffer()) {
48 return Var::operator=(other);
37 } else { 49 } else {
38 PP_NOTREACHED(); 50 PP_NOTREACHED();
39 var_ = PP_MakeNull(); 51 return *this;
40 } 52 }
41 } 53 }
42 54
43 uint32_t VarArrayBuffer_Dev::ByteLength() const { 55 uint32_t VarArrayBuffer_Dev::ByteLength() const {
44 if (has_interface<PPB_VarArrayBuffer_Dev>()) { 56 uint32_t byte_length = std::numeric_limits<uint32_t>::max();
45 return get_interface<PPB_VarArrayBuffer_Dev>()->ByteLength(var_); 57 if (is_array_buffer() && has_interface<PPB_VarArrayBuffer_Dev>())
46 } 58 get_interface<PPB_VarArrayBuffer_Dev>()->ByteLength(var_, &byte_length);
47 PP_NOTREACHED(); 59 else
48 return 0; 60 PP_NOTREACHED();
49 } 61 return byte_length;
50
51 const void* VarArrayBuffer_Dev::Map() const {
52 return const_cast<VarArrayBuffer_Dev*>(this)->Map();
53 } 62 }
54 63
55 void* VarArrayBuffer_Dev::Map() { 64 void* VarArrayBuffer_Dev::Map() {
56 // TODO(dmichael): This is not thread-safe. 65 if (is_array_buffer() && has_interface<PPB_VarArrayBuffer_Dev>())
57 if (buffer_) 66 return get_interface<PPB_VarArrayBuffer_Dev>()->Map(var_);
58 return buffer_;
59 if (has_interface<PPB_VarArrayBuffer_Dev>()) {
60 buffer_ = get_interface<PPB_VarArrayBuffer_Dev>()->Map(var_);
61 return buffer_;
62 }
63 PP_NOTREACHED(); 67 PP_NOTREACHED();
64 return 0; 68 return NULL;
69 }
70
71 void VarArrayBuffer_Dev::Unmap() {
72 if (is_array_buffer() && has_interface<PPB_VarArrayBuffer_Dev>())
73 get_interface<PPB_VarArrayBuffer_Dev>()->Unmap(var_);
74 else
75 PP_NOTREACHED();
65 } 76 }
66 77
67 } // namespace pp 78 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/cpp/dev/var_array_buffer_dev.h ('k') | ppapi/cpp/var.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698