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

Side by Side Diff: webkit/plugins/ppapi/resource_tracker.cc

Issue 6905088: New thunk system for Pepper proxy and implementation (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "webkit/plugins/ppapi/resource_tracker.h" 5 #include "webkit/plugins/ppapi/resource_tracker.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <set> 8 #include <set>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/rand_util.h" 11 #include "base/rand_util.h"
12 #include "ppapi/c/pp_resource.h" 12 #include "ppapi/c/pp_resource.h"
13 #include "ppapi/c/pp_var.h" 13 #include "ppapi/c/pp_var.h"
14 #include "ppapi/shared_impl/tracker_base.h"
14 #include "webkit/plugins/ppapi/plugin_module.h" 15 #include "webkit/plugins/ppapi/plugin_module.h"
15 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 16 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
16 #include "webkit/plugins/ppapi/resource.h" 17 #include "webkit/plugins/ppapi/resource.h"
18 #include "webkit/plugins/ppapi/resource_creation_impl.h"
17 #include "webkit/plugins/ppapi/var.h" 19 #include "webkit/plugins/ppapi/var.h"
18 20
19 enum PPIdType { 21 enum PPIdType {
20 PP_ID_TYPE_MODULE, 22 PP_ID_TYPE_MODULE,
21 PP_ID_TYPE_INSTANCE, 23 PP_ID_TYPE_INSTANCE,
22 PP_ID_TYPE_RESOURCE, 24 PP_ID_TYPE_RESOURCE,
23 PP_ID_TYPE_VAR, 25 PP_ID_TYPE_VAR,
24 PP_ID_TYPE_COUNT 26 PP_ID_TYPE_COUNT
25 }; 27 };
26 28
27 static const unsigned int kPPIdTypeBits = 2; 29 static const unsigned int kPPIdTypeBits = 2;
28 COMPILE_ASSERT(PP_ID_TYPE_COUNT <= (1<<kPPIdTypeBits), 30 COMPILE_ASSERT(PP_ID_TYPE_COUNT <= (1<<kPPIdTypeBits),
29 kPPIdTypeBits_is_too_small_for_all_id_types); 31 kPPIdTypeBits_is_too_small_for_all_id_types);
30 32
31 template <typename T> static inline T MakeTypedId(T value, PPIdType type) { 33 template <typename T> static inline T MakeTypedId(T value, PPIdType type) {
32 return (value << kPPIdTypeBits) | static_cast<T>(type); 34 return (value << kPPIdTypeBits) | static_cast<T>(type);
33 } 35 }
34 36
35 template <typename T> static inline bool CheckIdType(T id, PPIdType type) { 37 template <typename T> static inline bool CheckIdType(T id, PPIdType type) {
36 // 0 is a valid resource. 38 // 0 is a valid resource.
37 if (!id) 39 if (!id)
38 return true; 40 return true;
39 const T mask = (static_cast<T>(1) << kPPIdTypeBits) - 1; 41 const T mask = (static_cast<T>(1) << kPPIdTypeBits) - 1;
40 return (id & mask) == type; 42 return (id & mask) == type;
41 } 43 }
42 44
45 namespace shared_impl = ::ppapi::shared_impl;
46
43 namespace webkit { 47 namespace webkit {
44 namespace ppapi { 48 namespace ppapi {
45 49
50 namespace {
51
52 shared_impl::TrackerBase* GetTrackerBase() {
53 return ResourceTracker::Get();
54 }
55
56 } // namespace
57
46 struct ResourceTracker::InstanceData { 58 struct ResourceTracker::InstanceData {
47 InstanceData() : instance(0) {} 59 InstanceData() : instance(0) {}
48 60
49 // Non-owning pointer to the instance object. When a PluginInstance is 61 // Non-owning pointer to the instance object. When a PluginInstance is
50 // destroyed, it will notify us and we'll delete all associated data. 62 // destroyed, it will notify us and we'll delete all associated data.
51 PluginInstance* instance; 63 PluginInstance* instance;
52 64
53 // Resources and object vars associated with the instance. 65 // Resources and object vars associated with the instance.
54 ResourceSet resources; 66 ResourceSet resources;
55 VarSet object_vars; 67 VarSet object_vars;
56 }; 68 };
57 69
58 scoped_refptr<Resource> ResourceTracker::GetResource(PP_Resource res) const { 70 scoped_refptr<Resource> ResourceTracker::GetResource(PP_Resource res) const {
59 DLOG_IF(ERROR, !CheckIdType(res, PP_ID_TYPE_RESOURCE)) 71 DLOG_IF(ERROR, !CheckIdType(res, PP_ID_TYPE_RESOURCE))
60 << res << " is not a PP_Resource."; 72 << res << " is not a PP_Resource.";
61 ResourceMap::const_iterator result = live_resources_.find(res); 73 ResourceMap::const_iterator result = live_resources_.find(res);
62 if (result == live_resources_.end()) { 74 if (result == live_resources_.end()) {
63 return scoped_refptr<Resource>(); 75 return scoped_refptr<Resource>();
64 } 76 }
65 return result->second.first; 77 return result->second.first;
66 } 78 }
67 79
68 // static 80 // static
69 ResourceTracker* ResourceTracker::global_tracker_ = NULL; 81 ResourceTracker* ResourceTracker::global_tracker_ = NULL;
70 ResourceTracker* ResourceTracker::singleton_override_ = NULL; 82 ResourceTracker* ResourceTracker::singleton_override_ = NULL;
71 83
72 ResourceTracker::ResourceTracker() 84 ResourceTracker::ResourceTracker()
73 : last_resource_id_(0), 85 : last_resource_id_(0),
74 last_var_id_(0) { 86 last_var_id_(0) {
87 // Wire up the new shared resource tracker base to use our implementation.
88 shared_impl::TrackerBase::Init(&GetTrackerBase);
75 } 89 }
76 90
77 ResourceTracker::~ResourceTracker() { 91 ResourceTracker::~ResourceTracker() {
78 } 92 }
79 93
80 // static 94 // static
81 ResourceTracker* ResourceTracker::Get() { 95 ResourceTracker* ResourceTracker::Get() {
82 if (singleton_override_) 96 if (singleton_override_)
83 return singleton_override_; 97 return singleton_override_;
84 if (!global_tracker_) 98 if (!global_tracker_)
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 233
220 uint32 ResourceTracker::GetLiveObjectsForInstance( 234 uint32 ResourceTracker::GetLiveObjectsForInstance(
221 PP_Instance instance) const { 235 PP_Instance instance) const {
222 InstanceMap::const_iterator found = instance_map_.find(instance); 236 InstanceMap::const_iterator found = instance_map_.find(instance);
223 if (found == instance_map_.end()) 237 if (found == instance_map_.end())
224 return 0; 238 return 0;
225 return static_cast<uint32>(found->second.resources.size() + 239 return static_cast<uint32>(found->second.resources.size() +
226 found->second.object_vars.size()); 240 found->second.object_vars.size());
227 } 241 }
228 242
243 shared_impl::ResourceObjectBase* ResourceTracker::GetResourceAPI(
244 PP_Resource res) {
245 DLOG_IF(ERROR, !CheckIdType(res, PP_ID_TYPE_RESOURCE))
246 << res << " is not a PP_Resource.";
247 ResourceMap::const_iterator result = live_resources_.find(res);
248 if (result == live_resources_.end())
249 return NULL;
250 return result->second.first.get();
251 }
252
253 shared_impl::FunctionGroupBase* ResourceTracker::GetFunctionAPI(
254 PP_Instance inst,
255 pp::proxy::InterfaceID id) {
256 if (function_proxies_[id].get())
257 return function_proxies_[id].get();
258
259 if (id == ::pp::proxy::INTERFACE_ID_RESOURCE_CREATION)
260 function_proxies_[id].reset(new ResourceCreationImpl());
261
262 return function_proxies_[id].get();
263 }
264
229 scoped_refptr<Var> ResourceTracker::GetVar(int32 var_id) const { 265 scoped_refptr<Var> ResourceTracker::GetVar(int32 var_id) const {
230 DLOG_IF(ERROR, !CheckIdType(var_id, PP_ID_TYPE_VAR)) 266 DLOG_IF(ERROR, !CheckIdType(var_id, PP_ID_TYPE_VAR))
231 << var_id << " is not a PP_Var ID."; 267 << var_id << " is not a PP_Var ID.";
232 VarMap::const_iterator result = live_vars_.find(var_id); 268 VarMap::const_iterator result = live_vars_.find(var_id);
233 if (result == live_vars_.end()) 269 if (result == live_vars_.end())
234 return scoped_refptr<Var>(); 270 return scoped_refptr<Var>();
235 return result->second.first; 271 return result->second.first;
236 } 272 }
237 273
238 bool ResourceTracker::AddRefVar(int32 var_id) { 274 bool ResourceTracker::AddRefVar(int32 var_id) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 386
351 // static 387 // static
352 void ResourceTracker::ClearSingletonOverride() { 388 void ResourceTracker::ClearSingletonOverride() {
353 DCHECK(singleton_override_); 389 DCHECK(singleton_override_);
354 singleton_override_ = NULL; 390 singleton_override_ = NULL;
355 } 391 }
356 392
357 } // namespace ppapi 393 } // namespace ppapi
358 } // namespace webkit 394 } // namespace webkit
359 395
OLDNEW
« webkit/plugins/ppapi/ppb_graphics_2d_impl.h ('K') | « webkit/plugins/ppapi/resource_tracker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698