OLD | NEW |
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 "ppapi/proxy/plugin_resource_tracker.h" | 5 #include "ppapi/proxy/plugin_resource_tracker.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "ppapi/proxy/plugin_dispatcher.h" | 9 #include "ppapi/proxy/plugin_dispatcher.h" |
| 10 #include "ppapi/proxy/plugin_globals.h" |
10 #include "ppapi/proxy/ppapi_messages.h" | 11 #include "ppapi/proxy/ppapi_messages.h" |
11 #include "ppapi/proxy/serialized_var.h" | 12 #include "ppapi/proxy/serialized_var.h" |
12 #include "ppapi/shared_impl/proxy_lock.h" | 13 #include "ppapi/shared_impl/proxy_lock.h" |
13 #include "ppapi/shared_impl/resource.h" | 14 #include "ppapi/shared_impl/resource.h" |
14 #include "ppapi/shared_impl/tracker_base.h" | 15 #include "ppapi/shared_impl/tracker_base.h" |
15 #include "ppapi/shared_impl/var.h" | 16 #include "ppapi/shared_impl/var.h" |
16 | 17 |
17 namespace ppapi { | 18 namespace ppapi { |
18 namespace proxy { | 19 namespace proxy { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 // When non-NULL, this object overrides the ResourceTrackerSingleton. | |
23 PluginResourceTracker* g_resource_tracker_override = NULL; | |
24 | |
25 TrackerBase* GetTrackerBase() { | 23 TrackerBase* GetTrackerBase() { |
26 return PluginResourceTracker::GetInstance(); | 24 return PluginGlobals::Get()->plugin_resource_tracker(); |
27 } | 25 } |
28 | 26 |
29 } // namespace | 27 } // namespace |
30 | 28 |
31 PluginResourceTracker::PluginResourceTracker() | 29 PluginResourceTracker::PluginResourceTracker() { |
32 : var_tracker_test_override_(NULL) { | |
33 #ifdef ENABLE_PEPPER_THREADING | 30 #ifdef ENABLE_PEPPER_THREADING |
34 // Set the global proxy lock, since the plugin-side of the proxy needs to be | 31 // Set the global proxy lock, since the plugin-side of the proxy needs to be |
35 // synchronized. | 32 // synchronized. |
36 ppapi::ProxyLock::Set(&proxy_lock_); | 33 ppapi::ProxyLock::Set(&proxy_lock_); |
37 #endif | 34 #endif |
38 } | 35 } |
39 | 36 |
40 PluginResourceTracker::~PluginResourceTracker() { | 37 PluginResourceTracker::~PluginResourceTracker() { |
41 #ifdef ENABLE_PEPPER_THREADING | 38 #ifdef ENABLE_PEPPER_THREADING |
42 ppapi::ProxyLock::Reset(); | 39 ppapi::ProxyLock::Reset(); |
43 #endif | 40 #endif |
44 } | 41 } |
45 | 42 |
46 // static | 43 // static |
47 void PluginResourceTracker::SetInstanceForTest(PluginResourceTracker* tracker) { | |
48 g_resource_tracker_override = tracker; | |
49 } | |
50 | |
51 // static | |
52 PluginResourceTracker* PluginResourceTracker::GetInstance() { | |
53 if (g_resource_tracker_override) | |
54 return g_resource_tracker_override; | |
55 return Singleton<PluginResourceTracker>::get(); | |
56 } | |
57 | |
58 // static | |
59 TrackerBase* PluginResourceTracker::GetTrackerBaseInstance() { | 44 TrackerBase* PluginResourceTracker::GetTrackerBaseInstance() { |
60 return GetInstance(); | 45 return GetTrackerBase(); |
61 } | 46 } |
62 | 47 |
63 PP_Resource PluginResourceTracker::PluginResourceForHostResource( | 48 PP_Resource PluginResourceTracker::PluginResourceForHostResource( |
64 const HostResource& resource) const { | 49 const HostResource& resource) const { |
65 HostResourceMap::const_iterator found = host_resource_map_.find(resource); | 50 HostResourceMap::const_iterator found = host_resource_map_.find(resource); |
66 if (found == host_resource_map_.end()) | 51 if (found == host_resource_map_.end()) |
67 return 0; | 52 return 0; |
68 return found->second; | 53 return found->second; |
69 } | 54 } |
70 | 55 |
71 FunctionGroupBase* PluginResourceTracker::GetFunctionAPI(PP_Instance inst, | 56 FunctionGroupBase* PluginResourceTracker::GetFunctionAPI(PP_Instance inst, |
72 InterfaceID id) { | 57 InterfaceID id) { |
73 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(inst); | 58 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(inst); |
74 if (dispatcher) | 59 if (dispatcher) |
75 return dispatcher->GetFunctionAPI(id); | 60 return dispatcher->GetFunctionAPI(id); |
76 return NULL; | 61 return NULL; |
77 } | 62 } |
78 | 63 |
79 VarTracker* PluginResourceTracker::GetVarTracker() { | |
80 return &var_tracker(); | |
81 } | |
82 | |
83 ResourceTracker* PluginResourceTracker::GetResourceTracker() { | |
84 return this; | |
85 } | |
86 | |
87 PP_Module PluginResourceTracker::GetModuleForInstance(PP_Instance instance) { | 64 PP_Module PluginResourceTracker::GetModuleForInstance(PP_Instance instance) { |
88 // Currently proxied plugins don't use the PP_Module for anything useful. | 65 // Currently proxied plugins don't use the PP_Module for anything useful. |
89 return 0; | 66 return 0; |
90 } | 67 } |
91 | 68 |
92 PP_Resource PluginResourceTracker::AddResource(Resource* object) { | 69 PP_Resource PluginResourceTracker::AddResource(Resource* object) { |
93 PP_Resource ret = ResourceTracker::AddResource(object); | 70 PP_Resource ret = ResourceTracker::AddResource(object); |
94 | 71 |
95 // Some resources are plugin-only, so they don't have a host resource. | 72 // Some resources are plugin-only, so they don't have a host resource. |
96 if (object->host_resource().host_resource()) | 73 if (object->host_resource().host_resource()) |
(...skipping 18 matching lines...) Expand all Loading... |
115 // the instance was destroyed. In that case the browser-side resource has | 92 // the instance was destroyed. In that case the browser-side resource has |
116 // already been freed correctly on the browser side. | 93 // already been freed correctly on the browser side. |
117 dispatcher->Send(new PpapiHostMsg_PPBCore_ReleaseResource( | 94 dispatcher->Send(new PpapiHostMsg_PPBCore_ReleaseResource( |
118 INTERFACE_ID_PPB_CORE, object->host_resource())); | 95 INTERFACE_ID_PPB_CORE, object->host_resource())); |
119 } | 96 } |
120 } | 97 } |
121 } | 98 } |
122 | 99 |
123 } // namespace proxy | 100 } // namespace proxy |
124 } // namespace ppapi | 101 } // namespace ppapi |
OLD | NEW |