| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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" |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 | 13 |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/debug_util.h" | 15 #include "base/debug_util.h" |
| 16 #include "base/linked_ptr.h" |
| 16 #include "base/logging.h" | 17 #include "base/logging.h" |
| 17 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 18 #include "base/process_util.h" | 19 #include "base/process_util.h" |
| 19 #include "base/rand_util.h" | 20 #include "base/rand_util.h" |
| 20 #include "base/shared_memory.h" | 21 #include "base/shared_memory.h" |
| 22 #include "base/singleton.h" |
| 21 #include "base/string_util.h" | 23 #include "base/string_util.h" |
| 22 #include "base/thread.h" | 24 #include "base/thread.h" |
| 23 #include "chrome/app/result_codes.h" | 25 #include "chrome/app/result_codes.h" |
| 24 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/cache_manager_host.h" | 27 #include "chrome/browser/cache_manager_host.h" |
| 26 #include "chrome/browser/extensions/user_script_master.h" | 28 #include "chrome/browser/extensions/user_script_master.h" |
| 27 #include "chrome/browser/history/history.h" | 29 #include "chrome/browser/history/history.h" |
| 28 #include "chrome/browser/profile.h" | 30 #include "chrome/browser/profile.h" |
| 29 #include "chrome/browser/renderer_host/render_widget_helper.h" | 31 #include "chrome/browser/renderer_host/render_widget_helper.h" |
| 30 #include "chrome/browser/renderer_host/renderer_security_policy.h" | 32 #include "chrome/browser/renderer_host/renderer_security_policy.h" |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 // Crank up a thread and run the initialization there. With the way that | 321 // Crank up a thread and run the initialization there. With the way that |
| 320 // messages flow between the browser and renderer, this thread is required | 322 // messages flow between the browser and renderer, this thread is required |
| 321 // to prevent a deadlock in single-process mode. When using multiple | 323 // to prevent a deadlock in single-process mode. When using multiple |
| 322 // processes, the primordial thread in the renderer process has a message | 324 // processes, the primordial thread in the renderer process has a message |
| 323 // loop which is used for sending messages asynchronously to the io thread | 325 // loop which is used for sending messages asynchronously to the io thread |
| 324 // in the browser process. If we don't create this thread, then the | 326 // in the browser process. If we don't create this thread, then the |
| 325 // RenderThread is both responsible for rendering and also for | 327 // RenderThread is both responsible for rendering and also for |
| 326 // communicating IO. This can lead to deadlocks where the RenderThread is | 328 // communicating IO. This can lead to deadlocks where the RenderThread is |
| 327 // waiting for the IO to complete, while the browsermain is trying to pass | 329 // waiting for the IO to complete, while the browsermain is trying to pass |
| 328 // an event to the RenderThread. | 330 // an event to the RenderThread. |
| 329 // | 331 RendererMainThread* render_thread = new RendererMainThread(channel_id); |
| 330 // TODO: We should consider how to better cleanup threads on exit. | 332 |
| 331 base::Thread *render_thread = new RendererMainThread(channel_id); | 333 // This singleton keeps track of our pointers to avoid a leak. |
| 334 Singleton<std::vector<linked_ptr<RendererMainThread> > >::get()->push_back( |
| 335 linked_ptr<RendererMainThread>(render_thread)); |
| 336 |
| 332 base::Thread::Options options; | 337 base::Thread::Options options; |
| 333 options.message_loop_type = MessageLoop::TYPE_IO; | 338 options.message_loop_type = MessageLoop::TYPE_IO; |
| 334 render_thread->StartWithOptions(options); | 339 render_thread->StartWithOptions(options); |
| 335 } else { | 340 } else { |
| 336 if (g_browser_process->local_state() && | 341 if (g_browser_process->local_state() && |
| 337 g_browser_process->local_state()->GetBoolean( | 342 g_browser_process->local_state()->GetBoolean( |
| 338 prefs::kStartRenderersManually)) { | 343 prefs::kStartRenderersManually)) { |
| 339 RunStartRenderersManuallyDialog(cmd_line); | 344 RunStartRenderersManuallyDialog(cmd_line); |
| 340 } else { | 345 } else { |
| 341 #if defined(OS_WIN) | 346 #if defined(OS_WIN) |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 // child processes determine the pid of the parent. | 819 // child processes determine the pid of the parent. |
| 815 // Build the channel ID. This is composed of a unique identifier for the | 820 // Build the channel ID. This is composed of a unique identifier for the |
| 816 // parent browser process, an identifier for the renderer/plugin instance, | 821 // parent browser process, an identifier for the renderer/plugin instance, |
| 817 // and a random component. We use a random component so that a hacked child | 822 // and a random component. We use a random component so that a hacked child |
| 818 // process can't cause denial of service by causing future named pipe creation | 823 // process can't cause denial of service by causing future named pipe creation |
| 819 // to fail. | 824 // to fail. |
| 820 return StringPrintf(L"%d.%x.%d", | 825 return StringPrintf(L"%d.%x.%d", |
| 821 base::GetCurrentProcId(), instance, | 826 base::GetCurrentProcId(), instance, |
| 822 base::RandInt(0, std::numeric_limits<int>::max())); | 827 base::RandInt(0, std::numeric_limits<int>::max())); |
| 823 } | 828 } |
| OLD | NEW |