summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authordmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-26 21:04:10 +0000
committerdmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-26 21:04:10 +0000
commit47ef6148e87b5410135e35afe4259344a2a458e4 (patch)
treed2361e6c4d07e361aacc0bd3dc3e1195779c9457 /ppapi
parentb6a415ea6e0ad4751d1a9dca9f99bde727033167 (diff)
downloadchromium_src-47ef6148e87b5410135e35afe4259344a2a458e4.zip
chromium_src-47ef6148e87b5410135e35afe4259344a2a458e4.tar.gz
chromium_src-47ef6148e87b5410135e35afe4259344a2a458e4.tar.bz2
Tweaks to PPB_VarArrayBuffer in preperation for taking out of Dev.
* Add Unmap. * Make ByteLength more consistent with the rest of PPAPI. * Make C++ wrapper not cache the buffer. BUG= TEST= Review URL: http://codereview.chromium.org/9169052 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119286 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/api/dev/ppb_var_array_buffer_dev.idl55
-rw-r--r--ppapi/c/dev/ppb_var_array_buffer_dev.h60
-rw-r--r--ppapi/cpp/dev/var_array_buffer_dev.cc59
-rw-r--r--ppapi/cpp/dev/var_array_buffer_dev.h54
-rw-r--r--ppapi/cpp/var.h4
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/object_serialize.cc8
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_var.cc26
-rw-r--r--ppapi/proxy/plugin_array_buffer_var.cc6
-rw-r--r--ppapi/proxy/plugin_array_buffer_var.h3
-rw-r--r--ppapi/shared_impl/ppb_var_shared.cc16
-rw-r--r--ppapi/shared_impl/var.h3
-rw-r--r--ppapi/tests/test_post_message.cc5
-rw-r--r--ppapi/tests/test_websocket.cc4
13 files changed, 224 insertions, 79 deletions
diff --git a/ppapi/api/dev/ppb_var_array_buffer_dev.idl b/ppapi/api/dev/ppb_var_array_buffer_dev.idl
index 909ad71..2d3116b 100644
--- a/ppapi/api/dev/ppb_var_array_buffer_dev.idl
+++ b/ppapi/api/dev/ppb_var_array_buffer_dev.idl
@@ -8,7 +8,7 @@
*/
label Chrome {
- M17 = 0.1
+ M18 = 0.2
};
/**
@@ -23,25 +23,62 @@ interface PPB_VarArrayBuffer_Dev {
/**
* Create a zero-initialized VarArrayBuffer.
*
- * @param[in] size_in_bytes The size of the array buffer that will be created.
+ * @param[in] size_in_bytes The size of the ArrayBuffer that will be created.
*
- * @return A PP_Var which represents an VarArrayBuffer of the requested size
+ * @return A PP_Var which represents a VarArrayBuffer of the requested size
* with a reference count of 1.
*/
PP_Var Create([in] uint32_t size_in_bytes);
+
/**
- * Returns the length of the VarArrayBuffer in bytes.
+ * Retrieves the length of the VarArrayBuffer in bytes. On success,
+ * byte_length is set to the length of the given ArrayBuffer var. On failure,
+ * byte_length is unchanged (this could happen, for instance, if the given
+ * PP_Var is not of type PP_VARTYPE_ARRAY_BUFFER). Note that ByteLength() will
+ * successfully retrieve the the size of an ArrayBuffer even if the
+ * ArrayBuffer is not currently mapped.
+ *
+ * @param[in] array The ArrayBuffer whose length should be returned.
+ *
+ * @param[out] byte_length A variable which is set to the length of the given
+ * ArrayBuffer on success.
*
- * @return The length of the VarArrayBuffer in bytes.
+ * @return PP_TRUE on success, PP_FALSE on failure.
*/
- uint32_t ByteLength([in] PP_Var array);
+ PP_Bool ByteLength([in] PP_Var array, [out] uint32_t byte_length);
+
/**
- * Returns a pointer to the beginning of the buffer for the given array.
+ * Maps the ArrayBuffer in to the module's address space and returns a pointer
+ * to the beginning of the buffer for the given ArrayBuffer PP_Var. Note that
+ * calling Map() can be a relatively expensive operation. Use care when
+ * calling it in performance-critical code. For example, you should call it
+ * only once when looping over an ArrayBuffer:
+ *
+ * <code>
+ * char* data = (char*)(array_buffer_if.Map(array_buffer_var));
+ * uint32_t byte_length = 0;
+ * PP_Bool ok = array_buffer_if.ByteLength(array_buffer_var, &byte_length);
+ * if (!ok)
+ * return DoSomethingBecauseMyVarIsNotAnArrayBuffer();
+ * for (uint32_t i = 0; i < byte_length; ++i)
+ * data[i] = 'A';
+ * </code>
*
- * @param[in] array The array whose buffer should be returned.
+ * @param[in] array The ArrayBuffer whose internal buffer should be returned.
*
- * @return A pointer to the buffer for this array.
+ * @return A pointer to the internal buffer for this ArrayBuffer. Returns NULL
+ * if the given PP_Var is not of type PP_VARTYPE_ARRAY_BUFFER.
*/
mem_t Map([in] PP_Var array);
+
+ /**
+ * Unmaps the given ArrayBuffer var from the module address space. Use this if
+ * you want to save memory but might want to Map the buffer again later. The
+ * PP_Var remains valid and should still be released using PPB_Var when you
+ * are done with the ArrayBuffer.
+ *
+ * @param[in] array The ArrayBuffer which should be released.
+ */
+ void Unmap([in] PP_Var array);
};
diff --git a/ppapi/c/dev/ppb_var_array_buffer_dev.h b/ppapi/c/dev/ppb_var_array_buffer_dev.h
index e4daf90..272c8e2 100644
--- a/ppapi/c/dev/ppb_var_array_buffer_dev.h
+++ b/ppapi/c/dev/ppb_var_array_buffer_dev.h
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-/* From dev/ppb_var_array_buffer_dev.idl modified Wed Dec 14 18:08:00 2011. */
+/* From dev/ppb_var_array_buffer_dev.idl modified Thu Jan 26 11:25:54 2012. */
#ifndef PPAPI_C_DEV_PPB_VAR_ARRAY_BUFFER_DEV_H_
#define PPAPI_C_DEV_PPB_VAR_ARRAY_BUFFER_DEV_H_
@@ -13,9 +13,9 @@
#include "ppapi/c/pp_stdint.h"
#include "ppapi/c/pp_var.h"
-#define PPB_VAR_ARRAY_BUFFER_DEV_INTERFACE_0_1 "PPB_VarArrayBuffer(Dev);0.1"
+#define PPB_VAR_ARRAY_BUFFER_DEV_INTERFACE_0_2 "PPB_VarArrayBuffer(Dev);0.2"
#define PPB_VAR_ARRAY_BUFFER_DEV_INTERFACE \
- PPB_VAR_ARRAY_BUFFER_DEV_INTERFACE_0_1
+ PPB_VAR_ARRAY_BUFFER_DEV_INTERFACE_0_2
/**
* @file
@@ -34,33 +34,67 @@
* these Vars are not part of the embedding page's DOM, and can only be shared
* with JavaScript via pp::Instance's PostMessage and HandleMessage functions.
*/
-struct PPB_VarArrayBuffer_Dev_0_1 {
+struct PPB_VarArrayBuffer_Dev_0_2 {
/**
* Create a zero-initialized VarArrayBuffer.
*
- * @param[in] size_in_bytes The size of the array buffer that will be created.
+ * @param[in] size_in_bytes The size of the ArrayBuffer that will be created.
*
- * @return A PP_Var which represents an VarArrayBuffer of the requested size
+ * @return A PP_Var which represents a VarArrayBuffer of the requested size
* with a reference count of 1.
*/
struct PP_Var (*Create)(uint32_t size_in_bytes);
/**
- * Returns the length of the VarArrayBuffer in bytes.
+ * Retrieves the length of the VarArrayBuffer in bytes. On success,
+ * byte_length is set to the length of the given ArrayBuffer var. On failure,
+ * byte_length is unchanged (this could happen, for instance, if the given
+ * PP_Var is not of type PP_VARTYPE_ARRAY_BUFFER). Note that ByteLength() will
+ * successfully retrieve the the size of an ArrayBuffer even if the
+ * ArrayBuffer is not currently mapped.
*
- * @return The length of the VarArrayBuffer in bytes.
+ * @param[in] array The ArrayBuffer whose length should be returned.
+ *
+ * @param[out] byte_length A variable which is set to the length of the given
+ * ArrayBuffer on success.
+ *
+ * @return PP_TRUE on success, PP_FALSE on failure.
*/
- uint32_t (*ByteLength)(struct PP_Var array);
+ PP_Bool (*ByteLength)(struct PP_Var array, uint32_t* byte_length);
/**
- * Returns a pointer to the beginning of the buffer for the given array.
+ * Maps the ArrayBuffer in to the module's address space and returns a pointer
+ * to the beginning of the buffer for the given ArrayBuffer PP_Var. Note that
+ * calling Map() can be a relatively expensive operation. Use care when
+ * calling it in performance-critical code. For example, you should call it
+ * only once when looping over an ArrayBuffer:
+ *
+ * <code>
+ * char* data = (char*)(array_buffer_if.Map(array_buffer_var));
+ * uint32_t byte_length = 0;
+ * PP_Bool ok = array_buffer_if.ByteLength(array_buffer_var, &byte_length);
+ * if (!ok)
+ * return DoSomethingBecauseMyVarIsNotAnArrayBuffer();
+ * for (uint32_t i = 0; i < byte_length; ++i)
+ * data[i] = 'A';
+ * </code>
*
- * @param[in] array The array whose buffer should be returned.
+ * @param[in] array The ArrayBuffer whose internal buffer should be returned.
*
- * @return A pointer to the buffer for this array.
+ * @return A pointer to the internal buffer for this ArrayBuffer. Returns NULL
+ * if the given PP_Var is not of type PP_VARTYPE_ARRAY_BUFFER.
*/
void* (*Map)(struct PP_Var array);
+ /**
+ * Unmaps the given ArrayBuffer var from the module address space. Use this if
+ * you want to save memory but might want to Map the buffer again later. The
+ * PP_Var remains valid and should still be released using PPB_Var when you
+ * are done with the ArrayBuffer.
+ *
+ * @param[in] array The ArrayBuffer which should be released.
+ */
+ void (*Unmap)(struct PP_Var array);
};
-typedef struct PPB_VarArrayBuffer_Dev_0_1 PPB_VarArrayBuffer_Dev;
+typedef struct PPB_VarArrayBuffer_Dev_0_2 PPB_VarArrayBuffer_Dev;
/**
* @}
*/
diff --git a/ppapi/cpp/dev/var_array_buffer_dev.cc b/ppapi/cpp/dev/var_array_buffer_dev.cc
index 61f697e..47ad9b3 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,59 @@ 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::VarArrayBuffer_Dev& VarArrayBuffer_Dev::operator=(
+ const VarArrayBuffer_Dev& other) {
+ Var::operator=(other);
+ return *this;
+}
+
+pp::Var& VarArrayBuffer_Dev::operator=(const Var& other) {
+ if (other.is_array_buffer()) {
+ return Var::operator=(other);
+ } else {
+ PP_NOTREACHED();
+ return *this;
}
- PP_NOTREACHED();
- return 0;
}
-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>()->Unmap(var_);
+ else
+ PP_NOTREACHED();
}
} // namespace pp
diff --git a/ppapi/cpp/dev/var_array_buffer_dev.h b/ppapi/cpp/dev/var_array_buffer_dev.h
index 6f8c959..6f7c18a 100644
--- a/ppapi/cpp/dev/var_array_buffer_dev.h
+++ b/ppapi/cpp/dev/var_array_buffer_dev.h
@@ -1,4 +1,4 @@
-// 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.
@@ -20,18 +20,37 @@ namespace pp {
class VarArrayBuffer_Dev : public Var {
public:
/// Contruct a VarArrayBuffer_Dev given a var for which is_array_buffer() is
- /// true. This will refer to the same buffer as var, but allows you to access
- /// methods specific to VarArrayBuffer_Dev.
+ /// true. This will refer to the same ArrayBuffer as var, but allows you to
+ /// access methods specific to VarArrayBuffer_Dev.
///
- /// @param[in] var An array buffer Var.
+ /// @param[in] var An ArrayBuffer Var.
explicit VarArrayBuffer_Dev(const Var& var);
+ /// Copy constructor.
VarArrayBuffer_Dev(const VarArrayBuffer_Dev& buffer) : Var(buffer) {}
+ virtual ~VarArrayBuffer_Dev() {}
+
+ /// This function assigns one VarArrayBuffer to another VarArrayBuffer.
+ ///
+ /// @param[in] other The VarArrayBuffer to be assigned.
+ ///
+ /// @return The resulting VarArrayBuffer.
+ VarArrayBuffer_Dev& operator=(const VarArrayBuffer_Dev& other);
+
+ /// This function assigns one VarArrayBuffer to another VarArrayBuffer. Var's
+ /// assignment operator is overloaded here so that we can check for assigning
+ /// a non-ArrayBuffer var to a VarArrayBuffer_Dev.
+ ///
+ /// @param[in] other The VarArrayBuffer to be assigned.
+ ///
+ /// @return The resulting VarArrayBuffer (as a Var&).
+ virtual Var& operator=(const Var& other);
+
/// Construct a new VarArrayBuffer_Dev which is size_in_bytes bytes long and
/// initialized to zero.
///
- /// @param[in] size_in_bytes The size of the constructed array in bytes.
+ /// @param[in] size_in_bytes The size of the constructed ArrayBuffer in bytes.
VarArrayBuffer_Dev(uint32_t size_in_bytes);
/// Return the length of the VarArrayBuffer_Dev in bytes.
@@ -39,17 +58,26 @@ class VarArrayBuffer_Dev : public Var {
/// @return The length of the VarArrayBuffer_Dev in bytes.
uint32_t ByteLength() const;
- /// Return a pointer to the buffer associated with this VarArrayBuffer_Dev.
+ /// Maps the ArrayBuffer in to the module's address space and returns a
+ /// pointer to the internal buffer for this ArrayBuffer.
+ ///
+ /// Note that calling Map() can be a relatively expensive operation. Use care
+ /// when calling it in performance-critical code. For example, you should call
+ /// it only once when looping over an ArrayBuffer:
///
- /// @return A pointer to the buffer associated with this VarArrayBuffer_Dev.
+ /// <code>
+ /// char* data = static_cast<char*>(array_buffer_var.Map());
+ /// uint32_t byte_length = array_buffer_var.ByteLength();
+ /// for (uint32_t i = 0; i < byte_length; ++i)
+ /// data[i] = 'A';
+ /// </code>
+ ///
+ /// @return A pointer to the internal buffer for this ArrayBuffer.
void* Map();
- const void* Map() const;
-
- virtual ~VarArrayBuffer_Dev() {}
- private:
- // We cache the buffer so that repeated calls to Map() are quick.
- void* buffer_;
+ /// Unmaps this ArrayBuffer var from the module address space. Use this if
+ /// you want to save memory but might want to Map the buffer again later.
+ void Unmap();
};
} // namespace pp
diff --git a/ppapi/cpp/var.h b/ppapi/cpp/var.h
index 871fb603..56c479f3 100644
--- a/ppapi/cpp/var.h
+++ b/ppapi/cpp/var.h
@@ -1,4 +1,4 @@
-// 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.
@@ -92,7 +92,7 @@ class Var {
/// @param[in] other The <code>Var</code> to be assigned.
///
/// @return A resulting <code>Var</code>.
- Var& operator=(const Var& other);
+ virtual Var& operator=(const Var& other);
/// This function compares object identity (rather than value identity) for
/// objects, dictionaries, and arrays
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/object_serialize.cc b/ppapi/native_client/src/shared/ppapi_proxy/object_serialize.cc
index 7d29502..6debbe2 100644
--- a/ppapi/native_client/src/shared/ppapi_proxy/object_serialize.cc
+++ b/ppapi/native_client/src/shared/ppapi_proxy/object_serialize.cc
@@ -131,7 +131,9 @@ uint32_t PpVarSize(const PP_Var& var) {
break;
}
case PP_VARTYPE_ARRAY_BUFFER: {
- uint32_t buffer_length = PPBVarArrayBufferInterface()->ByteLength(var);
+ uint32_t buffer_length = 0;
+ if (!PPBVarArrayBufferInterface()->ByteLength(var, &buffer_length))
+ return 0;
buffer_length = RoundedStringBytes(buffer_length);
if (AddWouldOverflow(buffer_length,
NACL_OFFSETOF(SerializedString, string_bytes))) {
@@ -226,8 +228,8 @@ bool SerializePpVar(const PP_Var* vars,
break;
}
case PP_VARTYPE_ARRAY_BUFFER: {
- uint32_t buffer_length =
- PPBVarArrayBufferInterface()->ByteLength(vars[i]);
+ uint32_t buffer_length = 0;
+ PPBVarArrayBufferInterface()->ByteLength(vars[i], &buffer_length);
SerializedString* ss = reinterpret_cast<SerializedString*>(p);
ss->fixed.u.string_length = buffer_length;
memcpy(reinterpret_cast<void*>(ss->string_bytes),
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_var.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_var.cc
index 6315c51..b642eb0 100644
--- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_var.cc
+++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_var.cc
@@ -99,14 +99,18 @@ PP_Var CreateArrayBuffer(uint32_t size_in_bytes) {
return var;
}
-uint32_t ByteLength(PP_Var var) {
+PP_Bool ByteLength(PP_Var var, uint32_t* byte_length) {
DebugPrintf("PPB_VarArrayBuffer::ByteLength: var=PPB_Var(%s)\n",
PluginVar::DebugString(var).c_str());
SharedArrayBufferProxyVar buffer_var = ArrayBufferProxyVar::CastFromProxyVar(
ProxyVarCache::GetInstance().SharedProxyVarForVar(var));
- uint32_t len = buffer_var->buffer_length();
- DebugPrintf("PPB_VarArrayBuffer::ByteLength: length=%"NACL_PRIu32"\n", len);
- return len;
+ if (buffer_var) {
+ *byte_length = buffer_var->buffer_length();
+ DebugPrintf("PPB_VarArrayBuffer::ByteLength: length=%"NACL_PRIu32"\n",
+ *byte_length);
+ return PP_TRUE;
+ }
+ return PP_FALSE;
}
void* Map(PP_Var var) {
@@ -119,6 +123,12 @@ void* Map(PP_Var var) {
return data;
}
+void Unmap(PP_Var var) {
+ DebugPrintf("PPB_VarArrayBuffer::Unap: var=PPB_Var(%s)\n",
+ PluginVar::DebugString(var).c_str());
+ // We don't use shared memory, so there's nothing to do.
+}
+
} // namespace
const PPB_Var* PluginVar::GetInterface() {
@@ -145,7 +155,8 @@ const PPB_VarArrayBuffer_Dev* PluginVar::GetArrayBufferInterface() {
static const PPB_VarArrayBuffer_Dev interface = {
CreateArrayBuffer,
ByteLength,
- Map
+ Map,
+ Unmap
};
return &interface;
}
@@ -254,10 +265,11 @@ void PluginVar::Print(const PP_Var& var) {
case PP_VARTYPE_OBJECT:
DebugPrintf("PP_Var(object: %"NACL_PRIu64")", GetVarId(var));
break;
+ case PP_VARTYPE_ARRAY_BUFFER:
+ DebugPrintf("PP_Var(object: %"NACL_PRIu64")", GetVarId(var));
+ break;
case PP_VARTYPE_ARRAY:
case PP_VARTYPE_DICTIONARY:
- case PP_VARTYPE_ARRAY_BUFFER:
- NACL_NOTREACHED();
break;
}
}
diff --git a/ppapi/proxy/plugin_array_buffer_var.cc b/ppapi/proxy/plugin_array_buffer_var.cc
index d88ca7b..6d16cfe 100644
--- a/ppapi/proxy/plugin_array_buffer_var.cc
+++ b/ppapi/proxy/plugin_array_buffer_var.cc
@@ -1,4 +1,4 @@
-// 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.
@@ -23,6 +23,10 @@ void* PluginArrayBufferVar::Map() {
return &(buffer_[0]);
}
+void PluginArrayBufferVar::Unmap() {
+ // We don't actually use shared memory yet, so do nothing.
+}
+
uint32 PluginArrayBufferVar::ByteLength() {
return buffer_.size();
}
diff --git a/ppapi/proxy/plugin_array_buffer_var.h b/ppapi/proxy/plugin_array_buffer_var.h
index 5e4d702..2eed216 100644
--- a/ppapi/proxy/plugin_array_buffer_var.h
+++ b/ppapi/proxy/plugin_array_buffer_var.h
@@ -1,4 +1,4 @@
-// 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.
@@ -22,6 +22,7 @@ class PluginArrayBufferVar : public ArrayBufferVar {
// ArrayBufferVar implementation.
virtual void* Map() OVERRIDE;
+ virtual void Unmap() OVERRIDE;
virtual uint32 ByteLength() OVERRIDE;
private:
diff --git a/ppapi/shared_impl/ppb_var_shared.cc b/ppapi/shared_impl/ppb_var_shared.cc
index 7b0ffb4..3fb1c03 100644
--- a/ppapi/shared_impl/ppb_var_shared.cc
+++ b/ppapi/shared_impl/ppb_var_shared.cc
@@ -75,11 +75,12 @@ PP_Var CreateArrayBufferVar(uint32_t size_in_bytes) {
size_in_bytes);
}
-uint32_t ByteLength(PP_Var array) {
+PP_Bool ByteLength(PP_Var array, uint32_t* byte_length) {
ArrayBufferVar* buffer = ArrayBufferVar::FromPPVar(array);
if (!buffer)
- return 0;
- return buffer->ByteLength();
+ return PP_FALSE;
+ *byte_length = buffer->ByteLength();
+ return PP_TRUE;
}
void* Map(PP_Var array) {
@@ -89,10 +90,17 @@ void* Map(PP_Var array) {
return buffer->Map();
}
+void Unmap(PP_Var array) {
+ ArrayBufferVar* buffer = ArrayBufferVar::FromPPVar(array);
+ if (buffer)
+ buffer->Unmap();
+}
+
const PPB_VarArrayBuffer_Dev var_arraybuffer_interface = {
&CreateArrayBufferVar,
&ByteLength,
- &Map
+ &Map,
+ &Unmap
};
} // namespace
diff --git a/ppapi/shared_impl/var.h b/ppapi/shared_impl/var.h
index d41d00e..4d833ae 100644
--- a/ppapi/shared_impl/var.h
+++ b/ppapi/shared_impl/var.h
@@ -1,4 +1,4 @@
-// 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.
@@ -140,6 +140,7 @@ class PPAPI_SHARED_EXPORT ArrayBufferVar : public Var {
virtual ~ArrayBufferVar();
virtual void* Map() = 0;
+ virtual void Unmap() = 0;
virtual uint32 ByteLength() = 0;
// Var override.
diff --git a/ppapi/tests/test_post_message.cc b/ppapi/tests/test_post_message.cc
index 6051e30..a79676b 100644
--- a/ppapi/tests/test_post_message.cc
+++ b/ppapi/tests/test_post_message.cc
@@ -263,6 +263,11 @@ std::string TestPostMessage::TestSendingArrayBuffer() {
pp::VarArrayBuffer_Dev test_data(sizes[i]);
if (sizes[i] > 0)
ASSERT_NE(NULL, test_data.Map());
+ // Make sure we can Unmap/Map successfully (there's not really any way to
+ // detect if it's unmapped, so we just re-map before getting the pointer to
+ // the buffer).
+ test_data.Unmap();
+ test_data.Map();
ASSERT_EQ(sizes[i], test_data.ByteLength());
unsigned char* buff = static_cast<unsigned char*>(test_data.Map());
const uint32_t kByteLength = test_data.ByteLength();
diff --git a/ppapi/tests/test_websocket.cc b/ppapi/tests/test_websocket.cc
index c0073eb..368079e 100644
--- a/ppapi/tests/test_websocket.cc
+++ b/ppapi/tests/test_websocket.cc
@@ -113,7 +113,9 @@ bool TestWebSocket::AreEqualWithString(const PP_Var& var, const char* string) {
bool TestWebSocket::AreEqualWithBinary(const PP_Var& var,
const uint8_t* data,
uint32_t size) {
- if (arraybuffer_interface_->ByteLength(var) != size)
+ uint32_t buffer_size = 0;
+ PP_Bool success = arraybuffer_interface_->ByteLength(var, &buffer_size);
+ if (!success || buffer_size != size)
return false;
if (memcmp(arraybuffer_interface_->Map(var), data, size))
return false;