blob: f7353f116620c3571c7d96bdf5f1a39cdaaad872 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// 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(ResourceObjectType type,
PP_Instance instance,
const PP_Resource elements[],
uint32_t size)
: Resource(type, instance) {
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);
}
}
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;
}
} // namespace ppapi
|