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

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

Issue 6905088: New thunk system for Pepper proxy and implementation (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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) 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/plugin_resource.h" 11 #include "ppapi/proxy/plugin_resource.h"
12 #include "ppapi/proxy/serialized_var.h" 12 #include "ppapi/proxy/serialized_var.h"
13 #include "ppapi/shared_impl/tracker_base.h"
13 14
14 namespace pp { 15 namespace pp {
15 namespace proxy { 16 namespace proxy {
16 17
17 namespace { 18 namespace {
18 19
19 // When non-NULL, this object overrides the ResourceTrackerSingleton. 20 // When non-NULL, this object overrides the ResourceTrackerSingleton.
20 PluginResourceTracker* g_resource_tracker_override = NULL; 21 PluginResourceTracker* g_resource_tracker_override = NULL;
21 22
23 ::ppapi::shared_impl::TrackerBase* GetTrackerBase() {
24 return PluginResourceTracker::GetInstance();
25 }
26
22 } // namespace 27 } // namespace
23 28
24 PluginResourceTracker::ResourceInfo::ResourceInfo() : ref_count(0) { 29 PluginResourceTracker::ResourceInfo::ResourceInfo() : ref_count(0) {
25 } 30 }
26 31
27 PluginResourceTracker::ResourceInfo::ResourceInfo(int rc, 32 PluginResourceTracker::ResourceInfo::ResourceInfo(int rc,
28 linked_ptr<PluginResource> r) 33 linked_ptr<PluginResource> r)
29 : ref_count(rc), 34 : ref_count(rc),
30 resource(r) { 35 resource(r) {
31 } 36 }
32 37
33 PluginResourceTracker::ResourceInfo::ResourceInfo(const ResourceInfo& other) 38 PluginResourceTracker::ResourceInfo::ResourceInfo(const ResourceInfo& other)
34 : ref_count(other.ref_count), 39 : ref_count(other.ref_count),
35 resource(other.resource) { 40 resource(other.resource) {
41 // Wire up the new shared resource tracker base to use our implementation.
42 ::ppapi::shared_impl::TrackerBase::Init(&GetTrackerBase);
36 } 43 }
37 44
38 PluginResourceTracker::ResourceInfo::~ResourceInfo() { 45 PluginResourceTracker::ResourceInfo::~ResourceInfo() {
39 } 46 }
40 47
41 PluginResourceTracker::ResourceInfo& 48 PluginResourceTracker::ResourceInfo&
42 PluginResourceTracker::ResourceInfo::operator=( 49 PluginResourceTracker::ResourceInfo::operator=(
43 const ResourceInfo& other) { 50 const ResourceInfo& other) {
44 ref_count = other.ref_count; 51 ref_count = other.ref_count;
45 resource = other.resource; 52 resource = other.resource;
(...skipping 14 matching lines...) Expand all
60 g_resource_tracker_override = tracker; 67 g_resource_tracker_override = tracker;
61 } 68 }
62 69
63 // static 70 // static
64 PluginResourceTracker* PluginResourceTracker::GetInstance() { 71 PluginResourceTracker* PluginResourceTracker::GetInstance() {
65 if (g_resource_tracker_override) 72 if (g_resource_tracker_override)
66 return g_resource_tracker_override; 73 return g_resource_tracker_override;
67 return Singleton<PluginResourceTracker>::get(); 74 return Singleton<PluginResourceTracker>::get();
68 } 75 }
69 76
77 // static
78 ::ppapi::shared_impl::TrackerBase*
79 PluginResourceTracker::GetTrackerBaseInstance() {
80 return GetInstance();
81 }
82
70 PluginResource* PluginResourceTracker::GetResourceObject( 83 PluginResource* PluginResourceTracker::GetResourceObject(
71 PP_Resource pp_resource) { 84 PP_Resource pp_resource) {
72 ResourceMap::iterator found = resource_map_.find(pp_resource); 85 ResourceMap::iterator found = resource_map_.find(pp_resource);
73 if (found == resource_map_.end()) 86 if (found == resource_map_.end())
74 return NULL; 87 return NULL;
75 return found->second.resource.get(); 88 return found->second.resource.get();
76 } 89 }
77 90
78 PP_Resource PluginResourceTracker::AddResource( 91 PP_Resource PluginResourceTracker::AddResource(
79 linked_ptr<PluginResource> object) { 92 linked_ptr<PluginResource> object) {
(...skipping 25 matching lines...) Expand all
105 } 118 }
106 119
107 PP_Resource PluginResourceTracker::PluginResourceForHostResource( 120 PP_Resource PluginResourceTracker::PluginResourceForHostResource(
108 const HostResource& resource) const { 121 const HostResource& resource) const {
109 HostResourceMap::const_iterator found = host_resource_map_.find(resource); 122 HostResourceMap::const_iterator found = host_resource_map_.find(resource);
110 if (found == host_resource_map_.end()) 123 if (found == host_resource_map_.end())
111 return 0; 124 return 0;
112 return found->second; 125 return found->second;
113 } 126 }
114 127
128 ::ppapi::shared_impl::ResourceObjectBase* PluginResourceTracker::GetResourceAPI(
129 PP_Resource res) {
130 ResourceMap::iterator found = resource_map_.find(res);
131 if (found == resource_map_.end())
132 return NULL;
133 return found->second.resource.get();
134 }
135
136 ::ppapi::shared_impl::FunctionGroupBase* PluginResourceTracker::GetFunctionAPI(
137 PP_Instance inst,
138 pp::proxy::InterfaceID id) {
139 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(inst);
140 if (dispatcher)
141 return dispatcher->GetFunctionAPI(id);
142 return NULL;
143 }
144
115 void PluginResourceTracker::ReleasePluginResourceRef( 145 void PluginResourceTracker::ReleasePluginResourceRef(
116 const PP_Resource& resource, 146 const PP_Resource& resource,
117 bool notify_browser_on_release) { 147 bool notify_browser_on_release) {
118 ResourceMap::iterator found = resource_map_.find(resource); 148 ResourceMap::iterator found = resource_map_.find(resource);
119 if (found == resource_map_.end()) 149 if (found == resource_map_.end())
120 return; 150 return;
121 found->second.ref_count--; 151 found->second.ref_count--;
122 if (found->second.ref_count == 0) { 152 if (found->second.ref_count == 0) {
123 // Keep a reference while removing in case the destructor ends up 153 // Keep a reference while removing in case the destructor ends up
124 // re-entering. That way, when the destructor is called, it's out of the 154 // re-entering. That way, when the destructor is called, it's out of the
(...skipping 12 matching lines...) Expand all
137 INTERFACE_ID_PPB_CORE, host_resource)); 167 INTERFACE_ID_PPB_CORE, host_resource));
138 } else { 168 } else {
139 NOTREACHED(); 169 NOTREACHED();
140 } 170 }
141 } 171 }
142 } 172 }
143 } 173 }
144 174
145 } // namespace proxy 175 } // namespace proxy
146 } // namespace pp 176 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698