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

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

Issue 12920003: Revert 189518 "PPAPI: Remove threading options; it's always on" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 9 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/singleton.h" 8 #include "base/memory/singleton.h"
9 #include "ppapi/c/dev/ppp_class_deprecated.h" 9 #include "ppapi/c/dev/ppp_class_deprecated.h"
10 #include "ppapi/c/ppb_var.h" 10 #include "ppapi/c/ppb_var.h"
(...skipping 13 matching lines...) Expand all
24 } 24 }
25 25
26 bool PluginVarTracker::HostVar::operator<(const HostVar& other) const { 26 bool PluginVarTracker::HostVar::operator<(const HostVar& other) const {
27 if (dispatcher < other.dispatcher) 27 if (dispatcher < other.dispatcher)
28 return true; 28 return true;
29 if (other.dispatcher < dispatcher) 29 if (other.dispatcher < dispatcher)
30 return false; 30 return false;
31 return host_object_id < other.host_object_id; 31 return host_object_id < other.host_object_id;
32 } 32 }
33 33
34 PluginVarTracker::PluginVarTracker() : VarTracker(THREAD_SAFE) { 34 PluginVarTracker::PluginVarTracker() {
35 } 35 }
36 36
37 PluginVarTracker::~PluginVarTracker() { 37 PluginVarTracker::~PluginVarTracker() {
38 } 38 }
39 39
40 PP_Var PluginVarTracker::ReceiveObjectPassRef(const PP_Var& host_var, 40 PP_Var PluginVarTracker::ReceiveObjectPassRef(const PP_Var& host_var,
41 PluginDispatcher* dispatcher) { 41 PluginDispatcher* dispatcher) {
42 CheckThreadingPreconditions(); 42 DCHECK(CalledOnValidThread());
43 DCHECK(host_var.type == PP_VARTYPE_OBJECT); 43 DCHECK(host_var.type == PP_VARTYPE_OBJECT);
44 44
45 // Get the object. 45 // Get the object.
46 scoped_refptr<ProxyObjectVar> object( 46 scoped_refptr<ProxyObjectVar> object(
47 FindOrMakePluginVarFromHostVar(host_var, dispatcher)); 47 FindOrMakePluginVarFromHostVar(host_var, dispatcher));
48 48
49 // Actually create the PP_Var, this will add all the tracking info but not 49 // Actually create the PP_Var, this will add all the tracking info but not
50 // adjust any refcounts. 50 // adjust any refcounts.
51 PP_Var ret = GetOrCreateObjectVarID(object.get()); 51 PP_Var ret = GetOrCreateObjectVarID(object.get());
52 52
53 VarInfo& info = GetLiveVar(ret)->second; 53 VarInfo& info = GetLiveVar(ret)->second;
54 if (info.ref_count > 0) { 54 if (info.ref_count > 0) {
55 // We already had a reference to it before. That means the renderer now has 55 // We already had a reference to it before. That means the renderer now has
56 // two references on our behalf. We want to transfer that extra reference 56 // two references on our behalf. We want to transfer that extra reference
57 // to our list. This means we addref in the plugin, and release the extra 57 // to our list. This means we addref in the plugin, and release the extra
58 // one in the renderer. 58 // one in the renderer.
59 SendReleaseObjectMsg(*object); 59 SendReleaseObjectMsg(*object);
60 } 60 }
61 info.ref_count++; 61 info.ref_count++;
62 return ret; 62 return ret;
63 } 63 }
64 64
65 PP_Var PluginVarTracker::TrackObjectWithNoReference( 65 PP_Var PluginVarTracker::TrackObjectWithNoReference(
66 const PP_Var& host_var, 66 const PP_Var& host_var,
67 PluginDispatcher* dispatcher) { 67 PluginDispatcher* dispatcher) {
68 CheckThreadingPreconditions(); 68 DCHECK(CalledOnValidThread());
69 DCHECK(host_var.type == PP_VARTYPE_OBJECT); 69 DCHECK(host_var.type == PP_VARTYPE_OBJECT);
70 70
71 // Get the object. 71 // Get the object.
72 scoped_refptr<ProxyObjectVar> object( 72 scoped_refptr<ProxyObjectVar> object(
73 FindOrMakePluginVarFromHostVar(host_var, dispatcher)); 73 FindOrMakePluginVarFromHostVar(host_var, dispatcher));
74 74
75 // Actually create the PP_Var, this will add all the tracking info but not 75 // Actually create the PP_Var, this will add all the tracking info but not
76 // adjust any refcounts. 76 // adjust any refcounts.
77 PP_Var ret = GetOrCreateObjectVarID(object.get()); 77 PP_Var ret = GetOrCreateObjectVarID(object.get());
78 78
79 VarInfo& info = GetLiveVar(ret)->second; 79 VarInfo& info = GetLiveVar(ret)->second;
80 info.track_with_no_reference_count++; 80 info.track_with_no_reference_count++;
81 return ret; 81 return ret;
82 } 82 }
83 83
84 void PluginVarTracker::StopTrackingObjectWithNoReference( 84 void PluginVarTracker::StopTrackingObjectWithNoReference(
85 const PP_Var& plugin_var) { 85 const PP_Var& plugin_var) {
86 CheckThreadingPreconditions(); 86 DCHECK(CalledOnValidThread());
87 DCHECK(plugin_var.type == PP_VARTYPE_OBJECT); 87 DCHECK(plugin_var.type == PP_VARTYPE_OBJECT);
88 88
89 VarMap::iterator found = GetLiveVar(plugin_var); 89 VarMap::iterator found = GetLiveVar(plugin_var);
90 if (found == live_vars_.end()) { 90 if (found == live_vars_.end()) {
91 NOTREACHED(); 91 NOTREACHED();
92 return; 92 return;
93 } 93 }
94 94
95 DCHECK(found->second.track_with_no_reference_count > 0); 95 DCHECK(found->second.track_with_no_reference_count > 0);
96 found->second.track_with_no_reference_count--; 96 found->second.track_with_no_reference_count--;
97 DeleteObjectInfoIfNecessary(found); 97 DeleteObjectInfoIfNecessary(found);
98 } 98 }
99 99
100 PP_Var PluginVarTracker::GetHostObject(const PP_Var& plugin_object) const { 100 PP_Var PluginVarTracker::GetHostObject(const PP_Var& plugin_object) const {
101 CheckThreadingPreconditions(); 101 DCHECK(CalledOnValidThread());
102
102 if (plugin_object.type != PP_VARTYPE_OBJECT) { 103 if (plugin_object.type != PP_VARTYPE_OBJECT) {
103 NOTREACHED(); 104 NOTREACHED();
104 return PP_MakeUndefined(); 105 return PP_MakeUndefined();
105 } 106 }
106 107
107 Var* var = GetVar(plugin_object); 108 Var* var = GetVar(plugin_object);
108 ProxyObjectVar* object = var->AsProxyObjectVar(); 109 ProxyObjectVar* object = var->AsProxyObjectVar();
109 if (!object) { 110 if (!object) {
110 NOTREACHED(); 111 NOTREACHED();
111 return PP_MakeUndefined(); 112 return PP_MakeUndefined();
112 } 113 }
113 114
114 // Make a var with the host ID. 115 // Make a var with the host ID.
115 PP_Var ret = { PP_VARTYPE_OBJECT }; 116 PP_Var ret = { PP_VARTYPE_OBJECT };
116 ret.value.as_id = object->host_var_id(); 117 ret.value.as_id = object->host_var_id();
117 return ret; 118 return ret;
118 } 119 }
119 120
120 PluginDispatcher* PluginVarTracker::DispatcherForPluginObject( 121 PluginDispatcher* PluginVarTracker::DispatcherForPluginObject(
121 const PP_Var& plugin_object) const { 122 const PP_Var& plugin_object) const {
122 CheckThreadingPreconditions(); 123 DCHECK(CalledOnValidThread());
124
123 if (plugin_object.type != PP_VARTYPE_OBJECT) 125 if (plugin_object.type != PP_VARTYPE_OBJECT)
124 return NULL; 126 return NULL;
125 127
126 VarMap::const_iterator found = GetLiveVar(plugin_object); 128 VarMap::const_iterator found = GetLiveVar(plugin_object);
127 if (found == live_vars_.end()) 129 if (found == live_vars_.end())
128 return NULL; 130 return NULL;
129 131
130 ProxyObjectVar* object = found->second.var->AsProxyObjectVar(); 132 ProxyObjectVar* object = found->second.var->AsProxyObjectVar();
131 if (!object) 133 if (!object)
132 return NULL; 134 return NULL;
133 return object->dispatcher(); 135 return object->dispatcher();
134 } 136 }
135 137
136 void PluginVarTracker::ReleaseHostObject(PluginDispatcher* dispatcher, 138 void PluginVarTracker::ReleaseHostObject(PluginDispatcher* dispatcher,
137 const PP_Var& host_object) { 139 const PP_Var& host_object) {
138 CheckThreadingPreconditions(); 140 DCHECK(CalledOnValidThread());
139 DCHECK(host_object.type == PP_VARTYPE_OBJECT); 141 DCHECK(host_object.type == PP_VARTYPE_OBJECT);
140 142
141 // Convert the host object to a normal var valid in the plugin. 143 // Convert the host object to a normal var valid in the plugin.
142 HostVarToPluginVarMap::iterator found = host_var_to_plugin_var_.find( 144 HostVarToPluginVarMap::iterator found = host_var_to_plugin_var_.find(
143 HostVar(dispatcher, static_cast<int32>(host_object.value.as_id))); 145 HostVar(dispatcher, static_cast<int32>(host_object.value.as_id)));
144 if (found == host_var_to_plugin_var_.end()) { 146 if (found == host_var_to_plugin_var_.end()) {
145 NOTREACHED(); 147 NOTREACHED();
146 return; 148 return;
147 } 149 }
148 150
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 int id, 386 int id,
385 PP_Instance instance, 387 PP_Instance instance,
386 base::SharedMemoryHandle* handle, 388 base::SharedMemoryHandle* handle,
387 uint32* size_in_bytes) { 389 uint32* size_in_bytes) {
388 NOTREACHED(); 390 NOTREACHED();
389 return false; 391 return false;
390 } 392 }
391 393
392 } // namesace proxy 394 } // namesace proxy
393 } // namespace ppapi 395 } // namespace ppapi
OLDNEW
« no previous file with comments | « trunk/src/ppapi/proxy/plugin_resource_tracker_unittest.cc ('k') | trunk/src/ppapi/proxy/ppapi_proxy_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698