| 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 "content/renderer/render_thread_impl.h" | 5 #include "content/renderer/render_thread_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 // which means that we need to make the render thread pump UI events. | 172 // which means that we need to make the render thread pump UI events. |
| 173 RenderThreadImpl::RenderThreadImpl() { | 173 RenderThreadImpl::RenderThreadImpl() { |
| 174 Init(); | 174 Init(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 RenderThreadImpl::RenderThreadImpl(const std::string& channel_name) | 177 RenderThreadImpl::RenderThreadImpl(const std::string& channel_name) |
| 178 : ChildThread(channel_name) { | 178 : ChildThread(channel_name) { |
| 179 Init(); | 179 Init(); |
| 180 } | 180 } |
| 181 | 181 |
| 182 #if defined(OS_POSIX) |
| 183 class SuicideOnChannelErrorFilter : public IPC::ChannelProxy::MessageFilter { |
| 184 void OnChannelError() { |
| 185 // On POSIX, at least, one can install an unload handler which loops |
| 186 // forever and leave behind a renderer process which eats 100% CPU forever. |
| 187 // |
| 188 // This is because the terminate signals (ViewMsg_ShouldClose and the error |
| 189 // from the IPC channel) are routed to the main message loop but never |
| 190 // processed (because that message loop is stuck in V8). |
| 191 // |
| 192 // One could make the browser SIGKILL the renderers, but that leaves open a |
| 193 // large window where a browser failure (or a user, manually terminating |
| 194 // the browser because "it's stuck") will leave behind a process eating all |
| 195 // the CPU. |
| 196 // |
| 197 // So, we install a filter on the channel so that we can process this event |
| 198 // here and kill the process. |
| 199 |
| 200 _exit(0); |
| 201 } |
| 202 }; |
| 203 #endif // OS_POSIX |
| 204 |
| 205 |
| 182 void RenderThreadImpl::Init() { | 206 void RenderThreadImpl::Init() { |
| 183 TRACE_EVENT_BEGIN_ETW("RenderThreadImpl::Init", 0, ""); | 207 TRACE_EVENT_BEGIN_ETW("RenderThreadImpl::Init", 0, ""); |
| 184 | 208 |
| 185 #if defined(OS_MACOSX) || defined(OS_ANDROID) | 209 #if defined(OS_MACOSX) || defined(OS_ANDROID) |
| 186 // On Mac and Android, the select popups are rendered by the browser. | 210 // On Mac and Android, the select popups are rendered by the browser. |
| 187 WebKit::WebView::setUseExternalPopupMenus(true); | 211 WebKit::WebView::setUseExternalPopupMenus(true); |
| 188 #endif | 212 #endif |
| 189 | 213 |
| 190 lazy_tls.Pointer()->Set(this); | 214 lazy_tls.Pointer()->Set(this); |
| 191 | 215 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 AddFilter(audio_input_message_filter_.get()); | 249 AddFilter(audio_input_message_filter_.get()); |
| 226 | 250 |
| 227 audio_message_filter_ = new AudioMessageFilter(); | 251 audio_message_filter_ = new AudioMessageFilter(); |
| 228 AddFilter(audio_message_filter_.get()); | 252 AddFilter(audio_message_filter_.get()); |
| 229 | 253 |
| 230 devtools_agent_message_filter_ = new DevToolsAgentFilter(); | 254 devtools_agent_message_filter_ = new DevToolsAgentFilter(); |
| 231 AddFilter(devtools_agent_message_filter_.get()); | 255 AddFilter(devtools_agent_message_filter_.get()); |
| 232 | 256 |
| 233 AddFilter(new IndexedDBMessageFilter); | 257 AddFilter(new IndexedDBMessageFilter); |
| 234 | 258 |
| 259 #if defined(OS_POSIX) |
| 260 AddFilter(new SuicideOnChannelErrorFilter()); |
| 261 #endif |
| 262 |
| 235 content::GetContentClient()->renderer()->RenderThreadStarted(); | 263 content::GetContentClient()->renderer()->RenderThreadStarted(); |
| 236 | 264 |
| 237 // Note that under Linux, the media library will normally already have | 265 // Note that under Linux, the media library will normally already have |
| 238 // been initialized by the Zygote before this instance became a Renderer. | 266 // been initialized by the Zygote before this instance became a Renderer. |
| 239 FilePath media_path; | 267 FilePath media_path; |
| 240 PathService::Get(content::DIR_MEDIA_LIBS, &media_path); | 268 PathService::Get(content::DIR_MEDIA_LIBS, &media_path); |
| 241 if (!media_path.empty()) | 269 if (!media_path.empty()) |
| 242 media::InitializeMediaLibrary(media_path); | 270 media::InitializeMediaLibrary(media_path); |
| 243 | 271 |
| 244 TRACE_EVENT_END_ETW("RenderThreadImpl::Init", 0, ""); | 272 TRACE_EVENT_END_ETW("RenderThreadImpl::Init", 0, ""); |
| (...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 982 | 1010 |
| 983 scoped_refptr<base::MessageLoopProxy> | 1011 scoped_refptr<base::MessageLoopProxy> |
| 984 RenderThreadImpl::GetFileThreadMessageLoopProxy() { | 1012 RenderThreadImpl::GetFileThreadMessageLoopProxy() { |
| 985 DCHECK(message_loop() == MessageLoop::current()); | 1013 DCHECK(message_loop() == MessageLoop::current()); |
| 986 if (!file_thread_.get()) { | 1014 if (!file_thread_.get()) { |
| 987 file_thread_.reset(new base::Thread("Renderer::FILE")); | 1015 file_thread_.reset(new base::Thread("Renderer::FILE")); |
| 988 file_thread_->Start(); | 1016 file_thread_->Start(); |
| 989 } | 1017 } |
| 990 return file_thread_->message_loop_proxy(); | 1018 return file_thread_->message_loop_proxy(); |
| 991 } | 1019 } |
| OLD | NEW |