| 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 "ipc/ipc_message.h" | 7 #include "ipc/ipc_message.h" |
| 8 #include "ipc/ipc_sender.h" | 8 #include "ipc/ipc_sender.h" |
| 9 #include "ppapi/proxy/plugin_dispatcher.h" | 9 #include "ppapi/proxy/plugin_dispatcher.h" |
| 10 #include "ppapi/proxy/plugin_proxy_delegate.h" | 10 #include "ppapi/proxy/plugin_proxy_delegate.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 IPC::Sender* underlying_sender_; | 42 IPC::Sender* underlying_sender_; |
| 43 | 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(BrowserSender); | 44 DISALLOW_COPY_AND_ASSIGN(BrowserSender); |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 PluginGlobals* PluginGlobals::plugin_globals_ = NULL; | 47 PluginGlobals* PluginGlobals::plugin_globals_ = NULL; |
| 48 | 48 |
| 49 PluginGlobals::PluginGlobals() | 49 PluginGlobals::PluginGlobals() |
| 50 : ppapi::PpapiGlobals(), | 50 : ppapi::PpapiGlobals(), |
| 51 plugin_proxy_delegate_(NULL), | 51 plugin_proxy_delegate_(NULL), |
| 52 callback_tracker_(new CallbackTracker) { | 52 callback_tracker_(new CallbackTracker), |
| 53 loop_for_main_thread_( |
| 54 new MessageLoopResource(MessageLoopResource::ForMainThread())) { |
| 55 #if defined(ENABLE_PEPPER_THREADING) |
| 56 enable_threading_ = true; |
| 57 #else |
| 58 enable_threading_ = false; |
| 59 #endif |
| 60 |
| 53 DCHECK(!plugin_globals_); | 61 DCHECK(!plugin_globals_); |
| 54 plugin_globals_ = this; | 62 plugin_globals_ = this; |
| 55 | |
| 56 // ResourceTracker asserts that we have the lock when we add new resources, | |
| 57 // so we lock when creating the MessageLoopResource even though there is no | |
| 58 // chance of race conditions. | |
| 59 ProxyAutoLock lock; | |
| 60 loop_for_main_thread_ = | |
| 61 new MessageLoopResource(MessageLoopResource::ForMainThread()); | |
| 62 } | 63 } |
| 63 | 64 |
| 64 PluginGlobals::PluginGlobals(PerThreadForTest per_thread_for_test) | 65 PluginGlobals::PluginGlobals(PerThreadForTest per_thread_for_test) |
| 65 : ppapi::PpapiGlobals(per_thread_for_test), | 66 : ppapi::PpapiGlobals(per_thread_for_test), |
| 66 plugin_proxy_delegate_(NULL), | 67 plugin_proxy_delegate_(NULL), |
| 67 callback_tracker_(new CallbackTracker) { | 68 callback_tracker_(new CallbackTracker) { |
| 69 #if defined(ENABLE_PEPPER_THREADING) |
| 70 enable_threading_ = true; |
| 71 #else |
| 72 enable_threading_ = false; |
| 73 #endif |
| 68 DCHECK(!plugin_globals_); | 74 DCHECK(!plugin_globals_); |
| 69 } | 75 } |
| 70 | 76 |
| 71 PluginGlobals::~PluginGlobals() { | 77 PluginGlobals::~PluginGlobals() { |
| 72 DCHECK(plugin_globals_ == this || !plugin_globals_); | 78 DCHECK(plugin_globals_ == this || !plugin_globals_); |
| 73 { | 79 // Release the main-thread message loop. We should have the last reference |
| 74 ProxyAutoLock lock; | 80 // count, so this will delete the MessageLoop resource. We do this before |
| 75 // Release the main-thread message loop. We should have the last reference | 81 // we clear plugin_globals_, because the Resource destructor tries to access |
| 76 // count, so this will delete the MessageLoop resource. We do this before | 82 // this PluginGlobals. |
| 77 // we clear plugin_globals_, because the Resource destructor tries to access | 83 DCHECK(!loop_for_main_thread_ || loop_for_main_thread_->HasOneRef()); |
| 78 // this PluginGlobals. | 84 loop_for_main_thread_ = NULL; |
| 79 DCHECK(!loop_for_main_thread_ || loop_for_main_thread_->HasOneRef()); | 85 |
| 80 loop_for_main_thread_ = NULL; | |
| 81 } | |
| 82 plugin_globals_ = NULL; | 86 plugin_globals_ = NULL; |
| 83 } | 87 } |
| 84 | 88 |
| 85 ResourceTracker* PluginGlobals::GetResourceTracker() { | 89 ResourceTracker* PluginGlobals::GetResourceTracker() { |
| 86 return &plugin_resource_tracker_; | 90 return &plugin_resource_tracker_; |
| 87 } | 91 } |
| 88 | 92 |
| 89 VarTracker* PluginGlobals::GetVarTracker() { | 93 VarTracker* PluginGlobals::GetVarTracker() { |
| 90 return &plugin_var_tracker_; | 94 return &plugin_var_tracker_; |
| 91 } | 95 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 120 std::string PluginGlobals::GetCmdLine() { | 124 std::string PluginGlobals::GetCmdLine() { |
| 121 return command_line_; | 125 return command_line_; |
| 122 } | 126 } |
| 123 | 127 |
| 124 void PluginGlobals::PreCacheFontForFlash(const void* logfontw) { | 128 void PluginGlobals::PreCacheFontForFlash(const void* logfontw) { |
| 125 ProxyAutoUnlock unlock; | 129 ProxyAutoUnlock unlock; |
| 126 plugin_proxy_delegate_->PreCacheFont(logfontw); | 130 plugin_proxy_delegate_->PreCacheFont(logfontw); |
| 127 } | 131 } |
| 128 | 132 |
| 129 base::Lock* PluginGlobals::GetProxyLock() { | 133 base::Lock* PluginGlobals::GetProxyLock() { |
| 130 return &proxy_lock_; | 134 if (enable_threading_) |
| 135 return &proxy_lock_; |
| 136 return NULL; |
| 131 } | 137 } |
| 132 | 138 |
| 133 void PluginGlobals::LogWithSource(PP_Instance instance, | 139 void PluginGlobals::LogWithSource(PP_Instance instance, |
| 134 PP_LogLevel level, | 140 PP_LogLevel level, |
| 135 const std::string& source, | 141 const std::string& source, |
| 136 const std::string& value) { | 142 const std::string& value) { |
| 137 const std::string& fixed_up_source = source.empty() ? plugin_name_ : source; | 143 const std::string& fixed_up_source = source.empty() ? plugin_name_ : source; |
| 138 PluginDispatcher::LogWithSource(instance, level, fixed_up_source, value); | 144 PluginDispatcher::LogWithSource(instance, level, fixed_up_source, value); |
| 139 } | 145 } |
| 140 | 146 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 MessageLoopResource* PluginGlobals::loop_for_main_thread() { | 178 MessageLoopResource* PluginGlobals::loop_for_main_thread() { |
| 173 return loop_for_main_thread_.get(); | 179 return loop_for_main_thread_.get(); |
| 174 } | 180 } |
| 175 | 181 |
| 176 bool PluginGlobals::IsPluginGlobals() const { | 182 bool PluginGlobals::IsPluginGlobals() const { |
| 177 return true; | 183 return true; |
| 178 } | 184 } |
| 179 | 185 |
| 180 } // namespace proxy | 186 } // namespace proxy |
| 181 } // namespace ppapi | 187 } // namespace ppapi |
| OLD | NEW |