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