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

Unified Diff: ppapi/shared_impl/ppb_resource_array_shared.cc

Issue 9111008: Introduce PPB_ResourceArray_Dev. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 12 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/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

Powered by Google App Engine
This is Rietveld 408576698