| 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/ppapi_messages.h" | 10 #include "ppapi/proxy/ppapi_messages.h" |
| 11 #include "ppapi/proxy/serialized_var.h" | 11 #include "ppapi/proxy/serialized_var.h" |
| 12 #include "ppapi/shared_impl/resource.h" | 12 #include "ppapi/shared_impl/resource.h" |
| 13 #include "ppapi/shared_impl/tracker_base.h" | 13 #include "ppapi/shared_impl/tracker_base.h" |
| 14 #include "ppapi/shared_impl/var.h" | 14 #include "ppapi/shared_impl/var.h" |
| 15 | 15 |
| 16 using ppapi::HostResource; | 16 namespace ppapi { |
| 17 using ppapi::Resource; | |
| 18 | |
| 19 namespace pp { | |
| 20 namespace proxy { | 17 namespace proxy { |
| 21 | 18 |
| 22 namespace { | 19 namespace { |
| 23 | 20 |
| 24 // When non-NULL, this object overrides the ResourceTrackerSingleton. | 21 // When non-NULL, this object overrides the ResourceTrackerSingleton. |
| 25 PluginResourceTracker* g_resource_tracker_override = NULL; | 22 PluginResourceTracker* g_resource_tracker_override = NULL; |
| 26 | 23 |
| 27 ::ppapi::TrackerBase* GetTrackerBase() { | 24 TrackerBase* GetTrackerBase() { |
| 28 return PluginResourceTracker::GetInstance(); | 25 return PluginResourceTracker::GetInstance(); |
| 29 } | 26 } |
| 30 | 27 |
| 31 } // namespace | 28 } // namespace |
| 32 | 29 |
| 33 PluginResourceTracker::PluginResourceTracker() | 30 PluginResourceTracker::PluginResourceTracker() |
| 34 : var_tracker_test_override_(NULL) { | 31 : var_tracker_test_override_(NULL) { |
| 35 } | 32 } |
| 36 | 33 |
| 37 PluginResourceTracker::~PluginResourceTracker() { | 34 PluginResourceTracker::~PluginResourceTracker() { |
| 38 } | 35 } |
| 39 | 36 |
| 40 // static | 37 // static |
| 41 void PluginResourceTracker::SetInstanceForTest(PluginResourceTracker* tracker) { | 38 void PluginResourceTracker::SetInstanceForTest(PluginResourceTracker* tracker) { |
| 42 g_resource_tracker_override = tracker; | 39 g_resource_tracker_override = tracker; |
| 43 } | 40 } |
| 44 | 41 |
| 45 // static | 42 // static |
| 46 PluginResourceTracker* PluginResourceTracker::GetInstance() { | 43 PluginResourceTracker* PluginResourceTracker::GetInstance() { |
| 47 if (g_resource_tracker_override) | 44 if (g_resource_tracker_override) |
| 48 return g_resource_tracker_override; | 45 return g_resource_tracker_override; |
| 49 return Singleton<PluginResourceTracker>::get(); | 46 return Singleton<PluginResourceTracker>::get(); |
| 50 } | 47 } |
| 51 | 48 |
| 52 // static | 49 // static |
| 53 ::ppapi::TrackerBase* | 50 TrackerBase* PluginResourceTracker::GetTrackerBaseInstance() { |
| 54 PluginResourceTracker::GetTrackerBaseInstance() { | |
| 55 return GetInstance(); | 51 return GetInstance(); |
| 56 } | 52 } |
| 57 | 53 |
| 58 PP_Resource PluginResourceTracker::PluginResourceForHostResource( | 54 PP_Resource PluginResourceTracker::PluginResourceForHostResource( |
| 59 const HostResource& resource) const { | 55 const HostResource& resource) const { |
| 60 HostResourceMap::const_iterator found = host_resource_map_.find(resource); | 56 HostResourceMap::const_iterator found = host_resource_map_.find(resource); |
| 61 if (found == host_resource_map_.end()) | 57 if (found == host_resource_map_.end()) |
| 62 return 0; | 58 return 0; |
| 63 return found->second; | 59 return found->second; |
| 64 } | 60 } |
| 65 | 61 |
| 66 ::ppapi::FunctionGroupBase* PluginResourceTracker::GetFunctionAPI( | 62 FunctionGroupBase* PluginResourceTracker::GetFunctionAPI(PP_Instance inst, |
| 67 PP_Instance inst, | 63 InterfaceID id) { |
| 68 pp::proxy::InterfaceID id) { | |
| 69 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(inst); | 64 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(inst); |
| 70 if (dispatcher) | 65 if (dispatcher) |
| 71 return dispatcher->GetFunctionAPI(id); | 66 return dispatcher->GetFunctionAPI(id); |
| 72 return NULL; | 67 return NULL; |
| 73 } | 68 } |
| 74 | 69 |
| 75 ppapi::VarTracker* PluginResourceTracker::GetVarTracker() { | 70 VarTracker* PluginResourceTracker::GetVarTracker() { |
| 76 return &var_tracker(); | 71 return &var_tracker(); |
| 77 } | 72 } |
| 78 | 73 |
| 79 ppapi::ResourceTracker* PluginResourceTracker::GetResourceTracker() { | 74 ResourceTracker* PluginResourceTracker::GetResourceTracker() { |
| 80 return this; | 75 return this; |
| 81 } | 76 } |
| 82 | 77 |
| 83 PP_Resource PluginResourceTracker::AddResource(Resource* object) { | 78 PP_Resource PluginResourceTracker::AddResource(Resource* object) { |
| 84 PP_Resource ret = ResourceTracker::AddResource(object); | 79 PP_Resource ret = ResourceTracker::AddResource(object); |
| 85 | 80 |
| 86 // Some resources are plugin-only, so they don't have a host resource. | 81 // Some resources are plugin-only, so they don't have a host resource. |
| 87 if (object->host_resource().host_resource()) | 82 if (object->host_resource().host_resource()) |
| 88 host_resource_map_.insert(std::make_pair(object->host_resource(), ret)); | 83 host_resource_map_.insert(std::make_pair(object->host_resource(), ret)); |
| 89 return ret; | 84 return ret; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 105 // The dispatcher can be NULL if the plugin held on to a resource after | 100 // The dispatcher can be NULL if the plugin held on to a resource after |
| 106 // the instance was destroyed. In that case the browser-side resource has | 101 // the instance was destroyed. In that case the browser-side resource has |
| 107 // already been freed correctly on the browser side. | 102 // already been freed correctly on the browser side. |
| 108 dispatcher->Send(new PpapiHostMsg_PPBCore_ReleaseResource( | 103 dispatcher->Send(new PpapiHostMsg_PPBCore_ReleaseResource( |
| 109 INTERFACE_ID_PPB_CORE, object->host_resource())); | 104 INTERFACE_ID_PPB_CORE, object->host_resource())); |
| 110 } | 105 } |
| 111 } | 106 } |
| 112 } | 107 } |
| 113 | 108 |
| 114 } // namespace proxy | 109 } // namespace proxy |
| 115 } // namespace pp | 110 } // namespace ppapi |
| OLD | NEW |