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

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: update the documentation 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..e4372413fc4c95920f67c078d5ee7008a4514df8 100644
--- a/ppapi/cpp/dev/var_array_buffer_dev.cc
+++ b/ppapi/cpp/dev/var_array_buffer_dev.cc
@@ -4,6 +4,8 @@
#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,22 +20,17 @@ 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();
@@ -41,27 +38,26 @@ VarArrayBuffer_Dev::VarArrayBuffer_Dev(uint32_t size_in_bytes)
}
uint32_t VarArrayBuffer_Dev::ByteLength() const {
- if (has_interface<PPB_VarArrayBuffer_Dev>()) {
- return get_interface<PPB_VarArrayBuffer_Dev>()->ByteLength(var_);
- }
- PP_NOTREACHED();
- return 0;
-}
-
-const void* VarArrayBuffer_Dev::Map() const {
- return const_cast<VarArrayBuffer_Dev*>(this)->Map();
+ 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/25 22:19:07 Shouldn't this call UnMap?
dmichael (off chromium) 2012/01/25 23:50:11 Unmap is only an optimization for apps that want t
+ else
+ PP_NOTREACHED();
}
} // namespace pp

Powered by Google App Engine
This is Rietveld 408576698