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

Side by Side Diff: ppapi/shared_impl/ppb_resource_array_shared.cc

Issue 9391013: Make a global enum to differentiate impl & proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/shared_impl/ppb_resource_array_shared.h" 5 #include "ppapi/shared_impl/ppb_resource_array_shared.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ppapi/shared_impl/ppapi_globals.h" 8 #include "ppapi/shared_impl/ppapi_globals.h"
9 #include "ppapi/shared_impl/resource_tracker.h" 9 #include "ppapi/shared_impl/resource_tracker.h"
10 10
11 using ppapi::thunk::PPB_ResourceArray_API; 11 using ppapi::thunk::PPB_ResourceArray_API;
12 12
13 namespace ppapi { 13 namespace ppapi {
14 14
15 PPB_ResourceArray_Shared::PPB_ResourceArray_Shared(const InitAsImpl&, 15 PPB_ResourceArray_Shared::PPB_ResourceArray_Shared(ResourceObjectType type,
16 PP_Instance instance, 16 PP_Instance instance,
17 const PP_Resource elements[], 17 const PP_Resource elements[],
18 uint32_t size) 18 uint32_t size)
19 : Resource(instance) { 19 : Resource(type, instance) {
20 Initialize(elements, size); 20 DCHECK(resources_.empty());
21 }
22 21
23 PPB_ResourceArray_Shared::PPB_ResourceArray_Shared(const InitAsProxy&, 22 resources_.reserve(size);
24 PP_Instance instance, 23 for (uint32_t index = 0; index < size; ++index) {
25 const PP_Resource elements[], 24 PP_Resource element = elements[index];
26 uint32_t size) 25 if (element)
27 : Resource(HostResource::MakeInstanceOnly(instance)) { 26 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(element);
28 Initialize(elements, size); 27 resources_.push_back(element);
28 }
29 } 29 }
30 30
31 PPB_ResourceArray_Shared::~PPB_ResourceArray_Shared() { 31 PPB_ResourceArray_Shared::~PPB_ResourceArray_Shared() {
32 for (std::vector<PP_Resource>::iterator iter = resources_.begin(); 32 for (std::vector<PP_Resource>::iterator iter = resources_.begin();
33 iter != resources_.end(); ++iter) { 33 iter != resources_.end(); ++iter) {
34 if (*iter) 34 if (*iter)
35 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(*iter); 35 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(*iter);
36 } 36 }
37 } 37 }
38 38
39 PPB_ResourceArray_API* PPB_ResourceArray_Shared::AsPPB_ResourceArray_API() { 39 PPB_ResourceArray_API* PPB_ResourceArray_Shared::AsPPB_ResourceArray_API() {
40 return this; 40 return this;
41 } 41 }
42 42
43 uint32_t PPB_ResourceArray_Shared::GetSize() { 43 uint32_t PPB_ResourceArray_Shared::GetSize() {
44 return static_cast<uint32_t>(resources_.size()); 44 return static_cast<uint32_t>(resources_.size());
45 } 45 }
46 46
47 PP_Resource PPB_ResourceArray_Shared::GetAt(uint32_t index) { 47 PP_Resource PPB_ResourceArray_Shared::GetAt(uint32_t index) {
48 return index < resources_.size() ? resources_[index] : 0; 48 return index < resources_.size() ? resources_[index] : 0;
49 } 49 }
50 50
51 void PPB_ResourceArray_Shared::Initialize(const PP_Resource elements[],
52 uint32_t size) {
53 DCHECK(resources_.empty());
54
55 resources_.reserve(size);
56 for (uint32_t index = 0; index < size; ++index) {
57 PP_Resource element = elements[index];
58 if (element)
59 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(element);
60 resources_.push_back(element);
61 }
62 }
63
64 } // namespace ppapi 51 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698