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

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

Issue 8344025: Add a new globals object for PPAPI tracking information. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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
Property Changes:
Deleted: svn:mergeinfo
Reverse-merged /branches/chrome_webkit_merge_branch/src/webkit/plugins/ppapi/resource_tracker.cc:r3734-4217,4606-5108,5177-5263
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/function_group_base.h" 14 #include "ppapi/shared_impl/function_group_base.h"
15 #include "ppapi/shared_impl/id_assignment.h" 15 #include "ppapi/shared_impl/id_assignment.h"
16 #include "ppapi/shared_impl/tracker_base.h" 16 #include "ppapi/shared_impl/tracker_base.h"
17 #include "webkit/plugins/ppapi/callbacks.h" 17 #include "webkit/plugins/ppapi/callbacks.h"
18 #include "webkit/plugins/ppapi/host_globals.h"
18 #include "webkit/plugins/ppapi/npobject_var.h" 19 #include "webkit/plugins/ppapi/npobject_var.h"
19 #include "webkit/plugins/ppapi/plugin_module.h" 20 #include "webkit/plugins/ppapi/plugin_module.h"
20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 21 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
21 #include "webkit/plugins/ppapi/ppb_cursor_control_impl.h" 22 #include "webkit/plugins/ppapi/ppb_cursor_control_impl.h"
22 #include "webkit/plugins/ppapi/ppb_font_impl.h" 23 #include "webkit/plugins/ppapi/ppb_font_impl.h"
23 #include "webkit/plugins/ppapi/ppb_text_input_impl.h" 24 #include "webkit/plugins/ppapi/ppb_text_input_impl.h"
24 #include "webkit/plugins/ppapi/resource_creation_impl.h" 25 #include "webkit/plugins/ppapi/resource_creation_impl.h"
25 #include "webkit/plugins/ppapi/resource_helper.h" 26 #include "webkit/plugins/ppapi/resource_helper.h"
26 27
27 using ppapi::CheckIdType; 28 using ppapi::CheckIdType;
28 using ppapi::MakeTypedId; 29 using ppapi::MakeTypedId;
29 using ppapi::NPObjectVar; 30 using ppapi::NPObjectVar;
30 using ppapi::PPIdType; 31 using ppapi::PPIdType;
31 using ppapi::Var; 32 using ppapi::Var;
32 33
33 namespace webkit { 34 namespace webkit {
34 namespace ppapi { 35 namespace ppapi {
35 36
36 namespace { 37 namespace {
37 38
38 ::ppapi::TrackerBase* GetTrackerBase() { 39 ::ppapi::TrackerBase* GetTrackerBase() {
39 return ResourceTracker::Get(); 40 return HostGlobals::Get()->host_resource_tracker();
40 } 41 }
41 42
42 } // namespace 43 } // namespace
43 44
44 typedef std::map<NPObject*, NPObjectVar*> NPObjectToNPObjectVarMap; 45 typedef std::map<NPObject*, NPObjectVar*> NPObjectToNPObjectVarMap;
45 46
46 struct ResourceTracker::InstanceData { 47 struct ResourceTracker::InstanceData {
47 InstanceData() : instance(0) {} 48 InstanceData() : instance(0) {}
48 49
49 // Non-owning pointer to the instance object. When a PluginInstance is 50 // Non-owning pointer to the instance object. When a PluginInstance is
50 // destroyed, it will notify us and we'll delete all associated data. 51 // destroyed, it will notify us and we'll delete all associated data.
51 PluginInstance* instance; 52 PluginInstance* instance;
52 53
53 // Tracks all live NPObjectVars used by this module so we can map NPObjects 54 // Tracks all live NPObjectVars used by this module so we can map NPObjects
54 // to the corresponding object, and also release these properly if the 55 // to the corresponding object, and also release these properly if the
55 // instance goes away when there are still refs. These are non-owning 56 // instance goes away when there are still refs. These are non-owning
56 // references. 57 // references.
57 NPObjectToNPObjectVarMap np_object_to_object_var; 58 NPObjectToNPObjectVarMap np_object_to_object_var;
58 59
59 // Lazily allocated function proxies for the different interfaces. 60 // Lazily allocated function proxies for the different interfaces.
60 scoped_ptr< ::ppapi::FunctionGroupBase > 61 scoped_ptr< ::ppapi::FunctionGroupBase >
61 function_proxies[::ppapi::proxy::INTERFACE_ID_COUNT]; 62 function_proxies[::ppapi::proxy::INTERFACE_ID_COUNT];
62 }; 63 };
63 64
64 // static
65 ResourceTracker* ResourceTracker::global_tracker_ = NULL;
66 ResourceTracker* ResourceTracker::singleton_override_ = NULL;
67
68 ResourceTracker::ResourceTracker() { 65 ResourceTracker::ResourceTracker() {
69 // Wire up the new shared resource tracker base to use our implementation. 66 // Wire up the new shared resource tracker base to use our implementation.
70 ::ppapi::TrackerBase::Init(&GetTrackerBase); 67 ::ppapi::TrackerBase::Init(&GetTrackerBase);
71 } 68 }
72 69
73 ResourceTracker::~ResourceTracker() { 70 ResourceTracker::~ResourceTracker() {
74 } 71 }
75 72
76 // static
77 ResourceTracker* ResourceTracker::Get() {
78 if (singleton_override_)
79 return singleton_override_;
80 if (!global_tracker_)
81 global_tracker_ = new ResourceTracker;
82 return global_tracker_;
83 }
84
85 void ResourceTracker::CleanupInstanceData(PP_Instance instance, 73 void ResourceTracker::CleanupInstanceData(PP_Instance instance,
86 bool delete_instance) { 74 bool delete_instance) {
87 DLOG_IF(ERROR, !CheckIdType(instance, ::ppapi::PP_ID_TYPE_INSTANCE)) 75 DLOG_IF(ERROR, !CheckIdType(instance, ::ppapi::PP_ID_TYPE_INSTANCE))
88 << instance << " is not a PP_Instance."; 76 << instance << " is not a PP_Instance.";
89 InstanceMap::iterator found = instance_map_.find(instance); 77 InstanceMap::iterator found = instance_map_.find(instance);
90 if (found == instance_map_.end()) { 78 if (found == instance_map_.end()) {
91 NOTREACHED(); 79 NOTREACHED();
92 return; 80 return;
93 } 81 }
94 InstanceData& data = *found->second; 82 InstanceData& data = *found->second;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 case ::ppapi::proxy::INTERFACE_ID_RESOURCE_CREATION: 135 case ::ppapi::proxy::INTERFACE_ID_RESOURCE_CREATION:
148 proxy.reset(new ResourceCreationImpl(instance)); 136 proxy.reset(new ResourceCreationImpl(instance));
149 break; 137 break;
150 default: 138 default:
151 NOTREACHED(); 139 NOTREACHED();
152 } 140 }
153 141
154 return proxy.get(); 142 return proxy.get();
155 } 143 }
156 144
157 ::ppapi::VarTracker* ResourceTracker::GetVarTracker() {
158 return &var_tracker_;
159 }
160
161 ::ppapi::ResourceTracker* ResourceTracker::GetResourceTracker() {
162 return this;
163 }
164
165 PP_Module ResourceTracker::GetModuleForInstance(PP_Instance instance) { 145 PP_Module ResourceTracker::GetModuleForInstance(PP_Instance instance) {
166 PluginInstance* inst = GetInstance(instance); 146 PluginInstance* inst = GetInstance(instance);
167 if (!inst) 147 if (!inst)
168 return 0; 148 return 0;
169 return inst->module()->pp_module(); 149 return inst->module()->pp_module();
170 } 150 }
171 151
172 void ResourceTracker::LastPluginRefWasDeleted(::ppapi::Resource* object) { 152 void ResourceTracker::LastPluginRefWasDeleted(::ppapi::Resource* object) {
173 ::ppapi::ResourceTracker::LastPluginRefWasDeleted(object); 153 ::ppapi::ResourceTracker::LastPluginRefWasDeleted(object);
174 154
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 282
303 PluginModule* ResourceTracker::GetModule(PP_Module module) { 283 PluginModule* ResourceTracker::GetModule(PP_Module module) {
304 DLOG_IF(ERROR, !CheckIdType(module, ::ppapi::PP_ID_TYPE_MODULE)) 284 DLOG_IF(ERROR, !CheckIdType(module, ::ppapi::PP_ID_TYPE_MODULE))
305 << module << " is not a PP_Module."; 285 << module << " is not a PP_Module.";
306 ModuleMap::iterator found = module_map_.find(module); 286 ModuleMap::iterator found = module_map_.find(module);
307 if (found == module_map_.end()) 287 if (found == module_map_.end())
308 return NULL; 288 return NULL;
309 return found->second; 289 return found->second;
310 } 290 }
311 291
312 // static
313 void ResourceTracker::SetSingletonOverride(ResourceTracker* tracker) {
314 DCHECK(!singleton_override_);
315 singleton_override_ = tracker;
316 }
317
318 // static
319 void ResourceTracker::ClearSingletonOverride() {
320 DCHECK(singleton_override_);
321 singleton_override_ = NULL;
322 }
323
324 } // namespace ppapi 292 } // namespace ppapi
325 } // namespace webkit 293 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/resource_tracker.h ('k') | webkit/plugins/ppapi/resource_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698