OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ppapi/proxy/plugin_resource_tracker.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "ppapi/proxy/plugin_dispatcher.h" |
| 9 #include "ppapi/proxy/ppapi_messages.h" |
| 10 #include "ppapi/proxy/plugin_resource.h" |
| 11 #include "ppapi/proxy/serialized_var.h" |
| 12 |
| 13 namespace pp { |
| 14 namespace proxy { |
| 15 |
| 16 PluginResourceTracker::ResourceInfo::ResourceInfo() : ref_count(0) { |
| 17 } |
| 18 |
| 19 PluginResourceTracker::ResourceInfo::ResourceInfo(int rc, |
| 20 linked_ptr<PluginResource> r) |
| 21 : ref_count(rc), |
| 22 resource(r) { |
| 23 } |
| 24 |
| 25 PluginResourceTracker::ResourceInfo::ResourceInfo(const ResourceInfo& other) |
| 26 : ref_count(other.ref_count), |
| 27 resource(other.resource) { |
| 28 } |
| 29 |
| 30 PluginResourceTracker::ResourceInfo::~ResourceInfo() { |
| 31 } |
| 32 |
| 33 PluginResourceTracker::ResourceInfo& |
| 34 PluginResourceTracker::ResourceInfo::operator=( |
| 35 const ResourceInfo& other) { |
| 36 ref_count = other.ref_count; |
| 37 resource = other.resource; |
| 38 return *this; |
| 39 } |
| 40 |
| 41 PluginResourceTracker::PluginResourceTracker(PluginDispatcher* dispatcher) |
| 42 : dispatcher_(dispatcher) { |
| 43 } |
| 44 |
| 45 PluginResourceTracker::~PluginResourceTracker() { |
| 46 } |
| 47 |
| 48 PluginResource* PluginResourceTracker::GetResourceObject( |
| 49 PP_Resource pp_resource) { |
| 50 ResourceMap::iterator found = resource_map_.find(pp_resource); |
| 51 if (found == resource_map_.end()) |
| 52 return NULL; |
| 53 return found->second.resource.get(); |
| 54 } |
| 55 |
| 56 void PluginResourceTracker::AddResource(PP_Resource pp_resource, |
| 57 linked_ptr<PluginResource> object) { |
| 58 DCHECK(resource_map_.find(pp_resource) == resource_map_.end()); |
| 59 resource_map_[pp_resource] = ResourceInfo(1, object); |
| 60 } |
| 61 |
| 62 void PluginResourceTracker::AddRefResource(PP_Resource resource) { |
| 63 resource_map_[resource].ref_count++; |
| 64 } |
| 65 |
| 66 void PluginResourceTracker::ReleaseResource(PP_Resource resource) { |
| 67 ReleasePluginResourceRef(resource, true); |
| 68 } |
| 69 |
| 70 void PluginResourceTracker::ReleasePluginResourceRef( |
| 71 const PP_Resource& resource, |
| 72 bool notify_browser_on_release) { |
| 73 ResourceMap::iterator found = resource_map_.find(resource); |
| 74 if (found == resource_map_.end()) |
| 75 return; |
| 76 found->second.ref_count--; |
| 77 if (found->second.ref_count == 0) { |
| 78 if (notify_browser_on_release) { |
| 79 dispatcher_->Send(new PpapiHostMsg_PPBCore_ReleaseResource( |
| 80 INTERFACE_ID_PPB_CORE, resource)); |
| 81 } |
| 82 resource_map_.erase(found); |
| 83 } |
| 84 } |
| 85 |
| 86 } // namespace proxy |
| 87 } // namespace pp |
OLD | NEW |