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

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: sync 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
« no previous file with comments | « ppapi/shared_impl/ppb_resource_array_shared.h ('k') | ppapi/shared_impl/resource.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..9949fd5e33a7682bb0f45dcf02623cdf13042d2c
--- /dev/null
+++ b/ppapi/shared_impl/ppb_resource_array_shared.cc
@@ -0,0 +1,64 @@
+// 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) {
+ 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)) {
+ Initialize(elements, size);
+}
+
+PPB_ResourceArray_Shared::~PPB_ResourceArray_Shared() {
+ for (std::vector<PP_Resource>::iterator iter = resources_.begin();
+ iter != resources_.end(); ++iter) {
+ if (*iter)
+ PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(*iter);
+ }
+}
+
+PPB_ResourceArray_API* PPB_ResourceArray_Shared::AsPPB_ResourceArray_API() {
+ return this;
+}
+
+uint32_t PPB_ResourceArray_Shared::GetSize() {
+ return static_cast<uint32_t>(resources_.size());
+}
+
+PP_Resource PPB_ResourceArray_Shared::GetAt(uint32_t index) {
+ return index < resources_.size() ? resources_[index] : 0;
+}
+
+void PPB_ResourceArray_Shared::Initialize(const PP_Resource elements[],
+ uint32_t size) {
+ DCHECK(resources_.empty());
+
+ resources_.reserve(size);
+ for (uint32_t index = 0; index < size; ++index) {
+ PP_Resource element = elements[index];
+ if (element)
+ PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(element);
+ resources_.push_back(element);
+ }
+}
+
+} // namespace ppapi
« no previous file with comments | « ppapi/shared_impl/ppb_resource_array_shared.h ('k') | ppapi/shared_impl/resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698