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

Side by Side Diff: ppapi/proxy/plugin_resource_tracker.cc

Issue 6282007: First pass at making the proxy handle multiple renderers. This associates the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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/singleton.h"
8 #include "ppapi/proxy/plugin_dispatcher.h" 9 #include "ppapi/proxy/plugin_dispatcher.h"
9 #include "ppapi/proxy/ppapi_messages.h" 10 #include "ppapi/proxy/ppapi_messages.h"
10 #include "ppapi/proxy/plugin_resource.h" 11 #include "ppapi/proxy/plugin_resource.h"
11 #include "ppapi/proxy/serialized_var.h" 12 #include "ppapi/proxy/serialized_var.h"
12 13
13 namespace pp { 14 namespace pp {
14 namespace proxy { 15 namespace proxy {
15 16
16 PluginResourceTracker::ResourceInfo::ResourceInfo() : ref_count(0) { 17 PluginResourceTracker::ResourceInfo::ResourceInfo() : ref_count(0) {
17 } 18 }
(...skipping 13 matching lines...) Expand all
31 } 32 }
32 33
33 PluginResourceTracker::ResourceInfo& 34 PluginResourceTracker::ResourceInfo&
34 PluginResourceTracker::ResourceInfo::operator=( 35 PluginResourceTracker::ResourceInfo::operator=(
35 const ResourceInfo& other) { 36 const ResourceInfo& other) {
36 ref_count = other.ref_count; 37 ref_count = other.ref_count;
37 resource = other.resource; 38 resource = other.resource;
38 return *this; 39 return *this;
39 } 40 }
40 41
41 PluginResourceTracker::PluginResourceTracker(PluginDispatcher* dispatcher) 42 PluginResourceTracker::PluginResourceTracker() {
42 : dispatcher_(dispatcher) {
43 } 43 }
44 44
45 PluginResourceTracker::~PluginResourceTracker() { 45 PluginResourceTracker::~PluginResourceTracker() {
46 } 46 }
47 47
48 // static
49 PluginResourceTracker* PluginResourceTracker::GetInstance() {
50 return Singleton<PluginResourceTracker>::get();
51 }
52
48 PluginResource* PluginResourceTracker::GetResourceObject( 53 PluginResource* PluginResourceTracker::GetResourceObject(
49 PP_Resource pp_resource) { 54 PP_Resource pp_resource) {
50 ResourceMap::iterator found = resource_map_.find(pp_resource); 55 ResourceMap::iterator found = resource_map_.find(pp_resource);
51 if (found == resource_map_.end()) 56 if (found == resource_map_.end())
52 return NULL; 57 return NULL;
53 return found->second.resource.get(); 58 return found->second.resource.get();
54 } 59 }
55 60
56 void PluginResourceTracker::AddResource(PP_Resource pp_resource, 61 void PluginResourceTracker::AddResource(PP_Resource pp_resource,
57 linked_ptr<PluginResource> object) { 62 linked_ptr<PluginResource> object) {
(...skipping 16 matching lines...) Expand all
74 return false; // We've not seen this resource before. 79 return false; // We've not seen this resource before.
75 80
76 // We have already seen this resource and the caller wants the plugin to 81 // We have already seen this resource and the caller wants the plugin to
77 // have one more ref to the object (this function is called when retuning 82 // have one more ref to the object (this function is called when retuning
78 // a resource). 83 // a resource).
79 // 84 //
80 // This is like the PluginVarTracker::ReceiveObjectPassRef. We do an AddRef 85 // This is like the PluginVarTracker::ReceiveObjectPassRef. We do an AddRef
81 // in the plugin for the additional ref, and then a Release in the renderer 86 // in the plugin for the additional ref, and then a Release in the renderer
82 // because the code in the renderer addrefed on behalf of the caller. 87 // because the code in the renderer addrefed on behalf of the caller.
83 found->second.ref_count++; 88 found->second.ref_count++;
84 dispatcher_->Send(new PpapiHostMsg_PPBCore_ReleaseResource( 89
85 INTERFACE_ID_PPB_CORE, resource)); 90 SendReleaseResourceToHost(resource, found->second.resource.get());
86 return true; 91 return true;
87 } 92 }
88 93
89 void PluginResourceTracker::ReleasePluginResourceRef( 94 void PluginResourceTracker::ReleasePluginResourceRef(
90 const PP_Resource& resource, 95 const PP_Resource& resource,
91 bool notify_browser_on_release) { 96 bool notify_browser_on_release) {
92 ResourceMap::iterator found = resource_map_.find(resource); 97 ResourceMap::iterator found = resource_map_.find(resource);
93 if (found == resource_map_.end()) 98 if (found == resource_map_.end())
94 return; 99 return;
95 found->second.ref_count--; 100 found->second.ref_count--;
96 if (found->second.ref_count == 0) { 101 if (found->second.ref_count == 0) {
97 if (notify_browser_on_release) { 102 if (notify_browser_on_release)
98 dispatcher_->Send(new PpapiHostMsg_PPBCore_ReleaseResource( 103 SendReleaseResourceToHost(resource, found->second.resource.get());
99 INTERFACE_ID_PPB_CORE, resource));
100 }
101 resource_map_.erase(found); 104 resource_map_.erase(found);
102 } 105 }
103 } 106 }
104 107
108 void PluginResourceTracker::SendReleaseResourceToHost(
109 PP_Resource resource_id,
110 PluginResource* resource) {
111 PluginDispatcher* dispatcher =
112 PluginDispatcher::GetForInstance(resource->instance());
113 if (dispatcher) {
114 dispatcher->Send(new PpapiHostMsg_PPBCore_ReleaseResource(
115 INTERFACE_ID_PPB_CORE, resource_id));
116 } else {
117 NOTREACHED();
118 }
119 }
120
105 } // namespace proxy 121 } // namespace proxy
106 } // namespace pp 122 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698