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

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

Issue 199933002: Revert of Replace --ppapi-keep-alive-throttle command line switch with IPC parameter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
« no previous file with comments | « ppapi/proxy/plugin_globals.h ('k') | ppapi/proxy/plugin_main_irt.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"
11 #include "ppapi/proxy/plugin_dispatcher.h" 11 #include "ppapi/proxy/plugin_dispatcher.h"
12 #include "ppapi/proxy/plugin_proxy_delegate.h" 12 #include "ppapi/proxy/plugin_proxy_delegate.h"
13 #include "ppapi/proxy/ppapi_messages.h" 13 #include "ppapi/proxy/ppapi_messages.h"
14 #include "ppapi/proxy/ppb_message_loop_proxy.h" 14 #include "ppapi/proxy/ppb_message_loop_proxy.h"
15 #include "ppapi/proxy/resource_reply_thread_registrar.h" 15 #include "ppapi/proxy/resource_reply_thread_registrar.h"
16 #include "ppapi/shared_impl/ppapi_constants.h"
17 #include "ppapi/shared_impl/proxy_lock.h" 16 #include "ppapi/shared_impl/proxy_lock.h"
18 #include "ppapi/thunk/enter.h" 17 #include "ppapi/thunk/enter.h"
19 18
19 namespace {
20
21 const int kKeepaliveThrottleIntervalDefault = 5000;
22
23 } // namespace
24
20 namespace ppapi { 25 namespace ppapi {
21 namespace proxy { 26 namespace proxy {
22 27
23 // It performs necessary locking/unlocking of the proxy lock, and forwards all 28 // It performs necessary locking/unlocking of the proxy lock, and forwards all
24 // messages to the underlying sender. 29 // messages to the underlying sender.
25 class PluginGlobals::BrowserSender : public IPC::Sender { 30 class PluginGlobals::BrowserSender : public IPC::Sender {
26 public: 31 public:
27 // |underlying_sender| must outlive this object. 32 // |underlying_sender| must outlive this object.
28 explicit BrowserSender(IPC::Sender* underlying_sender) 33 explicit BrowserSender(IPC::Sender* underlying_sender)
29 : underlying_sender_(underlying_sender) { 34 : underlying_sender_(underlying_sender) {
(...skipping 22 matching lines...) Expand all
52 PluginGlobals* PluginGlobals::plugin_globals_ = NULL; 57 PluginGlobals* PluginGlobals::plugin_globals_ = NULL;
53 58
54 PluginGlobals::PluginGlobals() 59 PluginGlobals::PluginGlobals()
55 : ppapi::PpapiGlobals(), 60 : ppapi::PpapiGlobals(),
56 plugin_proxy_delegate_(NULL), 61 plugin_proxy_delegate_(NULL),
57 callback_tracker_(new CallbackTracker), 62 callback_tracker_(new CallbackTracker),
58 resource_reply_thread_registrar_( 63 resource_reply_thread_registrar_(
59 new ResourceReplyThreadRegistrar(GetMainThreadMessageLoop())), 64 new ResourceReplyThreadRegistrar(GetMainThreadMessageLoop())),
60 plugin_recently_active_(false), 65 plugin_recently_active_(false),
61 keepalive_throttle_interval_milliseconds_( 66 keepalive_throttle_interval_milliseconds_(
62 ppapi::kKeepaliveThrottleIntervalDefaultMilliseconds), 67 kKeepaliveThrottleIntervalDefault),
63 weak_factory_(this) { 68 weak_factory_(this) {
64 DCHECK(!plugin_globals_); 69 DCHECK(!plugin_globals_);
65 plugin_globals_ = this; 70 plugin_globals_ = this;
66 71
67 // ResourceTracker asserts that we have the lock when we add new resources, 72 // ResourceTracker asserts that we have the lock when we add new resources,
68 // so we lock when creating the MessageLoopResource even though there is no 73 // so we lock when creating the MessageLoopResource even though there is no
69 // chance of race conditions. 74 // chance of race conditions.
70 ProxyAutoLock lock; 75 ProxyAutoLock lock;
71 loop_for_main_thread_ = 76 loop_for_main_thread_ =
72 new MessageLoopResource(MessageLoopResource::ForMainThread()); 77 new MessageLoopResource(MessageLoopResource::ForMainThread());
73 } 78 }
74 79
75 PluginGlobals::PluginGlobals(PerThreadForTest per_thread_for_test) 80 PluginGlobals::PluginGlobals(PerThreadForTest per_thread_for_test)
76 : ppapi::PpapiGlobals(per_thread_for_test), 81 : ppapi::PpapiGlobals(per_thread_for_test),
77 plugin_proxy_delegate_(NULL), 82 plugin_proxy_delegate_(NULL),
78 callback_tracker_(new CallbackTracker), 83 callback_tracker_(new CallbackTracker),
79 resource_reply_thread_registrar_( 84 resource_reply_thread_registrar_(
80 new ResourceReplyThreadRegistrar(GetMainThreadMessageLoop())), 85 new ResourceReplyThreadRegistrar(GetMainThreadMessageLoop())),
81 plugin_recently_active_(false), 86 plugin_recently_active_(false),
82 keepalive_throttle_interval_milliseconds_( 87 keepalive_throttle_interval_milliseconds_(
83 kKeepaliveThrottleIntervalDefaultMilliseconds), 88 kKeepaliveThrottleIntervalDefault),
84 weak_factory_(this) { 89 weak_factory_(this) {
85 DCHECK(!plugin_globals_); 90 DCHECK(!plugin_globals_);
86 } 91 }
87 92
88 PluginGlobals::~PluginGlobals() { 93 PluginGlobals::~PluginGlobals() {
89 DCHECK(plugin_globals_ == this || !plugin_globals_); 94 DCHECK(plugin_globals_ == this || !plugin_globals_);
90 { 95 {
91 ProxyAutoLock lock; 96 ProxyAutoLock lock;
92 // Release the main-thread message loop. We should have the last reference 97 // Release the main-thread message loop. We should have the last reference
93 // count, so this will delete the MessageLoop resource. We do this before 98 // count, so this will delete the MessageLoop resource. We do this before
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 179 }
175 return file_thread_->message_loop_proxy(); 180 return file_thread_->message_loop_proxy();
176 } 181 }
177 182
178 void PluginGlobals::MarkPluginIsActive() { 183 void PluginGlobals::MarkPluginIsActive() {
179 if (!plugin_recently_active_) { 184 if (!plugin_recently_active_) {
180 plugin_recently_active_ = true; 185 plugin_recently_active_ = true;
181 if (!GetBrowserSender() || !base::MessageLoop::current()) 186 if (!GetBrowserSender() || !base::MessageLoop::current())
182 return; 187 return;
183 GetBrowserSender()->Send(new PpapiHostMsg_Keepalive()); 188 GetBrowserSender()->Send(new PpapiHostMsg_Keepalive());
184 DCHECK(keepalive_throttle_interval_milliseconds_); 189
185 GetMainThreadMessageLoop()->PostDelayedTask( 190 GetMainThreadMessageLoop()->PostDelayedTask(FROM_HERE,
186 FROM_HERE,
187 RunWhileLocked(base::Bind(&PluginGlobals::OnReleaseKeepaliveThrottle, 191 RunWhileLocked(base::Bind(&PluginGlobals::OnReleaseKeepaliveThrottle,
188 weak_factory_.GetWeakPtr())), 192 weak_factory_.GetWeakPtr())),
189 base::TimeDelta::FromMilliseconds( 193 base::TimeDelta::FromMilliseconds(
190 keepalive_throttle_interval_milliseconds_)); 194 keepalive_throttle_interval_milliseconds()));
191 } 195 }
192 } 196 }
193 197
194 IPC::Sender* PluginGlobals::GetBrowserSender() { 198 IPC::Sender* PluginGlobals::GetBrowserSender() {
195 if (!browser_sender_.get()) { 199 if (!browser_sender_.get()) {
196 browser_sender_.reset( 200 browser_sender_.reset(
197 new BrowserSender(plugin_proxy_delegate_->GetBrowserSender())); 201 new BrowserSender(plugin_proxy_delegate_->GetBrowserSender()));
198 } 202 }
199 203
200 return browser_sender_.get(); 204 return browser_sender_.get();
(...skipping 13 matching lines...) Expand all
214 const PP_BrowserFont_Trusted_Description& desc, 218 const PP_BrowserFont_Trusted_Description& desc,
215 const ppapi::Preferences& prefs) { 219 const ppapi::Preferences& prefs) {
216 return plugin_proxy_delegate_->CreateBrowserFont( 220 return plugin_proxy_delegate_->CreateBrowserFont(
217 connection, instance, desc, prefs); 221 connection, instance, desc, prefs);
218 } 222 }
219 223
220 MessageLoopResource* PluginGlobals::loop_for_main_thread() { 224 MessageLoopResource* PluginGlobals::loop_for_main_thread() {
221 return loop_for_main_thread_.get(); 225 return loop_for_main_thread_.get();
222 } 226 }
223 227
224 void PluginGlobals::set_keepalive_throttle_interval_milliseconds(unsigned i) { 228 int PluginGlobals::keepalive_throttle_interval_milliseconds() const {
229 return keepalive_throttle_interval_milliseconds_;
230 }
231
232 void PluginGlobals::set_keepalive_throttle_interval_milliseconds(int i) {
225 keepalive_throttle_interval_milliseconds_ = i; 233 keepalive_throttle_interval_milliseconds_ = i;
226 } 234 }
227 235
228 bool PluginGlobals::IsPluginGlobals() const { 236 bool PluginGlobals::IsPluginGlobals() const {
229 return true; 237 return true;
230 } 238 }
231 239
232 void PluginGlobals::OnReleaseKeepaliveThrottle() { 240 void PluginGlobals::OnReleaseKeepaliveThrottle() {
233 ppapi::ProxyLock::AssertAcquiredDebugOnly(); 241 ppapi::ProxyLock::AssertAcquiredDebugOnly();
234 plugin_recently_active_ = false; 242 plugin_recently_active_ = false;
235 } 243 }
236 244
237 } // namespace proxy 245 } // namespace proxy
238 } // namespace ppapi 246 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/plugin_globals.h ('k') | ppapi/proxy/plugin_main_irt.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698