OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 // Represents the browser side of the browser <--> renderer communication | 5 // Represents the browser side of the browser <--> renderer communication |
6 // channel. There will be one RenderProcessHost per renderer process. | 6 // channel. There will be one RenderProcessHost per renderer process. |
7 | 7 |
8 #include "content/browser/renderer_host/render_process_host_impl.h" | 8 #include "content/browser/renderer_host/render_process_host_impl.h" |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 cmd_line->PrependWrapper(renderer_prefix); | 965 cmd_line->PrependWrapper(renderer_prefix); |
966 AppendRendererCommandLine(cmd_line); | 966 AppendRendererCommandLine(cmd_line); |
967 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 967 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); |
968 | 968 |
969 // Spawn the child process asynchronously to avoid blocking the UI thread. | 969 // Spawn the child process asynchronously to avoid blocking the UI thread. |
970 // As long as there's no renderer prefix, we can use the zygote process | 970 // As long as there's no renderer prefix, we can use the zygote process |
971 // at this stage. | 971 // at this stage. |
972 child_process_launcher_.reset(new ChildProcessLauncher( | 972 child_process_launcher_.reset(new ChildProcessLauncher( |
973 new RendererSandboxedProcessLauncherDelegate(channel_.get()), cmd_line, | 973 new RendererSandboxedProcessLauncherDelegate(channel_.get()), cmd_line, |
974 GetID(), this, child_token_, | 974 GetID(), this, child_token_, |
975 base::Bind(&RenderProcessHostImpl::OnMojoError, | 975 base::Bind(&RenderProcessHostImpl::OnMojoError, id_))); |
976 weak_factory_.GetWeakPtr(), | |
977 base::ThreadTaskRunnerHandle::Get()))); | |
978 channel_->Pause(); | 976 channel_->Pause(); |
979 | 977 |
980 fast_shutdown_started_ = false; | 978 fast_shutdown_started_ = false; |
981 } | 979 } |
982 | 980 |
983 // Push any pending messages to the channel now. Note that if the child | 981 // Push any pending messages to the channel now. Note that if the child |
984 // process is still launching, the channel will be paused and outgoing | 982 // process is still launching, the channel will be paused and outgoing |
985 // messages will be queued internally by the channel. | 983 // messages will be queued internally by the channel. |
986 while (!queued_messages_.empty()) { | 984 while (!queued_messages_.empty()) { |
987 channel_->Send(queued_messages_.front().release()); | 985 channel_->Send(queued_messages_.front().release()); |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1456 | 1454 |
1457 void RenderProcessHostImpl::AddObserver(RenderProcessHostObserver* observer) { | 1455 void RenderProcessHostImpl::AddObserver(RenderProcessHostObserver* observer) { |
1458 observers_.AddObserver(observer); | 1456 observers_.AddObserver(observer); |
1459 } | 1457 } |
1460 | 1458 |
1461 void RenderProcessHostImpl::RemoveObserver( | 1459 void RenderProcessHostImpl::RemoveObserver( |
1462 RenderProcessHostObserver* observer) { | 1460 RenderProcessHostObserver* observer) { |
1463 observers_.RemoveObserver(observer); | 1461 observers_.RemoveObserver(observer); |
1464 } | 1462 } |
1465 | 1463 |
1466 void RenderProcessHostImpl::ShutdownForBadMessage() { | 1464 void RenderProcessHostImpl::ShutdownForBadMessage( |
| 1465 CrashReportMode crash_report_mode) { |
1467 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 1466 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
1468 if (command_line->HasSwitch(switches::kDisableKillAfterBadIPC)) | 1467 if (command_line->HasSwitch(switches::kDisableKillAfterBadIPC)) |
1469 return; | 1468 return; |
1470 | 1469 |
1471 if (run_renderer_in_process()) { | 1470 if (run_renderer_in_process()) { |
1472 // In single process mode it is better if we don't suicide but just | 1471 // In single process mode it is better if we don't suicide but just |
1473 // crash. | 1472 // crash. |
1474 CHECK(false); | 1473 CHECK(false); |
1475 } | 1474 } |
1476 | 1475 |
1477 // We kill the renderer but don't include a NOTREACHED, because we want the | 1476 // We kill the renderer but don't include a NOTREACHED, because we want the |
1478 // browser to try to survive when it gets illegal messages from the renderer. | 1477 // browser to try to survive when it gets illegal messages from the renderer. |
1479 Shutdown(RESULT_CODE_KILLED_BAD_MESSAGE, false); | 1478 Shutdown(RESULT_CODE_KILLED_BAD_MESSAGE, false); |
1480 | 1479 |
1481 // Report a crash, since none will be generated by the killed renderer. | 1480 if (crash_report_mode == CrashReportMode::GENERATE_CRASH_DUMP) { |
1482 base::debug::DumpWithoutCrashing(); | 1481 // Report a crash, since none will be generated by the killed renderer. |
| 1482 base::debug::DumpWithoutCrashing(); |
| 1483 } |
1483 | 1484 |
1484 // Log the renderer kill to the histogram tracking all kills. | 1485 // Log the renderer kill to the histogram tracking all kills. |
1485 BrowserChildProcessHostImpl::HistogramBadMessageTerminated( | 1486 BrowserChildProcessHostImpl::HistogramBadMessageTerminated( |
1486 PROCESS_TYPE_RENDERER); | 1487 PROCESS_TYPE_RENDERER); |
1487 } | 1488 } |
1488 | 1489 |
1489 void RenderProcessHostImpl::WidgetRestored() { | 1490 void RenderProcessHostImpl::WidgetRestored() { |
1490 visible_widgets_++; | 1491 visible_widgets_++; |
1491 UpdateProcessPriority(); | 1492 UpdateProcessPriority(); |
1492 DCHECK(!is_process_backgrounded_); | 1493 DCHECK(!is_process_backgrounded_); |
(...skipping 1531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3024 | 3025 |
3025 // Skip widgets in other processes. | 3026 // Skip widgets in other processes. |
3026 if (rvh->GetProcess()->GetID() != GetID()) | 3027 if (rvh->GetProcess()->GetID() != GetID()) |
3027 continue; | 3028 continue; |
3028 | 3029 |
3029 rvh->OnWebkitPreferencesChanged(); | 3030 rvh->OnWebkitPreferencesChanged(); |
3030 } | 3031 } |
3031 } | 3032 } |
3032 | 3033 |
3033 // static | 3034 // static |
3034 void RenderProcessHostImpl::OnMojoError( | 3035 void RenderProcessHostImpl::OnMojoError(int render_process_id, |
3035 base::WeakPtr<RenderProcessHostImpl> process, | 3036 const std::string& error) { |
3036 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
3037 const std::string& error) { | |
3038 if (!task_runner->BelongsToCurrentThread()) { | |
3039 task_runner->PostTask(FROM_HERE, | |
3040 base::Bind(&RenderProcessHostImpl::OnMojoError, | |
3041 process, task_runner, error)); | |
3042 return; | |
3043 } | |
3044 if (!process) | |
3045 return; | |
3046 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 3037 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
3047 | 3038 |
3048 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias | 3039 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias |
3049 // enough information here so that we can determine what the bad message was. | 3040 // enough information here so that we can determine what the bad message was. |
3050 base::debug::Alias(&error); | 3041 base::debug::Alias(&error); |
3051 bad_message::ReceivedBadMessage(process.get(), | 3042 bad_message::ReceivedBadMessage(render_process_id, |
3052 bad_message::RPH_MOJO_PROCESS_ERROR); | 3043 bad_message::RPH_MOJO_PROCESS_ERROR); |
3053 } | 3044 } |
3054 | 3045 |
3055 } // namespace content | 3046 } // namespace content |
OLD | NEW |