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

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

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