Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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. | |
| 4 | |
| 5 #ifndef NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_ARRAY_BUFFER_PROXY_VAR_H_ | |
| 6 #define NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_ARRAY_BUFFER_PROXY_VAR_H_ | |
| 7 | |
| 8 #include "native_client/src/include/nacl_memory.h" | |
| 9 #include "native_client/src/shared/ppapi_proxy/proxy_var.h" | |
| 10 | |
| 11 #include <vector> | |
| 12 | |
| 13 namespace ppapi_proxy { | |
| 14 | |
| 15 // Subclass of ProxyVar that handles ArrayBuffer objects. | |
| 16 class ArrayBufferProxyVar : public ProxyVar { | |
| 17 public: | |
| 18 explicit ArrayBufferProxyVar(uint32_t size_in_bytes) | |
| 19 : ProxyVar(PP_VARTYPE_ARRAY_BUFFER), buffer_(size_in_bytes, 0) {} | |
| 20 | |
| 21 void* buffer() { return buffer_.empty() ? NULL : &buffer_[0]; } | |
| 22 uint32_t buffer_length() const { return buffer_.size(); } | |
| 23 | |
| 24 // Convenience function to do type checking and down-casting. This returns a | |
| 25 // scoped_refptr<>, so you don't have to down-cast the raw pointer. | |
| 26 static scoped_refptr<ArrayBufferProxyVar> CastFromProxyVar( | |
| 27 SharedProxyVar proxy_var) { | |
| 28 if (proxy_var == NULL || | |
| 29 proxy_var->pp_var_type() != PP_VARTYPE_ARRAY_BUFFER) { | |
| 30 scoped_refptr<ArrayBufferProxyVar> null_ptr; | |
| 31 return null_ptr; | |
| 32 } | |
| 33 return scoped_refptr<ArrayBufferProxyVar>( | |
| 34 static_cast<ArrayBufferProxyVar*>(proxy_var.get())); | |
| 35 } | |
| 36 | |
| 37 private: | |
| 38 std::vector<uint8_t> buffer_; | |
| 39 | |
| 40 ArrayBufferProxyVar(); // Not implemented, do not use. | |
|
brettw
2011/12/28 20:05:14
Are you sure you need this to prevent the empty co
| |
| 41 }; | |
| 42 | |
| 43 typedef scoped_refptr<ArrayBufferProxyVar> SharedArrayBufferProxyVar; | |
| 44 | |
| 45 } // namespace ppapi_proxy | |
| 46 | |
| 47 #endif // NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_ARRAY_BUFFER_PROXY_VAR_H_ | |
| OLD | NEW |