OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "chrome/browser/renderer_host/browser_render_process_host.h" | 8 #include "chrome/browser/renderer_host/browser_render_process_host.h" |
9 | 9 |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "chrome/browser/visitedlink_master.h" | 47 #include "chrome/browser/visitedlink_master.h" |
48 #include "chrome/common/chrome_switches.h" | 48 #include "chrome/common/chrome_switches.h" |
49 #include "chrome/common/chrome_descriptors.h" | 49 #include "chrome/common/chrome_descriptors.h" |
50 #include "chrome/common/child_process_info.h" | 50 #include "chrome/common/child_process_info.h" |
51 #include "chrome/common/logging_chrome.h" | 51 #include "chrome/common/logging_chrome.h" |
52 #include "chrome/common/notification_service.h" | 52 #include "chrome/common/notification_service.h" |
53 #include "chrome/common/process_watcher.h" | 53 #include "chrome/common/process_watcher.h" |
54 #include "chrome/common/render_messages.h" | 54 #include "chrome/common/render_messages.h" |
55 #include "chrome/common/result_codes.h" | 55 #include "chrome/common/result_codes.h" |
56 #include "chrome/renderer/render_process.h" | 56 #include "chrome/renderer/render_process.h" |
57 #include "chrome/renderer/render_thread.h" | |
58 #include "chrome/installer/util/google_update_settings.h" | 57 #include "chrome/installer/util/google_update_settings.h" |
59 #include "grit/generated_resources.h" | 58 #include "grit/generated_resources.h" |
60 | 59 |
61 #if defined(OS_WIN) | 60 #if defined(OS_WIN) |
62 #include "app/win_util.h" | 61 #include "app/win_util.h" |
63 #include "chrome/browser/sandbox_policy.h" | 62 #include "chrome/browser/sandbox_policy.h" |
64 #elif defined(OS_LINUX) | 63 #elif defined(OS_LINUX) |
65 #include "base/linux_util.h" | 64 #include "base/linux_util.h" |
66 #include "chrome/browser/zygote_host_linux.h" | 65 #include "chrome/browser/zygote_host_linux.h" |
67 #include "chrome/browser/renderer_host/render_crash_handler_host_linux.h" | 66 #include "chrome/browser/renderer_host/render_crash_handler_host_linux.h" |
(...skipping 18 matching lines...) Expand all Loading... |
86 ~RendererMainThread() { | 85 ~RendererMainThread() { |
87 Stop(); | 86 Stop(); |
88 } | 87 } |
89 | 88 |
90 protected: | 89 protected: |
91 virtual void Init() { | 90 virtual void Init() { |
92 #if defined(OS_WIN) | 91 #if defined(OS_WIN) |
93 CoInitialize(NULL); | 92 CoInitialize(NULL); |
94 #endif | 93 #endif |
95 | 94 |
96 render_process_ = new RenderProcess(); | 95 render_process_ = new RenderProcess(channel_id_); |
97 render_process_->set_main_thread(new RenderThread(channel_id_)); | |
98 // It's a little lame to manually set this flag. But the single process | 96 // It's a little lame to manually set this flag. But the single process |
99 // RendererThread will receive the WM_QUIT. We don't need to assert on | 97 // RendererThread will receive the WM_QUIT. We don't need to assert on |
100 // this thread, so just force the flag manually. | 98 // this thread, so just force the flag manually. |
101 // If we want to avoid this, we could create the InProcRendererThread | 99 // If we want to avoid this, we could create the InProcRendererThread |
102 // directly with _beginthreadex() rather than using the Thread class. | 100 // directly with _beginthreadex() rather than using the Thread class. |
103 base::Thread::SetThreadWasQuitProperly(true); | 101 base::Thread::SetThreadWasQuitProperly(true); |
104 } | 102 } |
105 | 103 |
106 virtual void CleanUp() { | 104 virtual void CleanUp() { |
107 delete render_process_; | 105 delete render_process_; |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 404 |
407 const std::wstring& profile_path = | 405 const std::wstring& profile_path = |
408 browser_command_line.GetSwitchValue(switches::kUserDataDir); | 406 browser_command_line.GetSwitchValue(switches::kUserDataDir); |
409 if (!profile_path.empty()) | 407 if (!profile_path.empty()) |
410 cmd_line.AppendSwitchWithValue(switches::kUserDataDir, | 408 cmd_line.AppendSwitchWithValue(switches::kUserDataDir, |
411 profile_path); | 409 profile_path); |
412 | 410 |
413 if (run_renderer_in_process()) { | 411 if (run_renderer_in_process()) { |
414 // Crank up a thread and run the initialization there. With the way that | 412 // Crank up a thread and run the initialization there. With the way that |
415 // messages flow between the browser and renderer, this thread is required | 413 // messages flow between the browser and renderer, this thread is required |
416 // to prevent a deadlock in single-process mode. Since the primordial | 414 // to prevent a deadlock in single-process mode. When using multiple |
417 // thread in the renderer process runs the WebKit code and can sometimes | 415 // processes, the primordial thread in the renderer process has a message |
418 // blocking calls to the UI thread (i.e. this thread), they need to run on | 416 // loop which is used for sending messages asynchronously to the io thread |
419 // separate threads. | 417 // in the browser process. If we don't create this thread, then the |
| 418 // RenderThread is both responsible for rendering and also for |
| 419 // communicating IO. This can lead to deadlocks where the RenderThread is |
| 420 // waiting for the IO to complete, while the browsermain is trying to pass |
| 421 // an event to the RenderThread. |
420 in_process_renderer_.reset(new RendererMainThread(channel_id)); | 422 in_process_renderer_.reset(new RendererMainThread(channel_id)); |
421 | 423 |
422 base::Thread::Options options; | 424 base::Thread::Options options; |
423 options.message_loop_type = MessageLoop::TYPE_UI; | 425 options.message_loop_type = MessageLoop::TYPE_IO; |
424 in_process_renderer_->StartWithOptions(options); | 426 in_process_renderer_->StartWithOptions(options); |
425 } else { | 427 } else { |
426 base::ProcessHandle process = 0; | 428 base::ProcessHandle process = 0; |
427 #if defined(OS_WIN) | 429 #if defined(OS_WIN) |
428 process = sandbox::StartProcess(&cmd_line); | 430 process = sandbox::StartProcess(&cmd_line); |
429 #elif defined(OS_POSIX) | 431 #elif defined(OS_POSIX) |
430 #if defined(OS_LINUX) | 432 #if defined(OS_LINUX) |
431 if (!has_cmd_prefix) { | 433 if (!has_cmd_prefix) { |
432 base::GlobalDescriptors::Mapping mapping; | 434 base::GlobalDescriptors::Mapping mapping; |
433 const int ipcfd = channel_->GetClientFileDescriptor(); | 435 const int ipcfd = channel_->GetClientFileDescriptor(); |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 profile()->GetExtensionMessageService()->RemoveEventListener(event_name, | 975 profile()->GetExtensionMessageService()->RemoveEventListener(event_name, |
974 pid()); | 976 pid()); |
975 } | 977 } |
976 } | 978 } |
977 | 979 |
978 void BrowserRenderProcessHost::OnExtensionCloseChannel(int port_id) { | 980 void BrowserRenderProcessHost::OnExtensionCloseChannel(int port_id) { |
979 if (profile()->GetExtensionMessageService()) { | 981 if (profile()->GetExtensionMessageService()) { |
980 profile()->GetExtensionMessageService()->CloseChannel(port_id); | 982 profile()->GetExtensionMessageService()->CloseChannel(port_id); |
981 } | 983 } |
982 } | 984 } |
OLD | NEW |