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

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

Issue 6334016: Refactor PPAPI proxy resource handling to maintain which host they came from,... (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
« no previous file with comments | « ppapi/proxy/plugin_var_tracker.h ('k') | ppapi/proxy/plugin_var_tracker_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_var_tracker.h" 5 #include "ppapi/proxy/plugin_var_tracker.h"
6 6
7 #include "base/ref_counted.h" 7 #include "base/ref_counted.h"
8 #include "base/singleton.h" 8 #include "base/singleton.h"
9 #include "ppapi/c/ppb_var.h" 9 #include "ppapi/c/ppb_var.h"
10 #include "ppapi/proxy/ppapi_messages.h" 10 #include "ppapi/proxy/ppapi_messages.h"
11 #include "ppapi/proxy/interface_id.h" 11 #include "ppapi/proxy/interface_id.h"
12 12
13 namespace pp { 13 namespace pp {
14 namespace proxy { 14 namespace proxy {
15 15
16 namespace { 16 namespace {
17 17
18 // When non-NULL, this object overrides the VarTrackerSingleton.
19 PluginVarTracker* var_tracker_override = NULL;
20
18 class RefCountedString : public base::RefCounted<RefCountedString> { 21 class RefCountedString : public base::RefCounted<RefCountedString> {
19 public: 22 public:
20 RefCountedString() { 23 RefCountedString() {
21 } 24 }
22 RefCountedString(const std::string& str) : value_(str) { 25 RefCountedString(const std::string& str) : value_(str) {
23 } 26 }
24 RefCountedString(const char* data, size_t len) 27 RefCountedString(const char* data, size_t len)
25 : value_(data, len) { 28 : value_(data, len) {
26 } 29 }
27 30
(...skipping 29 matching lines...) Expand all
57 ref_count(0), 60 ref_count(0),
58 track_with_no_reference_count(0) { 61 track_with_no_reference_count(0) {
59 } 62 }
60 63
61 PluginVarTracker::PluginVarTracker() : last_plugin_object_id_(0) { 64 PluginVarTracker::PluginVarTracker() : last_plugin_object_id_(0) {
62 } 65 }
63 66
64 PluginVarTracker::~PluginVarTracker() { 67 PluginVarTracker::~PluginVarTracker() {
65 } 68 }
66 69
70 // static
71 void PluginVarTracker::SetInstanceForTest(PluginVarTracker* tracker) {
72 var_tracker_override = tracker;
73 }
74
75 // static
67 PluginVarTracker* PluginVarTracker::GetInstance() { 76 PluginVarTracker* PluginVarTracker::GetInstance() {
77 if (var_tracker_override)
78 return var_tracker_override;
68 return Singleton<PluginVarTracker>::get(); 79 return Singleton<PluginVarTracker>::get();
69 } 80 }
70 81
71 PluginVarTracker::VarID PluginVarTracker::MakeString(const std::string& str) { 82 PluginVarTracker::VarID PluginVarTracker::MakeString(const std::string& str) {
72 RefCountedString* out = new RefCountedString(str); 83 RefCountedString* out = new RefCountedString(str);
73 out->AddRef(); 84 out->AddRef();
74 return static_cast<VarID>(reinterpret_cast<intptr_t>(out)); 85 return static_cast<VarID>(reinterpret_cast<intptr_t>(out));
75 } 86 }
76 87
77 PluginVarTracker::VarID PluginVarTracker::MakeString(const char* str, 88 PluginVarTracker::VarID PluginVarTracker::MakeString(const char* str,
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 if (found == plugin_var_info_.end()) { 225 if (found == plugin_var_info_.end()) {
215 NOTREACHED(); 226 NOTREACHED();
216 return PP_MakeUndefined(); 227 return PP_MakeUndefined();
217 } 228 }
218 PP_Var ret; 229 PP_Var ret;
219 ret.type = PP_VARTYPE_OBJECT; 230 ret.type = PP_VARTYPE_OBJECT;
220 ret.value.as_id = found->second.host_var.host_object_id; 231 ret.value.as_id = found->second.host_var.host_object_id;
221 return ret; 232 return ret;
222 } 233 }
223 234
235 void PluginVarTracker::ReleaseHostObject(Sender* sender,
236 const PP_Var& host_object) {
237 // Convert the host object to a normal var valid in the plugin.
238 DCHECK(host_object.type == PP_VARTYPE_OBJECT);
239 HostVarToPluginVarMap::iterator found = host_var_to_plugin_var_.find(
240 HostVar(sender, host_object.value.as_id));
241 if (found == host_var_to_plugin_var_.end()) {
242 NOTREACHED();
243 return;
244 }
245
246 // Now just release the object like normal.
247 PP_Var plugin_object;
248 plugin_object.type = PP_VARTYPE_OBJECT;
249 plugin_object.value.as_id = found->second;
250 Release(plugin_object);
251 }
252
224 int PluginVarTracker::GetRefCountForObject(const PP_Var& plugin_object) { 253 int PluginVarTracker::GetRefCountForObject(const PP_Var& plugin_object) {
225 PluginVarInfoMap::iterator found = plugin_var_info_.find( 254 PluginVarInfoMap::iterator found = plugin_var_info_.find(
226 plugin_object.value.as_id); 255 plugin_object.value.as_id);
227 if (found == plugin_var_info_.end()) 256 if (found == plugin_var_info_.end())
228 return -1; 257 return -1;
229 return found->second.ref_count; 258 return found->second.ref_count;
230 } 259 }
231 260
232 int PluginVarTracker::GetTrackedWithNoReferenceCountForObject( 261 int PluginVarTracker::GetTrackedWithNoReferenceCountForObject(
233 const PP_Var& plugin_object) { 262 const PP_Var& plugin_object) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 306
278 // Object ref counts are all zero, delete from both maps. 307 // Object ref counts are all zero, delete from both maps.
279 DCHECK(host_var_to_plugin_var_.find(iter->second.host_var) != 308 DCHECK(host_var_to_plugin_var_.find(iter->second.host_var) !=
280 host_var_to_plugin_var_.end()); 309 host_var_to_plugin_var_.end());
281 host_var_to_plugin_var_.erase(iter->second.host_var); 310 host_var_to_plugin_var_.erase(iter->second.host_var);
282 plugin_var_info_.erase(iter); 311 plugin_var_info_.erase(iter);
283 } 312 }
284 313
285 } // namesace proxy 314 } // namesace proxy
286 } // namespace pp 315 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/proxy/plugin_var_tracker.h ('k') | ppapi/proxy/plugin_var_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698