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

Unified 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: Clarify ByteLength behavior when not mapped. 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/cpp/dev/var_array_buffer_dev.cc
diff --git a/ppapi/cpp/dev/var_array_buffer_dev.cc b/ppapi/cpp/dev/var_array_buffer_dev.cc
index 61f697efa2150ff29bc267264eeb48db51eb8d53..9be106f73f1894eeba19f6e09498c3879fd045b1 100644
--- a/ppapi/cpp/dev/var_array_buffer_dev.cc
+++ b/ppapi/cpp/dev/var_array_buffer_dev.cc
@@ -1,9 +1,11 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ppapi/cpp/dev/var_array_buffer_dev.h"
+#include <limits>
+
#include "ppapi/c/dev/ppb_var_array_buffer_dev.h"
#include "ppapi/cpp/logging.h"
#include "ppapi/cpp/module_impl.h"
@@ -18,50 +20,50 @@ template <> const char* interface_name<PPB_VarArrayBuffer_Dev>() {
} // namespace
-VarArrayBuffer_Dev::VarArrayBuffer_Dev(const Var& var)
- : Var(var), buffer_(NULL) {
- if (var.is_array_buffer()) {
- buffer_ = Map();
- } else {
+VarArrayBuffer_Dev::VarArrayBuffer_Dev(const Var& var) : Var(var) {
+ if (!var.is_array_buffer()) {
PP_NOTREACHED();
var_ = PP_MakeNull();
}
}
-VarArrayBuffer_Dev::VarArrayBuffer_Dev(uint32_t size_in_bytes)
- : buffer_(NULL) {
+VarArrayBuffer_Dev::VarArrayBuffer_Dev(uint32_t size_in_bytes) {
if (has_interface<PPB_VarArrayBuffer_Dev>()) {
var_ = get_interface<PPB_VarArrayBuffer_Dev>()->Create(size_in_bytes);
needs_release_ = true;
- buffer_ = Map();
} else {
PP_NOTREACHED();
var_ = PP_MakeNull();
}
}
-uint32_t VarArrayBuffer_Dev::ByteLength() const {
- if (has_interface<PPB_VarArrayBuffer_Dev>()) {
- return get_interface<PPB_VarArrayBuffer_Dev>()->ByteLength(var_);
- }
- PP_NOTREACHED();
- return 0;
+pp::VarArrayBuffer_Dev& VarArrayBuffer_Dev::operator=(
+ const VarArrayBuffer_Dev& other) {
+ Var::operator=(other);
bbudge 2012/01/26 17:20:26 Isn't it a problem that you can assign a non-Array
dmichael (off chromium) 2012/01/26 18:33:48 Good point; I was only really thinking about stati
+ return *this;
}
-const void* VarArrayBuffer_Dev::Map() const {
- return const_cast<VarArrayBuffer_Dev*>(this)->Map();
+uint32_t VarArrayBuffer_Dev::ByteLength() const {
+ uint32_t byte_length = std::numeric_limits<uint32_t>::max();
+ if (is_array_buffer() && has_interface<PPB_VarArrayBuffer_Dev>())
+ get_interface<PPB_VarArrayBuffer_Dev>()->ByteLength(var_, &byte_length);
+ else
+ PP_NOTREACHED();
+ return byte_length;
}
void* VarArrayBuffer_Dev::Map() {
- // TODO(dmichael): This is not thread-safe.
- if (buffer_)
- return buffer_;
- if (has_interface<PPB_VarArrayBuffer_Dev>()) {
- buffer_ = get_interface<PPB_VarArrayBuffer_Dev>()->Map(var_);
- return buffer_;
- }
+ if (is_array_buffer() && has_interface<PPB_VarArrayBuffer_Dev>())
+ return get_interface<PPB_VarArrayBuffer_Dev>()->Map(var_);
PP_NOTREACHED();
- return 0;
+ return NULL;
+}
+
+void VarArrayBuffer_Dev::Unmap() {
+ if (is_array_buffer() && has_interface<PPB_VarArrayBuffer_Dev>())
+ get_interface<PPB_VarArrayBuffer_Dev>()->Map(var_);
bbudge 2012/01/26 17:20:26 Reading the code, it still seems weird to see Unma
dmichael (off chromium) 2012/01/26 18:33:48 Gah. You were completely right the first time. I r
+ else
+ PP_NOTREACHED();
}
} // namespace pp

Powered by Google App Engine
This is Rietveld 408576698