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