OLD | NEW |
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_message_filter.h" |
12 #include "ppapi/proxy/plugin_proxy_delegate.h" | 13 #include "ppapi/proxy/plugin_proxy_delegate.h" |
13 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
14 #include "ppapi/proxy/ppb_message_loop_proxy.h" | 15 #include "ppapi/proxy/ppb_message_loop_proxy.h" |
15 #include "ppapi/proxy/resource_reply_thread_registrar.h" | 16 #include "ppapi/proxy/resource_reply_thread_registrar.h" |
| 17 #include "ppapi/proxy/udp_socket_filter.h" |
16 #include "ppapi/shared_impl/ppapi_constants.h" | 18 #include "ppapi/shared_impl/ppapi_constants.h" |
17 #include "ppapi/shared_impl/proxy_lock.h" | 19 #include "ppapi/shared_impl/proxy_lock.h" |
18 #include "ppapi/thunk/enter.h" | 20 #include "ppapi/thunk/enter.h" |
19 | 21 |
20 namespace ppapi { | 22 namespace ppapi { |
21 namespace proxy { | 23 namespace proxy { |
22 | 24 |
23 // It performs necessary locking/unlocking of the proxy lock, and forwards all | 25 // It performs necessary locking/unlocking of the proxy lock, and forwards all |
24 // messages to the underlying sender. | 26 // messages to the underlying sender. |
25 class PluginGlobals::BrowserSender : public IPC::Sender { | 27 class PluginGlobals::BrowserSender : public IPC::Sender { |
(...skipping 18 matching lines...) Expand all Loading... |
44 | 46 |
45 private: | 47 private: |
46 // Non-owning pointer. | 48 // Non-owning pointer. |
47 IPC::Sender* underlying_sender_; | 49 IPC::Sender* underlying_sender_; |
48 | 50 |
49 DISALLOW_COPY_AND_ASSIGN(BrowserSender); | 51 DISALLOW_COPY_AND_ASSIGN(BrowserSender); |
50 }; | 52 }; |
51 | 53 |
52 PluginGlobals* PluginGlobals::plugin_globals_ = NULL; | 54 PluginGlobals* PluginGlobals::plugin_globals_ = NULL; |
53 | 55 |
54 PluginGlobals::PluginGlobals() | 56 PluginGlobals::PluginGlobals( |
| 57 const scoped_refptr<base::TaskRunner>& ipc_task_runner) |
55 : ppapi::PpapiGlobals(), | 58 : ppapi::PpapiGlobals(), |
56 plugin_proxy_delegate_(NULL), | 59 plugin_proxy_delegate_(NULL), |
57 callback_tracker_(new CallbackTracker), | 60 callback_tracker_(new CallbackTracker), |
| 61 ipc_task_runner_(ipc_task_runner), |
58 resource_reply_thread_registrar_( | 62 resource_reply_thread_registrar_( |
59 new ResourceReplyThreadRegistrar(GetMainThreadMessageLoop())), | 63 new ResourceReplyThreadRegistrar(GetMainThreadMessageLoop())), |
| 64 udp_socket_filter_(new UDPSocketFilter()), |
60 plugin_recently_active_(false), | 65 plugin_recently_active_(false), |
61 keepalive_throttle_interval_milliseconds_( | 66 keepalive_throttle_interval_milliseconds_( |
62 ppapi::kKeepaliveThrottleIntervalDefaultMilliseconds), | 67 ppapi::kKeepaliveThrottleIntervalDefaultMilliseconds), |
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( |
| 81 PerThreadForTest per_thread_for_test, |
| 82 const scoped_refptr<base::TaskRunner>& ipc_task_runner) |
76 : ppapi::PpapiGlobals(per_thread_for_test), | 83 : ppapi::PpapiGlobals(per_thread_for_test), |
77 plugin_proxy_delegate_(NULL), | 84 plugin_proxy_delegate_(NULL), |
78 callback_tracker_(new CallbackTracker), | 85 callback_tracker_(new CallbackTracker), |
| 86 ipc_task_runner_(ipc_task_runner), |
79 resource_reply_thread_registrar_( | 87 resource_reply_thread_registrar_( |
80 new ResourceReplyThreadRegistrar(GetMainThreadMessageLoop())), | 88 new ResourceReplyThreadRegistrar(GetMainThreadMessageLoop())), |
81 plugin_recently_active_(false), | 89 plugin_recently_active_(false), |
82 keepalive_throttle_interval_milliseconds_( | 90 keepalive_throttle_interval_milliseconds_( |
83 kKeepaliveThrottleIntervalDefaultMilliseconds), | 91 kKeepaliveThrottleIntervalDefaultMilliseconds), |
84 weak_factory_(this) { | 92 weak_factory_(this) { |
85 DCHECK(!plugin_globals_); | 93 DCHECK(!plugin_globals_); |
86 } | 94 } |
87 | 95 |
88 PluginGlobals::~PluginGlobals() { | 96 PluginGlobals::~PluginGlobals() { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 void PluginGlobals::ResetPluginProxyDelegate() { | 237 void PluginGlobals::ResetPluginProxyDelegate() { |
230 DCHECK(plugin_proxy_delegate_); | 238 DCHECK(plugin_proxy_delegate_); |
231 plugin_proxy_delegate_ = NULL; | 239 plugin_proxy_delegate_ = NULL; |
232 browser_sender_.reset(); | 240 browser_sender_.reset(); |
233 } | 241 } |
234 | 242 |
235 MessageLoopResource* PluginGlobals::loop_for_main_thread() { | 243 MessageLoopResource* PluginGlobals::loop_for_main_thread() { |
236 return loop_for_main_thread_.get(); | 244 return loop_for_main_thread_.get(); |
237 } | 245 } |
238 | 246 |
| 247 void PluginGlobals::RegisterResourceMessageFilters( |
| 248 ppapi::proxy::PluginMessageFilter* plugin_filter) { |
| 249 plugin_filter->AddResourceMessageFilter(udp_socket_filter_.get()); |
| 250 } |
| 251 |
239 void PluginGlobals::set_keepalive_throttle_interval_milliseconds(unsigned i) { | 252 void PluginGlobals::set_keepalive_throttle_interval_milliseconds(unsigned i) { |
240 keepalive_throttle_interval_milliseconds_ = i; | 253 keepalive_throttle_interval_milliseconds_ = i; |
241 } | 254 } |
242 | 255 |
243 bool PluginGlobals::IsPluginGlobals() const { | 256 bool PluginGlobals::IsPluginGlobals() const { |
244 return true; | 257 return true; |
245 } | 258 } |
246 | 259 |
247 void PluginGlobals::OnReleaseKeepaliveThrottle() { | 260 void PluginGlobals::OnReleaseKeepaliveThrottle() { |
248 ppapi::ProxyLock::AssertAcquiredDebugOnly(); | 261 ppapi::ProxyLock::AssertAcquiredDebugOnly(); |
249 plugin_recently_active_ = false; | 262 plugin_recently_active_ = false; |
250 } | 263 } |
251 | 264 |
252 } // namespace proxy | 265 } // namespace proxy |
253 } // namespace ppapi | 266 } // namespace ppapi |
OLD | NEW |