Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / ppapi / cpp / var_array_buffer.cc
blob0bc8ea57ad779c8d51f2d44d63e80d9ec27aef02
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
3 // found in the LICENSE file.
5 #include "ppapi/cpp/var_array_buffer.h"
7 #include <limits>
9 #include "ppapi/c/ppb_var_array_buffer.h"
10 #include "ppapi/cpp/logging.h"
11 #include "ppapi/cpp/module_impl.h"
13 namespace pp {
15 namespace {
17 template <> const char* interface_name<PPB_VarArrayBuffer_1_0>() {
18 return PPB_VAR_ARRAY_BUFFER_INTERFACE_1_0;
21 } // namespace
23 VarArrayBuffer::VarArrayBuffer() {
24 ConstructWithSize(0);
27 VarArrayBuffer::VarArrayBuffer(const Var& var) : Var(var) {
28 if (!var.is_array_buffer()) {
29 PP_NOTREACHED();
30 var_ = PP_MakeNull();
34 VarArrayBuffer::VarArrayBuffer(uint32_t size_in_bytes) {
35 ConstructWithSize(size_in_bytes);
38 pp::VarArrayBuffer& VarArrayBuffer::operator=(const VarArrayBuffer& other) {
39 Var::operator=(other);
40 return *this;
43 pp::Var& VarArrayBuffer::operator=(const Var& other) {
44 if (other.is_array_buffer()) {
45 return Var::operator=(other);
46 } else {
47 PP_NOTREACHED();
48 return *this;
52 uint32_t VarArrayBuffer::ByteLength() const {
53 uint32_t byte_length = std::numeric_limits<uint32_t>::max();
54 if (is_array_buffer() && has_interface<PPB_VarArrayBuffer_1_0>())
55 get_interface<PPB_VarArrayBuffer_1_0>()->ByteLength(var_, &byte_length);
56 else
57 PP_NOTREACHED();
58 return byte_length;
61 void* VarArrayBuffer::Map() {
62 if (is_array_buffer() && has_interface<PPB_VarArrayBuffer_1_0>())
63 return get_interface<PPB_VarArrayBuffer_1_0>()->Map(var_);
64 PP_NOTREACHED();
65 return NULL;
68 void VarArrayBuffer::Unmap() {
69 if (is_array_buffer() && has_interface<PPB_VarArrayBuffer_1_0>())
70 get_interface<PPB_VarArrayBuffer_1_0>()->Unmap(var_);
71 else
72 PP_NOTREACHED();
76 void VarArrayBuffer::ConstructWithSize(uint32_t size_in_bytes) {
77 PP_DCHECK(is_undefined());
79 if (has_interface<PPB_VarArrayBuffer_1_0>()) {
80 var_ = get_interface<PPB_VarArrayBuffer_1_0>()->Create(size_in_bytes);
81 } else {
82 PP_NOTREACHED();
83 var_ = PP_MakeNull();
85 is_managed_ = true;
88 } // namespace pp