| 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_proxy_delegate.h" | 12 #include "ppapi/proxy/plugin_proxy_delegate.h" |
| 13 #include "ppapi/proxy/ppb_message_loop_proxy.h" | 13 #include "ppapi/proxy/ppb_message_loop_proxy.h" |
| 14 #include "ppapi/proxy/resource_reply_thread_registrar.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 |
| 17 namespace ppapi { | 18 namespace ppapi { |
| 18 namespace proxy { | 19 namespace proxy { |
| 19 | 20 |
| 20 // It performs necessary locking/unlocking of the proxy lock, and forwards all | 21 // It performs necessary locking/unlocking of the proxy lock, and forwards all |
| 21 // messages to the underlying sender. | 22 // messages to the underlying sender. |
| 22 class PluginGlobals::BrowserSender : public IPC::Sender { | 23 class PluginGlobals::BrowserSender : public IPC::Sender { |
| 23 public: | 24 public: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 44 IPC::Sender* underlying_sender_; | 45 IPC::Sender* underlying_sender_; |
| 45 | 46 |
| 46 DISALLOW_COPY_AND_ASSIGN(BrowserSender); | 47 DISALLOW_COPY_AND_ASSIGN(BrowserSender); |
| 47 }; | 48 }; |
| 48 | 49 |
| 49 PluginGlobals* PluginGlobals::plugin_globals_ = NULL; | 50 PluginGlobals* PluginGlobals::plugin_globals_ = NULL; |
| 50 | 51 |
| 51 PluginGlobals::PluginGlobals() | 52 PluginGlobals::PluginGlobals() |
| 52 : ppapi::PpapiGlobals(), | 53 : ppapi::PpapiGlobals(), |
| 53 plugin_proxy_delegate_(NULL), | 54 plugin_proxy_delegate_(NULL), |
| 54 callback_tracker_(new CallbackTracker) { | 55 callback_tracker_(new CallbackTracker), |
| 56 resource_reply_thread_registrar_( |
| 57 new ResourceReplyThreadRegistrar(GetMainThreadMessageLoop())) { |
| 55 DCHECK(!plugin_globals_); | 58 DCHECK(!plugin_globals_); |
| 56 plugin_globals_ = this; | 59 plugin_globals_ = this; |
| 57 | 60 |
| 58 // ResourceTracker asserts that we have the lock when we add new resources, | 61 // 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 | 62 // so we lock when creating the MessageLoopResource even though there is no |
| 60 // chance of race conditions. | 63 // chance of race conditions. |
| 61 ProxyAutoLock lock; | 64 ProxyAutoLock lock; |
| 62 loop_for_main_thread_ = | 65 loop_for_main_thread_ = |
| 63 new MessageLoopResource(MessageLoopResource::ForMainThread()); | 66 new MessageLoopResource(MessageLoopResource::ForMainThread()); |
| 64 } | 67 } |
| 65 | 68 |
| 66 PluginGlobals::PluginGlobals(PerThreadForTest per_thread_for_test) | 69 PluginGlobals::PluginGlobals(PerThreadForTest per_thread_for_test) |
| 67 : ppapi::PpapiGlobals(per_thread_for_test), | 70 : ppapi::PpapiGlobals(per_thread_for_test), |
| 68 plugin_proxy_delegate_(NULL), | 71 plugin_proxy_delegate_(NULL), |
| 69 callback_tracker_(new CallbackTracker) { | 72 callback_tracker_(new CallbackTracker), |
| 73 resource_reply_thread_registrar_( |
| 74 new ResourceReplyThreadRegistrar(GetMainThreadMessageLoop())) { |
| 70 DCHECK(!plugin_globals_); | 75 DCHECK(!plugin_globals_); |
| 71 } | 76 } |
| 72 | 77 |
| 73 PluginGlobals::~PluginGlobals() { | 78 PluginGlobals::~PluginGlobals() { |
| 74 DCHECK(plugin_globals_ == this || !plugin_globals_); | 79 DCHECK(plugin_globals_ == this || !plugin_globals_); |
| 75 { | 80 { |
| 76 ProxyAutoLock lock; | 81 ProxyAutoLock lock; |
| 77 // Release the main-thread message loop. We should have the last reference | 82 // 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 | 83 // count, so this will delete the MessageLoop resource. We do this before |
| 79 // we clear plugin_globals_, because the Resource destructor tries to access | 84 // we clear plugin_globals_, because the Resource destructor tries to access |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 MessageLoopResource* PluginGlobals::loop_for_main_thread() { | 194 MessageLoopResource* PluginGlobals::loop_for_main_thread() { |
| 190 return loop_for_main_thread_.get(); | 195 return loop_for_main_thread_.get(); |
| 191 } | 196 } |
| 192 | 197 |
| 193 bool PluginGlobals::IsPluginGlobals() const { | 198 bool PluginGlobals::IsPluginGlobals() const { |
| 194 return true; | 199 return true; |
| 195 } | 200 } |
| 196 | 201 |
| 197 } // namespace proxy | 202 } // namespace proxy |
| 198 } // namespace ppapi | 203 } // namespace ppapi |
| OLD | NEW |