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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 RenderThreadImpl::RenderThreadImpl() | 401 RenderThreadImpl::RenderThreadImpl() |
402 : ChildThread(Options(ShouldUseMojoChannel())) { | 402 : ChildThread(Options(ShouldUseMojoChannel())) { |
403 Init(); | 403 Init(); |
404 } | 404 } |
405 | 405 |
406 RenderThreadImpl::RenderThreadImpl(const std::string& channel_name) | 406 RenderThreadImpl::RenderThreadImpl(const std::string& channel_name) |
407 : ChildThread(Options(channel_name, ShouldUseMojoChannel())) { | 407 : ChildThread(Options(channel_name, ShouldUseMojoChannel())) { |
408 Init(); | 408 Init(); |
409 } | 409 } |
410 | 410 |
| 411 RenderThreadImpl::RenderThreadImpl( |
| 412 scoped_ptr<base::MessageLoop> main_message_loop) |
| 413 : ChildThread(Options(ShouldUseMojoChannel())), |
| 414 main_message_loop_(main_message_loop.Pass()) { |
| 415 Init(); |
| 416 } |
| 417 |
411 void RenderThreadImpl::Init() { | 418 void RenderThreadImpl::Init() { |
412 TRACE_EVENT_BEGIN_ETW("RenderThreadImpl::Init", 0, ""); | 419 TRACE_EVENT_BEGIN_ETW("RenderThreadImpl::Init", 0, ""); |
413 | 420 |
414 base::debug::TraceLog::GetInstance()->SetThreadSortIndex( | 421 base::debug::TraceLog::GetInstance()->SetThreadSortIndex( |
415 base::PlatformThread::CurrentId(), | 422 base::PlatformThread::CurrentId(), |
416 kTraceEventRendererMainThreadSortIndex); | 423 kTraceEventRendererMainThreadSortIndex); |
417 | 424 |
418 #if defined(OS_MACOSX) || defined(OS_ANDROID) | 425 #if defined(OS_MACOSX) || defined(OS_ANDROID) |
419 // On Mac and Android, the select popups are rendered by the browser. | 426 // On Mac and Android, the select popups are rendered by the browser. |
420 blink::WebView::setUseExternalPopupMenus(true); | 427 blink::WebView::setUseExternalPopupMenus(true); |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 // EmbeddedWorkerDispatcher. So it must be deleted before deleting | 665 // EmbeddedWorkerDispatcher. So it must be deleted before deleting |
659 // RenderThreadImpl. | 666 // RenderThreadImpl. |
660 embedded_worker_dispatcher_.reset(); | 667 embedded_worker_dispatcher_.reset(); |
661 | 668 |
662 // Ramp down IDB before we ramp down WebKit (and V8), since IDB classes might | 669 // Ramp down IDB before we ramp down WebKit (and V8), since IDB classes might |
663 // hold pointers to V8 objects (e.g., via pending requests). | 670 // hold pointers to V8 objects (e.g., via pending requests). |
664 main_thread_indexed_db_dispatcher_.reset(); | 671 main_thread_indexed_db_dispatcher_.reset(); |
665 | 672 |
666 main_thread_compositor_task_runner_ = NULL; | 673 main_thread_compositor_task_runner_ = NULL; |
667 | 674 |
668 if (blink_platform_impl_) | 675 if (gpu_channel_.get()) |
669 blink::shutdown(); | 676 gpu_channel_->DestroyChannel(); |
670 | |
671 lazy_tls.Pointer()->Set(NULL); | |
672 | 677 |
673 // TODO(port) | 678 // TODO(port) |
674 #if defined(OS_WIN) | 679 #if defined(OS_WIN) |
675 // Clean up plugin channels before this thread goes away. | 680 // Clean up plugin channels before this thread goes away. |
676 NPChannelBase::CleanupChannels(); | 681 NPChannelBase::CleanupChannels(); |
677 #endif | 682 #endif |
| 683 |
| 684 // Shut down the message loop before shutting down Blink. |
| 685 // This prevents a scenario where a pending task in the message loop accesses |
| 686 // Blink objects after Blink shuts down. |
| 687 // This must be at the very end of the shutdown sequence. You must not touch |
| 688 // the message loop after this. |
| 689 main_message_loop_.reset(); |
| 690 if (blink_platform_impl_) |
| 691 blink::shutdown(); |
| 692 |
| 693 lazy_tls.Pointer()->Set(NULL); |
678 } | 694 } |
679 | 695 |
680 bool RenderThreadImpl::Send(IPC::Message* msg) { | 696 bool RenderThreadImpl::Send(IPC::Message* msg) { |
681 // Certain synchronous messages cannot always be processed synchronously by | 697 // Certain synchronous messages cannot always be processed synchronously by |
682 // the browser, e.g., putting up UI and waiting for the user. This could cause | 698 // the browser, e.g., putting up UI and waiting for the user. This could cause |
683 // a complete hang of Chrome if a windowed plug-in is trying to communicate | 699 // a complete hang of Chrome if a windowed plug-in is trying to communicate |
684 // with the renderer thread since the browser's UI thread could be stuck | 700 // with the renderer thread since the browser's UI thread could be stuck |
685 // (within a Windows API call) trying to synchronously communicate with the | 701 // (within a Windows API call) trying to synchronously communicate with the |
686 // plug-in. The remedy is to pump messages on this thread while the browser | 702 // plug-in. The remedy is to pump messages on this thread while the browser |
687 // is processing this request. This creates an opportunity for re-entrancy | 703 // is processing this request. This creates an opportunity for re-entrancy |
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1593 hidden_widget_count_--; | 1609 hidden_widget_count_--; |
1594 | 1610 |
1595 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { | 1611 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { |
1596 return; | 1612 return; |
1597 } | 1613 } |
1598 | 1614 |
1599 ScheduleIdleHandler(kLongIdleHandlerDelayMs); | 1615 ScheduleIdleHandler(kLongIdleHandlerDelayMs); |
1600 } | 1616 } |
1601 | 1617 |
1602 } // namespace content | 1618 } // namespace content |
OLD | NEW |