| 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 <utility> | 10 #include <utility> |
| (...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 #endif | 615 #endif |
| 616 | 616 |
| 617 lazy_tls.Pointer()->Set(this); | 617 lazy_tls.Pointer()->Set(this); |
| 618 | 618 |
| 619 // Register this object as the main thread. | 619 // Register this object as the main thread. |
| 620 ChildProcess::current()->set_main_thread(this); | 620 ChildProcess::current()->set_main_thread(this); |
| 621 | 621 |
| 622 InitializeWebKit(resource_task_queue); | 622 InitializeWebKit(resource_task_queue); |
| 623 | 623 |
| 624 // In single process the single process is all there is. | 624 // In single process the single process is all there is. |
| 625 notify_webkit_of_modal_loop_ = true; | |
| 626 webkit_shared_timer_suspended_ = false; | 625 webkit_shared_timer_suspended_ = false; |
| 627 widget_count_ = 0; | 626 widget_count_ = 0; |
| 628 hidden_widget_count_ = 0; | 627 hidden_widget_count_ = 0; |
| 629 idle_notification_delay_in_ms_ = kInitialIdleHandlerDelayMs; | 628 idle_notification_delay_in_ms_ = kInitialIdleHandlerDelayMs; |
| 630 idle_notifications_to_skip_ = 0; | 629 idle_notifications_to_skip_ = 0; |
| 631 layout_test_mode_ = false; | 630 layout_test_mode_ = false; |
| 632 | 631 |
| 633 appcache_dispatcher_.reset( | 632 appcache_dispatcher_.reset( |
| 634 new AppCacheDispatcher(Get(), new AppCacheFrontendImpl())); | 633 new AppCacheDispatcher(Get(), new AppCacheFrontendImpl())); |
| 635 dom_storage_dispatcher_.reset(new DomStorageDispatcher()); | 634 dom_storage_dispatcher_.reset(new DomStorageDispatcher()); |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 | 949 |
| 951 // The message loop must be cleared after shutting down | 950 // The message loop must be cleared after shutting down |
| 952 // the DiscardableSharedMemoryManager, which needs to send messages | 951 // the DiscardableSharedMemoryManager, which needs to send messages |
| 953 // to the browser process. | 952 // to the browser process. |
| 954 main_message_loop_.reset(); | 953 main_message_loop_.reset(); |
| 955 | 954 |
| 956 lazy_tls.Pointer()->Set(NULL); | 955 lazy_tls.Pointer()->Set(NULL); |
| 957 } | 956 } |
| 958 | 957 |
| 959 bool RenderThreadImpl::Send(IPC::Message* msg) { | 958 bool RenderThreadImpl::Send(IPC::Message* msg) { |
| 960 // Certain synchronous messages cannot always be processed synchronously by | 959 // There are cases where we want to pump asynchronous messages while waiting |
| 961 // the browser, e.g., putting up UI and waiting for the user. This could cause | 960 // synchronously for the replies to the message to be sent here. However, this |
| 962 // a complete hang of Chrome if a windowed plugin is trying to communicate | 961 // may create an opportunity for re-entrancy into WebKit and other subsystems, |
| 963 // with the renderer thread since the browser's UI thread could be stuck | 962 // so we need to take care to disable callbacks, timers, and pending network |
| 964 // (within a Windows API call) trying to synchronously communicate with the | 963 // loads that could trigger such callbacks. |
| 965 // plugin. The remedy is to pump messages on this thread while the browser | |
| 966 // is processing this request. This creates an opportunity for re-entrancy | |
| 967 // into WebKit, so we need to take care to disable callbacks, timers, and | |
| 968 // pending network loads that could trigger such callbacks. | |
| 969 bool pumping_events = false; | 964 bool pumping_events = false; |
| 970 if (msg->is_sync()) { | 965 if (msg->is_sync()) { |
| 971 if (msg->is_caller_pumping_messages()) { | 966 if (msg->is_caller_pumping_messages()) { |
| 972 pumping_events = true; | 967 pumping_events = true; |
| 973 } | 968 } |
| 974 } | 969 } |
| 975 | 970 |
| 976 bool notify_webkit_of_modal_loop = true; // default value | |
| 977 std::swap(notify_webkit_of_modal_loop, notify_webkit_of_modal_loop_); | |
| 978 | |
| 979 if (pumping_events) { | 971 if (pumping_events) { |
| 980 renderer_scheduler_->SuspendTimerQueue(); | 972 renderer_scheduler_->SuspendTimerQueue(); |
| 981 | 973 WebView::willEnterModalLoop(); |
| 982 if (notify_webkit_of_modal_loop) | |
| 983 WebView::willEnterModalLoop(); | |
| 984 } | 974 } |
| 985 | 975 |
| 986 bool rv = ChildThreadImpl::Send(msg); | 976 bool rv = ChildThreadImpl::Send(msg); |
| 987 | 977 |
| 988 if (pumping_events) { | 978 if (pumping_events) { |
| 989 if (notify_webkit_of_modal_loop) | 979 WebView::didExitModalLoop(); |
| 990 WebView::didExitModalLoop(); | |
| 991 | |
| 992 renderer_scheduler_->ResumeTimerQueue(); | 980 renderer_scheduler_->ResumeTimerQueue(); |
| 993 } | 981 } |
| 994 | 982 |
| 995 return rv; | 983 return rv; |
| 996 } | 984 } |
| 997 | 985 |
| 998 IPC::SyncChannel* RenderThreadImpl::GetChannel() { | 986 IPC::SyncChannel* RenderThreadImpl::GetChannel() { |
| 999 return channel(); | 987 return channel(); |
| 1000 } | 988 } |
| 1001 | 989 |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1645 scoped_refptr<base::SingleThreadTaskRunner> | 1633 scoped_refptr<base::SingleThreadTaskRunner> |
| 1646 RenderThreadImpl::GetIOThreadTaskRunner() { | 1634 RenderThreadImpl::GetIOThreadTaskRunner() { |
| 1647 return io_thread_task_runner_; | 1635 return io_thread_task_runner_; |
| 1648 } | 1636 } |
| 1649 | 1637 |
| 1650 std::unique_ptr<base::SharedMemory> RenderThreadImpl::AllocateSharedMemory( | 1638 std::unique_ptr<base::SharedMemory> RenderThreadImpl::AllocateSharedMemory( |
| 1651 size_t size) { | 1639 size_t size) { |
| 1652 return HostAllocateSharedMemoryBuffer(size); | 1640 return HostAllocateSharedMemoryBuffer(size); |
| 1653 } | 1641 } |
| 1654 | 1642 |
| 1655 void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() { | |
| 1656 notify_webkit_of_modal_loop_ = false; | |
| 1657 } | |
| 1658 | |
| 1659 void RenderThreadImpl::OnChannelError() { | 1643 void RenderThreadImpl::OnChannelError() { |
| 1660 // In single-process mode, the renderer can't be restarted after shutdown. | 1644 // In single-process mode, the renderer can't be restarted after shutdown. |
| 1661 // So, if we get a channel error, crash the whole process right now to get a | 1645 // So, if we get a channel error, crash the whole process right now to get a |
| 1662 // more informative stack, since we will otherwise just crash later when we | 1646 // more informative stack, since we will otherwise just crash later when we |
| 1663 // try to restart it. | 1647 // try to restart it. |
| 1664 CHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( | 1648 CHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1665 switches::kSingleProcess)); | 1649 switches::kSingleProcess)); |
| 1666 ChildThreadImpl::OnChannelError(); | 1650 ChildThreadImpl::OnChannelError(); |
| 1667 } | 1651 } |
| 1668 | 1652 |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2104 v8_memory_pressure_level == v8::MemoryPressureLevel::kCritical) | 2088 v8_memory_pressure_level == v8::MemoryPressureLevel::kCritical) |
| 2105 v8_memory_pressure_level = v8::MemoryPressureLevel::kModerate; | 2089 v8_memory_pressure_level = v8::MemoryPressureLevel::kModerate; |
| 2106 | 2090 |
| 2107 blink::mainThreadIsolate()->MemoryPressureNotification( | 2091 blink::mainThreadIsolate()->MemoryPressureNotification( |
| 2108 v8_memory_pressure_level); | 2092 v8_memory_pressure_level); |
| 2109 blink::MemoryPressureNotificationToWorkerThreadIsolates( | 2093 blink::MemoryPressureNotificationToWorkerThreadIsolates( |
| 2110 v8_memory_pressure_level); | 2094 v8_memory_pressure_level); |
| 2111 } | 2095 } |
| 2112 | 2096 |
| 2113 } // namespace content | 2097 } // namespace content |
| OLD | NEW |