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

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

Issue 61063003: Keep NaCl plugins used in app background pages alive when active. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments in patch 3 & 4. Created 7 years 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_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/ppb_message_loop_proxy.h" 14 #include "ppapi/proxy/ppb_message_loop_proxy.h"
14 #include "ppapi/shared_impl/proxy_lock.h" 15 #include "ppapi/shared_impl/proxy_lock.h"
15 #include "ppapi/thunk/enter.h" 16 #include "ppapi/thunk/enter.h"
16 17
18 namespace {
19
20 const int kKeepaliveThrottleIntervalDefault = 5000;
21
22 } // namespace
23
17 namespace ppapi { 24 namespace ppapi {
18 namespace proxy { 25 namespace proxy {
19 26
20 // It performs necessary locking/unlocking of the proxy lock, and forwards all 27 // It performs necessary locking/unlocking of the proxy lock, and forwards all
21 // messages to the underlying sender. 28 // messages to the underlying sender.
22 class PluginGlobals::BrowserSender : public IPC::Sender { 29 class PluginGlobals::BrowserSender : public IPC::Sender {
23 public: 30 public:
24 // |underlying_sender| must outlive this object. 31 // |underlying_sender| must outlive this object.
25 explicit BrowserSender(IPC::Sender* underlying_sender) 32 explicit BrowserSender(IPC::Sender* underlying_sender)
26 : underlying_sender_(underlying_sender) { 33 : underlying_sender_(underlying_sender) {
(...skipping 17 matching lines...) Expand all
44 IPC::Sender* underlying_sender_; 51 IPC::Sender* underlying_sender_;
45 52
46 DISALLOW_COPY_AND_ASSIGN(BrowserSender); 53 DISALLOW_COPY_AND_ASSIGN(BrowserSender);
47 }; 54 };
48 55
49 PluginGlobals* PluginGlobals::plugin_globals_ = NULL; 56 PluginGlobals* PluginGlobals::plugin_globals_ = NULL;
50 57
51 PluginGlobals::PluginGlobals() 58 PluginGlobals::PluginGlobals()
52 : ppapi::PpapiGlobals(), 59 : ppapi::PpapiGlobals(),
53 plugin_proxy_delegate_(NULL), 60 plugin_proxy_delegate_(NULL),
54 callback_tracker_(new CallbackTracker) { 61 callback_tracker_(new CallbackTracker),
62 plugin_recently_active_(false),
63 keep_aliave_throttle_interval_milliseconds_(
64 kKeepaliveThrottleIntervalDefault),
65 weak_factory_(this)
66 {
yzshen1 2013/12/13 21:23:15 On the previous line, please.
scheib 2013/12/14 00:07:41 Done.
55 DCHECK(!plugin_globals_); 67 DCHECK(!plugin_globals_);
56 plugin_globals_ = this; 68 plugin_globals_ = this;
57 69
58 // ResourceTracker asserts that we have the lock when we add new resources, 70 // ResourceTracker asserts that we have the lock when we add new resources,
59 // so we lock when creating the MessageLoopResource even though there is no 71 // so we lock when creating the MessageLoopResource even though there is no
60 // chance of race conditions. 72 // chance of race conditions.
61 ProxyAutoLock lock; 73 ProxyAutoLock lock;
62 loop_for_main_thread_ = 74 loop_for_main_thread_ =
63 new MessageLoopResource(MessageLoopResource::ForMainThread()); 75 new MessageLoopResource(MessageLoopResource::ForMainThread());
64 } 76 }
65 77
66 PluginGlobals::PluginGlobals(PerThreadForTest per_thread_for_test) 78 PluginGlobals::PluginGlobals(PerThreadForTest per_thread_for_test)
67 : ppapi::PpapiGlobals(per_thread_for_test), 79 : ppapi::PpapiGlobals(per_thread_for_test),
68 plugin_proxy_delegate_(NULL), 80 plugin_proxy_delegate_(NULL),
69 callback_tracker_(new CallbackTracker) { 81 callback_tracker_(new CallbackTracker),
82 plugin_recently_active_(false),
yzshen1 2013/12/13 21:23:15 Please also init keep_alive_throttle_interval_mill
scheib 2013/12/14 00:07:41 Done.
83 weak_factory_(this) {
70 DCHECK(!plugin_globals_); 84 DCHECK(!plugin_globals_);
71 } 85 }
72 86
73 PluginGlobals::~PluginGlobals() { 87 PluginGlobals::~PluginGlobals() {
74 DCHECK(plugin_globals_ == this || !plugin_globals_); 88 DCHECK(plugin_globals_ == this || !plugin_globals_);
75 { 89 {
76 ProxyAutoLock lock; 90 ProxyAutoLock lock;
77 // Release the main-thread message loop. We should have the last reference 91 // Release the main-thread message loop. We should have the last reference
78 // count, so this will delete the MessageLoop resource. We do this before 92 // count, so this will delete the MessageLoop resource. We do this before
79 // we clear plugin_globals_, because the Resource destructor tries to access 93 // we clear plugin_globals_, because the Resource destructor tries to access
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 base::TaskRunner* PluginGlobals::GetFileTaskRunner() { 167 base::TaskRunner* PluginGlobals::GetFileTaskRunner() {
154 if (!file_thread_.get()) { 168 if (!file_thread_.get()) {
155 file_thread_.reset(new base::Thread("Plugin::File")); 169 file_thread_.reset(new base::Thread("Plugin::File"));
156 base::Thread::Options options; 170 base::Thread::Options options;
157 options.message_loop_type = base::MessageLoop::TYPE_IO; 171 options.message_loop_type = base::MessageLoop::TYPE_IO;
158 file_thread_->StartWithOptions(options); 172 file_thread_->StartWithOptions(options);
159 } 173 }
160 return file_thread_->message_loop_proxy(); 174 return file_thread_->message_loop_proxy();
161 } 175 }
162 176
177 void PluginGlobals::MarkPluginIsActive() {
178 if (!plugin_recently_active_) {
179 plugin_recently_active_ = true;
180 if (!GetBrowserSender() || !base::MessageLoop::current())
181 return;
182 GetBrowserSender()->Send(new PpapiHostMsg_Keepalive());
183
184 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
185 base::Bind(&PluginGlobals::OnReleaseKeepaliveThrottle,
186 weak_factory_.GetWeakPtr()),
187 base::TimeDelta::FromMilliseconds(
188 keep_aliave_throttle_interval_milliseconds()));
189 }
190 }
191
163 IPC::Sender* PluginGlobals::GetBrowserSender() { 192 IPC::Sender* PluginGlobals::GetBrowserSender() {
164 if (!browser_sender_.get()) { 193 if (!browser_sender_.get()) {
165 browser_sender_.reset( 194 browser_sender_.reset(
166 new BrowserSender(plugin_proxy_delegate_->GetBrowserSender())); 195 new BrowserSender(plugin_proxy_delegate_->GetBrowserSender()));
167 } 196 }
168 197
169 return browser_sender_.get(); 198 return browser_sender_.get();
170 } 199 }
171 200
172 std::string PluginGlobals::GetUILanguage() { 201 std::string PluginGlobals::GetUILanguage() {
(...skipping 10 matching lines...) Expand all
183 const PP_BrowserFont_Trusted_Description& desc, 212 const PP_BrowserFont_Trusted_Description& desc,
184 const ppapi::Preferences& prefs) { 213 const ppapi::Preferences& prefs) {
185 return plugin_proxy_delegate_->CreateBrowserFont( 214 return plugin_proxy_delegate_->CreateBrowserFont(
186 connection, instance, desc, prefs); 215 connection, instance, desc, prefs);
187 } 216 }
188 217
189 MessageLoopResource* PluginGlobals::loop_for_main_thread() { 218 MessageLoopResource* PluginGlobals::loop_for_main_thread() {
190 return loop_for_main_thread_.get(); 219 return loop_for_main_thread_.get();
191 } 220 }
192 221
222 int PluginGlobals::keep_aliave_throttle_interval_milliseconds() {
223 return keep_aliave_throttle_interval_milliseconds_;
224 }
225
226 void PluginGlobals::set_keep_aliave_throttle_interval_milliseconds(int i) {
227 keep_aliave_throttle_interval_milliseconds_ = i;
228 }
229
193 bool PluginGlobals::IsPluginGlobals() const { 230 bool PluginGlobals::IsPluginGlobals() const {
194 return true; 231 return true;
195 } 232 }
196 233
234 void PluginGlobals::OnReleaseKeepaliveThrottle() {
235 ppapi::ProxyAutoLock lock;
236 plugin_recently_active_ = false;
237 }
238
197 } // namespace proxy 239 } // namespace proxy
198 } // namespace ppapi 240 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698