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

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

Issue 568793002: PPAPI: Fix GetBrowserInterface race conditions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 6 years, 3 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
« no previous file with comments | « ppapi/proxy/plugin_globals.h ('k') | ppapi/proxy/ppapi_proxy_test.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) 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_globals.h" 5 #include "ppapi/proxy/plugin_globals.h"
6 6
7 #include "base/task_runner.h" 7 #include "base/task_runner.h"
8 #include "base/threading/thread.h" 8 #include "base/threading/thread.h"
9 #include "ipc/ipc_message.h" 9 #include "ipc/ipc_message.h"
10 #include "ipc/ipc_sender.h" 10 #include "ipc/ipc_sender.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 GetMainThreadMessageLoop()->PostDelayedTask( 185 GetMainThreadMessageLoop()->PostDelayedTask(
186 FROM_HERE, 186 FROM_HERE,
187 RunWhileLocked(base::Bind(&PluginGlobals::OnReleaseKeepaliveThrottle, 187 RunWhileLocked(base::Bind(&PluginGlobals::OnReleaseKeepaliveThrottle,
188 weak_factory_.GetWeakPtr())), 188 weak_factory_.GetWeakPtr())),
189 base::TimeDelta::FromMilliseconds( 189 base::TimeDelta::FromMilliseconds(
190 keepalive_throttle_interval_milliseconds_)); 190 keepalive_throttle_interval_milliseconds_));
191 } 191 }
192 } 192 }
193 193
194 IPC::Sender* PluginGlobals::GetBrowserSender() { 194 IPC::Sender* PluginGlobals::GetBrowserSender() {
195 if (!browser_sender_.get()) { 195 // CAUTION: This function is called without the ProxyLock. See also
196 browser_sender_.reset( 196 // InterfaceList::GetInterfaceForPPB.
197 new BrowserSender(plugin_proxy_delegate_->GetBrowserSender())); 197 //
198 } 198 // See also SetPluginProxyDelegate. That initializes browser_sender_ before
199 199 // the plugin can start threads, and it may be cleared after the
200 // plugin has torn down threads. So this pointer is expected to remain valid
201 // during the lifetime of the plugin.
200 return browser_sender_.get(); 202 return browser_sender_.get();
201 } 203 }
202 204
203 std::string PluginGlobals::GetUILanguage() { 205 std::string PluginGlobals::GetUILanguage() {
204 return plugin_proxy_delegate_->GetUILanguage(); 206 return plugin_proxy_delegate_->GetUILanguage();
205 } 207 }
206 208
207 void PluginGlobals::SetActiveURL(const std::string& url) { 209 void PluginGlobals::SetActiveURL(const std::string& url) {
208 plugin_proxy_delegate_->SetActiveURL(url); 210 plugin_proxy_delegate_->SetActiveURL(url);
209 } 211 }
210 212
211 PP_Resource PluginGlobals::CreateBrowserFont( 213 PP_Resource PluginGlobals::CreateBrowserFont(
212 Connection connection, 214 Connection connection,
213 PP_Instance instance, 215 PP_Instance instance,
214 const PP_BrowserFont_Trusted_Description& desc, 216 const PP_BrowserFont_Trusted_Description& desc,
215 const ppapi::Preferences& prefs) { 217 const ppapi::Preferences& prefs) {
216 return plugin_proxy_delegate_->CreateBrowserFont( 218 return plugin_proxy_delegate_->CreateBrowserFont(
217 connection, instance, desc, prefs); 219 connection, instance, desc, prefs);
218 } 220 }
219 221
222 void PluginGlobals::SetPluginProxyDelegate(PluginProxyDelegate* delegate) {
223 DCHECK(delegate && !plugin_proxy_delegate_);
224 plugin_proxy_delegate_ = delegate;
225 browser_sender_.reset(
226 new BrowserSender(plugin_proxy_delegate_->GetBrowserSender()));
227 }
228
229 void PluginGlobals::ResetPluginProxyDelegate() {
230 DCHECK(plugin_proxy_delegate_);
231 plugin_proxy_delegate_ = NULL;
232 browser_sender_.reset();
233 }
234
220 MessageLoopResource* PluginGlobals::loop_for_main_thread() { 235 MessageLoopResource* PluginGlobals::loop_for_main_thread() {
221 return loop_for_main_thread_.get(); 236 return loop_for_main_thread_.get();
222 } 237 }
223 238
224 void PluginGlobals::set_keepalive_throttle_interval_milliseconds(unsigned i) { 239 void PluginGlobals::set_keepalive_throttle_interval_milliseconds(unsigned i) {
225 keepalive_throttle_interval_milliseconds_ = i; 240 keepalive_throttle_interval_milliseconds_ = i;
226 } 241 }
227 242
228 bool PluginGlobals::IsPluginGlobals() const { 243 bool PluginGlobals::IsPluginGlobals() const {
229 return true; 244 return true;
230 } 245 }
231 246
232 void PluginGlobals::OnReleaseKeepaliveThrottle() { 247 void PluginGlobals::OnReleaseKeepaliveThrottle() {
233 ppapi::ProxyLock::AssertAcquiredDebugOnly(); 248 ppapi::ProxyLock::AssertAcquiredDebugOnly();
234 plugin_recently_active_ = false; 249 plugin_recently_active_ = false;
235 } 250 }
236 251
237 } // namespace proxy 252 } // namespace proxy
238 } // namespace ppapi 253 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/plugin_globals.h ('k') | ppapi/proxy/ppapi_proxy_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698