| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 173 |
| 174 void RenderThreadImpl::Init() { | 174 void RenderThreadImpl::Init() { |
| 175 TRACE_EVENT_BEGIN_ETW("RenderThreadImpl::Init", 0, ""); | 175 TRACE_EVENT_BEGIN_ETW("RenderThreadImpl::Init", 0, ""); |
| 176 | 176 |
| 177 #if defined(OS_MACOSX) | 177 #if defined(OS_MACOSX) |
| 178 // On Mac, the select popups are rendered by the browser. | 178 // On Mac, the select popups are rendered by the browser. |
| 179 WebKit::WebView::setUseExternalPopupMenus(true); | 179 WebKit::WebView::setUseExternalPopupMenus(true); |
| 180 #endif | 180 #endif |
| 181 | 181 |
| 182 lazy_tls.Pointer()->Set(this); | 182 lazy_tls.Pointer()->Set(this); |
| 183 GpuChannelHostFactory::set_instance(this); |
| 184 |
| 183 #if defined(OS_WIN) | 185 #if defined(OS_WIN) |
| 184 // If you are running plugins in this thread you need COM active but in | 186 // If you are running plugins in this thread you need COM active but in |
| 185 // the normal case you don't. | 187 // the normal case you don't. |
| 186 if (RenderProcessImpl::InProcessPlugins()) | 188 if (RenderProcessImpl::InProcessPlugins()) |
| 187 initialize_com_.reset(new base::win::ScopedCOMInitializer()); | 189 initialize_com_.reset(new base::win::ScopedCOMInitializer()); |
| 188 #endif | 190 #endif |
| 189 | 191 |
| 190 // Register this object as the main thread. | 192 // Register this object as the main thread. |
| 191 ChildProcess::current()->set_main_thread(this); | 193 ChildProcess::current()->set_main_thread(this); |
| 192 | 194 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 } | 262 } |
| 261 #endif | 263 #endif |
| 262 if (compositor_thread_.get()) { | 264 if (compositor_thread_.get()) { |
| 263 RemoveFilter(compositor_thread_->GetMessageFilter()); | 265 RemoveFilter(compositor_thread_->GetMessageFilter()); |
| 264 compositor_thread_.reset(); | 266 compositor_thread_.reset(); |
| 265 } | 267 } |
| 266 | 268 |
| 267 if (webkit_platform_support_.get()) | 269 if (webkit_platform_support_.get()) |
| 268 WebKit::shutdown(); | 270 WebKit::shutdown(); |
| 269 | 271 |
| 272 GpuChannelHostFactory::set_instance(NULL); |
| 270 lazy_tls.Pointer()->Set(NULL); | 273 lazy_tls.Pointer()->Set(NULL); |
| 271 | 274 |
| 272 // TODO(port) | 275 // TODO(port) |
| 273 #if defined(OS_WIN) | 276 #if defined(OS_WIN) |
| 274 // Clean up plugin channels before this thread goes away. | 277 // Clean up plugin channels before this thread goes away. |
| 275 NPChannelBase::CleanupChannels(); | 278 NPChannelBase::CleanupChannels(); |
| 276 #endif | 279 #endif |
| 277 } | 280 } |
| 278 | 281 |
| 279 bool RenderThreadImpl::Send(IPC::Message* msg) { | 282 bool RenderThreadImpl::Send(IPC::Message* msg) { |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 void RenderThreadImpl::PreCacheFont(const LOGFONT& log_font) { | 673 void RenderThreadImpl::PreCacheFont(const LOGFONT& log_font) { |
| 671 Send(new ChildProcessHostMsg_PreCacheFont(log_font)); | 674 Send(new ChildProcessHostMsg_PreCacheFont(log_font)); |
| 672 } | 675 } |
| 673 | 676 |
| 674 void RenderThreadImpl::ReleaseCachedFonts() { | 677 void RenderThreadImpl::ReleaseCachedFonts() { |
| 675 Send(new ChildProcessHostMsg_ReleaseCachedFonts()); | 678 Send(new ChildProcessHostMsg_ReleaseCachedFonts()); |
| 676 } | 679 } |
| 677 | 680 |
| 678 #endif // OS_WIN | 681 #endif // OS_WIN |
| 679 | 682 |
| 683 bool RenderThreadImpl::IsMainThread() { |
| 684 return !!current(); |
| 685 } |
| 686 |
| 687 bool RenderThreadImpl::IsIOThread() { |
| 688 return MessageLoop::current() == ChildProcess::current()->io_message_loop(); |
| 689 } |
| 690 |
| 691 MessageLoop* RenderThreadImpl::GetMainLoop() { |
| 692 return message_loop(); |
| 693 } |
| 694 base::MessageLoopProxy* RenderThreadImpl::GetIOLoopProxy() { |
| 695 return ChildProcess::current()->io_message_loop_proxy(); |
| 696 } |
| 697 |
| 698 base::WaitableEvent* RenderThreadImpl::GetShutDownEvent() { |
| 699 return ChildProcess::current()->GetShutDownEvent(); |
| 700 } |
| 701 |
| 702 scoped_ptr<base::SharedMemory> RenderThreadImpl::AllocateSharedMemory( |
| 703 uint32 size) { |
| 704 if (!IsMainThread()) |
| 705 return scoped_ptr<base::SharedMemory>(); |
| 706 base::SharedMemoryHandle handle; |
| 707 if (!ChildThread::Send(new ChildProcessHostMsg_SyncAllocateSharedMemory( |
| 708 size, |
| 709 &handle))) { |
| 710 return scoped_ptr<base::SharedMemory>(); |
| 711 } |
| 712 if (!base::SharedMemory::IsHandleValid(handle)) |
| 713 return scoped_ptr<base::SharedMemory>(); |
| 714 return scoped_ptr<base::SharedMemory>(new base::SharedMemory(handle, false)); |
| 715 } |
| 716 |
| 717 int32 RenderThreadImpl::CreateViewCommandBuffer( |
| 718 int32 surface_id, const GPUCreateCommandBufferConfig& init_params) { |
| 719 int32 route_id = MSG_ROUTING_NONE; |
| 720 ChildThread::Send(new GpuHostMsg_CreateViewCommandBuffer( |
| 721 surface_id, |
| 722 init_params, |
| 723 &route_id)); |
| 724 return route_id; |
| 725 } |
| 726 |
| 680 int32 RenderThreadImpl::RoutingIDForCurrentContext() { | 727 int32 RenderThreadImpl::RoutingIDForCurrentContext() { |
| 681 int32 routing_id = MSG_ROUTING_CONTROL; | 728 int32 routing_id = MSG_ROUTING_CONTROL; |
| 682 if (v8::Context::InContext()) { | 729 if (v8::Context::InContext()) { |
| 683 WebFrame* frame = WebFrame::frameForCurrentContext(); | 730 WebFrame* frame = WebFrame::frameForCurrentContext(); |
| 684 if (frame) { | 731 if (frame) { |
| 685 RenderViewImpl* view = RenderViewImpl::FromWebView(frame->view()); | 732 RenderViewImpl* view = RenderViewImpl::FromWebView(frame->view()); |
| 686 if (view) | 733 if (view) |
| 687 routing_id = view->routing_id(); | 734 routing_id = view->routing_id(); |
| 688 } | 735 } |
| 689 } else { | 736 } else { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 if (gpu_channel_->state() == GpuChannelHost::kUnconnected || | 838 if (gpu_channel_->state() == GpuChannelHost::kUnconnected || |
| 792 gpu_channel_->state() == GpuChannelHost::kConnected) | 839 gpu_channel_->state() == GpuChannelHost::kConnected) |
| 793 return GetGpuChannel(); | 840 return GetGpuChannel(); |
| 794 | 841 |
| 795 // Recreate the channel if it has been lost. | 842 // Recreate the channel if it has been lost. |
| 796 if (gpu_channel_->state() == GpuChannelHost::kLost) | 843 if (gpu_channel_->state() == GpuChannelHost::kLost) |
| 797 gpu_channel_ = NULL; | 844 gpu_channel_ = NULL; |
| 798 } | 845 } |
| 799 | 846 |
| 800 if (!gpu_channel_.get()) | 847 if (!gpu_channel_.get()) |
| 801 gpu_channel_ = new GpuChannelHost; | 848 gpu_channel_ = new GpuChannelHost(this); |
| 802 | 849 |
| 803 // Ask the browser for the channel name. | 850 // Ask the browser for the channel name. |
| 804 IPC::ChannelHandle channel_handle; | 851 IPC::ChannelHandle channel_handle; |
| 805 base::ProcessHandle renderer_process_for_gpu; | 852 base::ProcessHandle renderer_process_for_gpu; |
| 806 content::GPUInfo gpu_info; | 853 content::GPUInfo gpu_info; |
| 807 if (!Send(new GpuHostMsg_EstablishGpuChannel(cause_for_gpu_launch, | 854 if (!Send(new GpuHostMsg_EstablishGpuChannel(cause_for_gpu_launch, |
| 808 &channel_handle, | 855 &channel_handle, |
| 809 &renderer_process_for_gpu, | 856 &renderer_process_for_gpu, |
| 810 &gpu_info)) || | 857 &gpu_info)) || |
| 811 channel_handle.name.empty() || | 858 channel_handle.name.empty() || |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 | 912 |
| 866 scoped_refptr<base::MessageLoopProxy> | 913 scoped_refptr<base::MessageLoopProxy> |
| 867 RenderThreadImpl::GetFileThreadMessageLoopProxy() { | 914 RenderThreadImpl::GetFileThreadMessageLoopProxy() { |
| 868 DCHECK(message_loop() == MessageLoop::current()); | 915 DCHECK(message_loop() == MessageLoop::current()); |
| 869 if (!file_thread_.get()) { | 916 if (!file_thread_.get()) { |
| 870 file_thread_.reset(new base::Thread("Renderer::FILE")); | 917 file_thread_.reset(new base::Thread("Renderer::FILE")); |
| 871 file_thread_->Start(); | 918 file_thread_->Start(); |
| 872 } | 919 } |
| 873 return file_thread_->message_loop_proxy(); | 920 return file_thread_->message_loop_proxy(); |
| 874 } | 921 } |
| OLD | NEW |