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

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

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