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

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

Issue 10069032: PPAPI: Compile out thread checks when pepper threading is turned on. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 | « no previous file | ppapi/shared_impl/var_tracker.h » ('j') | ppapi/shared_impl/var_tracker.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ppb_var.h" 9 #include "ppapi/c/ppb_var.h"
10 #include "ppapi/proxy/plugin_array_buffer_var.h" 10 #include "ppapi/proxy/plugin_array_buffer_var.h"
11 #include "ppapi/proxy/plugin_dispatcher.h" 11 #include "ppapi/proxy/plugin_dispatcher.h"
12 #include "ppapi/proxy/ppapi_messages.h" 12 #include "ppapi/proxy/ppapi_messages.h"
13 #include "ppapi/proxy/proxy_object_var.h" 13 #include "ppapi/proxy/proxy_object_var.h"
14 #include "ppapi/shared_impl/api_id.h" 14 #include "ppapi/shared_impl/api_id.h"
15 #include "ppapi/shared_impl/var.h" 15 #include "ppapi/shared_impl/var.h"
16 16
17 #ifdef ENABLE_PEPPER_THREADING
18 #define CHECK_VALID_THREAD() do {} while(false)
19 #else
20 #define CHECK_VALID_THREAD() do { CalledOnValidThread(); } while(false)
yzshen1 2012/04/12 22:21:23 - We need to DCHECK the result of CalledOnValidThr
21 #endif
22
17 namespace ppapi { 23 namespace ppapi {
18 namespace proxy { 24 namespace proxy {
19 25
20 PluginVarTracker::HostVar::HostVar(PluginDispatcher* d, int32 i) 26 PluginVarTracker::HostVar::HostVar(PluginDispatcher* d, int32 i)
21 : dispatcher(d), 27 : dispatcher(d),
22 host_object_id(i) { 28 host_object_id(i) {
23 } 29 }
24 30
25 bool PluginVarTracker::HostVar::operator<(const HostVar& other) const { 31 bool PluginVarTracker::HostVar::operator<(const HostVar& other) const {
26 if (dispatcher < other.dispatcher) 32 if (dispatcher < other.dispatcher)
27 return true; 33 return true;
28 if (other.dispatcher < dispatcher) 34 if (other.dispatcher < dispatcher)
29 return false; 35 return false;
30 return host_object_id < other.host_object_id; 36 return host_object_id < other.host_object_id;
31 } 37 }
32 38
33 PluginVarTracker::PluginVarTracker() { 39 PluginVarTracker::PluginVarTracker() {
34 } 40 }
35 41
36 PluginVarTracker::~PluginVarTracker() { 42 PluginVarTracker::~PluginVarTracker() {
37 } 43 }
38 44
39 PP_Var PluginVarTracker::ReceiveObjectPassRef(const PP_Var& host_var, 45 PP_Var PluginVarTracker::ReceiveObjectPassRef(const PP_Var& host_var,
40 PluginDispatcher* dispatcher) { 46 PluginDispatcher* dispatcher) {
41 DCHECK(CalledOnValidThread()); 47 CHECK_VALID_THREAD();
42 DCHECK(host_var.type == PP_VARTYPE_OBJECT); 48 DCHECK(host_var.type == PP_VARTYPE_OBJECT);
43 49
44 // Get the object. 50 // Get the object.
45 scoped_refptr<ProxyObjectVar> object( 51 scoped_refptr<ProxyObjectVar> object(
46 FindOrMakePluginVarFromHostVar(host_var, dispatcher)); 52 FindOrMakePluginVarFromHostVar(host_var, dispatcher));
47 53
48 // Actually create the PP_Var, this will add all the tracking info but not 54 // Actually create the PP_Var, this will add all the tracking info but not
49 // adjust any refcounts. 55 // adjust any refcounts.
50 PP_Var ret = GetOrCreateObjectVarID(object.get()); 56 PP_Var ret = GetOrCreateObjectVarID(object.get());
51 57
52 VarInfo& info = GetLiveVar(ret)->second; 58 VarInfo& info = GetLiveVar(ret)->second;
53 if (info.ref_count > 0) { 59 if (info.ref_count > 0) {
54 // We already had a reference to it before. That means the renderer now has 60 // We already had a reference to it before. That means the renderer now has
55 // two references on our behalf. We want to transfer that extra reference 61 // two references on our behalf. We want to transfer that extra reference
56 // to our list. This means we addref in the plugin, and release the extra 62 // to our list. This means we addref in the plugin, and release the extra
57 // one in the renderer. 63 // one in the renderer.
58 SendReleaseObjectMsg(*object); 64 SendReleaseObjectMsg(*object);
59 } 65 }
60 info.ref_count++; 66 info.ref_count++;
61 return ret; 67 return ret;
62 } 68 }
63 69
64 PP_Var PluginVarTracker::TrackObjectWithNoReference( 70 PP_Var PluginVarTracker::TrackObjectWithNoReference(
65 const PP_Var& host_var, 71 const PP_Var& host_var,
66 PluginDispatcher* dispatcher) { 72 PluginDispatcher* dispatcher) {
67 DCHECK(CalledOnValidThread()); 73 CHECK_VALID_THREAD();
68 DCHECK(host_var.type == PP_VARTYPE_OBJECT); 74 DCHECK(host_var.type == PP_VARTYPE_OBJECT);
69 75
70 // Get the object. 76 // Get the object.
71 scoped_refptr<ProxyObjectVar> object( 77 scoped_refptr<ProxyObjectVar> object(
72 FindOrMakePluginVarFromHostVar(host_var, dispatcher)); 78 FindOrMakePluginVarFromHostVar(host_var, dispatcher));
73 79
74 // Actually create the PP_Var, this will add all the tracking info but not 80 // Actually create the PP_Var, this will add all the tracking info but not
75 // adjust any refcounts. 81 // adjust any refcounts.
76 PP_Var ret = GetOrCreateObjectVarID(object.get()); 82 PP_Var ret = GetOrCreateObjectVarID(object.get());
77 83
78 VarInfo& info = GetLiveVar(ret)->second; 84 VarInfo& info = GetLiveVar(ret)->second;
79 info.track_with_no_reference_count++; 85 info.track_with_no_reference_count++;
80 return ret; 86 return ret;
81 } 87 }
82 88
83 void PluginVarTracker::StopTrackingObjectWithNoReference( 89 void PluginVarTracker::StopTrackingObjectWithNoReference(
84 const PP_Var& plugin_var) { 90 const PP_Var& plugin_var) {
85 DCHECK(CalledOnValidThread()); 91 CHECK_VALID_THREAD();
86 DCHECK(plugin_var.type == PP_VARTYPE_OBJECT); 92 DCHECK(plugin_var.type == PP_VARTYPE_OBJECT);
87 93
88 VarMap::iterator found = GetLiveVar(plugin_var); 94 VarMap::iterator found = GetLiveVar(plugin_var);
89 if (found == live_vars_.end()) { 95 if (found == live_vars_.end()) {
90 NOTREACHED(); 96 NOTREACHED();
91 return; 97 return;
92 } 98 }
93 99
94 DCHECK(found->second.track_with_no_reference_count > 0); 100 DCHECK(found->second.track_with_no_reference_count > 0);
95 found->second.track_with_no_reference_count--; 101 found->second.track_with_no_reference_count--;
96 DeleteObjectInfoIfNecessary(found); 102 DeleteObjectInfoIfNecessary(found);
97 } 103 }
98 104
99 PP_Var PluginVarTracker::GetHostObject(const PP_Var& plugin_object) const { 105 PP_Var PluginVarTracker::GetHostObject(const PP_Var& plugin_object) const {
100 DCHECK(CalledOnValidThread()); 106 CHECK_VALID_THREAD();
101 107
102 if (plugin_object.type != PP_VARTYPE_OBJECT) { 108 if (plugin_object.type != PP_VARTYPE_OBJECT) {
103 NOTREACHED(); 109 NOTREACHED();
104 return PP_MakeUndefined(); 110 return PP_MakeUndefined();
105 } 111 }
106 112
107 Var* var = GetVar(plugin_object); 113 Var* var = GetVar(plugin_object);
108 ProxyObjectVar* object = var->AsProxyObjectVar(); 114 ProxyObjectVar* object = var->AsProxyObjectVar();
109 if (!object) { 115 if (!object) {
110 NOTREACHED(); 116 NOTREACHED();
111 return PP_MakeUndefined(); 117 return PP_MakeUndefined();
112 } 118 }
113 119
114 // Make a var with the host ID. 120 // Make a var with the host ID.
115 PP_Var ret = { PP_VARTYPE_OBJECT }; 121 PP_Var ret = { PP_VARTYPE_OBJECT };
116 ret.value.as_id = object->host_var_id(); 122 ret.value.as_id = object->host_var_id();
117 return ret; 123 return ret;
118 } 124 }
119 125
120 PluginDispatcher* PluginVarTracker::DispatcherForPluginObject( 126 PluginDispatcher* PluginVarTracker::DispatcherForPluginObject(
121 const PP_Var& plugin_object) const { 127 const PP_Var& plugin_object) const {
122 DCHECK(CalledOnValidThread()); 128 CHECK_VALID_THREAD();
123 129
124 if (plugin_object.type != PP_VARTYPE_OBJECT) 130 if (plugin_object.type != PP_VARTYPE_OBJECT)
125 return NULL; 131 return NULL;
126 132
127 VarMap::const_iterator found = GetLiveVar(plugin_object); 133 VarMap::const_iterator found = GetLiveVar(plugin_object);
128 if (found == live_vars_.end()) 134 if (found == live_vars_.end())
129 return NULL; 135 return NULL;
130 136
131 ProxyObjectVar* object = found->second.var->AsProxyObjectVar(); 137 ProxyObjectVar* object = found->second.var->AsProxyObjectVar();
132 if (!object) 138 if (!object)
133 return NULL; 139 return NULL;
134 return object->dispatcher(); 140 return object->dispatcher();
135 } 141 }
136 142
137 void PluginVarTracker::ReleaseHostObject(PluginDispatcher* dispatcher, 143 void PluginVarTracker::ReleaseHostObject(PluginDispatcher* dispatcher,
138 const PP_Var& host_object) { 144 const PP_Var& host_object) {
139 DCHECK(CalledOnValidThread()); 145 CHECK_VALID_THREAD();
140 DCHECK(host_object.type == PP_VARTYPE_OBJECT); 146 DCHECK(host_object.type == PP_VARTYPE_OBJECT);
141 147
142 // Convert the host object to a normal var valid in the plugin. 148 // Convert the host object to a normal var valid in the plugin.
143 HostVarToPluginVarMap::iterator found = host_var_to_plugin_var_.find( 149 HostVarToPluginVarMap::iterator found = host_var_to_plugin_var_.find(
144 HostVar(dispatcher, static_cast<int32>(host_object.value.as_id))); 150 HostVar(dispatcher, static_cast<int32>(host_object.value.as_id)));
145 if (found == host_var_to_plugin_var_.end()) { 151 if (found == host_var_to_plugin_var_.end()) {
146 NOTREACHED(); 152 NOTREACHED();
147 return; 153 return;
148 } 154 }
149 155
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 VarMap::iterator ret = live_vars_.find(found->second); 271 VarMap::iterator ret = live_vars_.find(found->second);
266 DCHECK(ret != live_vars_.end()); 272 DCHECK(ret != live_vars_.end());
267 273
268 // All objects should be proxy objects. 274 // All objects should be proxy objects.
269 DCHECK(ret->second.var->AsProxyObjectVar()); 275 DCHECK(ret->second.var->AsProxyObjectVar());
270 return scoped_refptr<ProxyObjectVar>(ret->second.var->AsProxyObjectVar()); 276 return scoped_refptr<ProxyObjectVar>(ret->second.var->AsProxyObjectVar());
271 } 277 }
272 278
273 } // namesace proxy 279 } // namesace proxy
274 } // namespace ppapi 280 } // namespace ppapi
OLDNEW
« no previous file with comments | « no previous file | ppapi/shared_impl/var_tracker.h » ('j') | ppapi/shared_impl/var_tracker.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698