Index: ppapi/shared_impl/ppb_resource_array_shared.cc |
diff --git a/ppapi/shared_impl/ppb_resource_array_shared.cc b/ppapi/shared_impl/ppb_resource_array_shared.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d61297ce0dc8ee3279bbcbd625fa986ef236899c |
--- /dev/null |
+++ b/ppapi/shared_impl/ppb_resource_array_shared.cc |
@@ -0,0 +1,75 @@ |
+// 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/shared_impl/ppb_resource_array_shared.h" |
+ |
+#include "base/logging.h" |
+#include "ppapi/shared_impl/ppapi_globals.h" |
+#include "ppapi/shared_impl/resource_tracker.h" |
+ |
+using ppapi::thunk::PPB_ResourceArray_API; |
+ |
+namespace ppapi { |
+ |
+PPB_ResourceArray_Shared::PPB_ResourceArray_Shared(const InitAsImpl&, |
+ PP_Instance instance, |
+ const PP_Resource elements[], |
+ uint32_t size) |
+ : Resource(instance), |
+ elements_(NULL), |
+ size_(0) { |
+ Initialize(elements, size); |
+} |
+ |
+PPB_ResourceArray_Shared::PPB_ResourceArray_Shared(const InitAsProxy&, |
+ PP_Instance instance, |
+ const PP_Resource elements[], |
+ uint32_t size) |
+ : Resource(HostResource::MakeInstanceOnly(instance)), |
+ elements_(NULL), |
+ size_(0) { |
+ Initialize(elements, size); |
+} |
+ |
+PPB_ResourceArray_Shared::~PPB_ResourceArray_Shared() { |
+ if (!elements_) |
+ return; |
+ |
+ for (uint32_t index = 0; index < size_; ++index) { |
+ PP_Resource element = elements_[index]; |
+ if (element) |
+ PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(element); |
+ } |
+ |
+ delete[] elements_; |
+} |
+ |
+PPB_ResourceArray_API* PPB_ResourceArray_Shared::AsPPB_ResourceArray_API() { |
+ return this; |
+} |
+ |
+uint32_t PPB_ResourceArray_Shared::GetSize() { |
+ return size_; |
+} |
+ |
+PP_Resource PPB_ResourceArray_Shared::GetAt(uint32_t index) { |
+ return index < size_ ? elements_[index] : 0; |
+} |
+ |
+void PPB_ResourceArray_Shared::Initialize(const PP_Resource elements[], |
+ uint32_t size) { |
+ DCHECK(!elements_ && size_ == 0); |
+ |
+ size_ = size; |
+ if (size > 0) |
+ elements_ = new PP_Resource[size]; |
+ for (uint32_t index = 0; index < size; ++index) { |
+ PP_Resource element = elements[index]; |
+ elements_[index] = element; |
+ if (element) |
+ PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(element); |
+ } |
+} |
+ |
+} // namespace ppapi |