OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/service/service_utility_process_host.h" | 5 #include "chrome/service/service_utility_process_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
14 #include "base/scoped_temp_dir.h" | 14 #include "base/scoped_temp_dir.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/chrome_utility_messages.h" | 17 #include "chrome/common/chrome_utility_messages.h" |
18 #include "content/common/child_process_host.h" | 18 #include "content/public/common/child_process_host.h" |
19 #include "content/public/common/result_codes.h" | 19 #include "content/public/common/result_codes.h" |
20 #include "ipc/ipc_switches.h" | 20 #include "ipc/ipc_switches.h" |
21 #include "printing/page_range.h" | 21 #include "printing/page_range.h" |
22 #include "ui/base/ui_base_switches.h" | 22 #include "ui/base/ui_base_switches.h" |
23 #include "ui/gfx/rect.h" | 23 #include "ui/gfx/rect.h" |
24 | 24 |
25 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
26 #include "base/file_path.h" | 26 #include "base/file_path.h" |
27 #include "base/memory/scoped_ptr.h" | 27 #include "base/memory/scoped_ptr.h" |
28 #include "base/win/scoped_handle.h" | 28 #include "base/win/scoped_handle.h" |
29 #include "content/common/sandbox_policy.h" | 29 #include "content/common/sandbox_policy.h" |
30 #include "printing/emf_win.h" | 30 #include "printing/emf_win.h" |
31 #endif | 31 #endif |
32 | 32 |
| 33 using content::ChildProcessHost; |
| 34 |
33 ServiceUtilityProcessHost::ServiceUtilityProcessHost( | 35 ServiceUtilityProcessHost::ServiceUtilityProcessHost( |
34 Client* client, base::MessageLoopProxy* client_message_loop_proxy) | 36 Client* client, base::MessageLoopProxy* client_message_loop_proxy) |
35 : handle_(base::kNullProcessHandle), | 37 : handle_(base::kNullProcessHandle), |
36 client_(client), | 38 client_(client), |
37 client_message_loop_proxy_(client_message_loop_proxy), | 39 client_message_loop_proxy_(client_message_loop_proxy), |
38 waiting_for_reply_(false) { | 40 waiting_for_reply_(false) { |
39 child_process_host_.reset(new ChildProcessHost(this)); | 41 child_process_host_.reset(ChildProcessHost::Create(this)); |
40 } | 42 } |
41 | 43 |
42 ServiceUtilityProcessHost::~ServiceUtilityProcessHost() { | 44 ServiceUtilityProcessHost::~ServiceUtilityProcessHost() { |
43 // We need to kill the child process when the host dies. | 45 // We need to kill the child process when the host dies. |
44 base::KillProcess(handle_, content::RESULT_CODE_NORMAL_EXIT, false); | 46 base::KillProcess(handle_, content::RESULT_CODE_NORMAL_EXIT, false); |
45 } | 47 } |
46 | 48 |
47 bool ServiceUtilityProcessHost::StartRenderPDFPagesToMetafile( | 49 bool ServiceUtilityProcessHost::StartRenderPDFPagesToMetafile( |
48 const FilePath& pdf_path, | 50 const FilePath& pdf_path, |
49 const printing::PdfRenderSettings& render_settings, | 51 const printing::PdfRenderSettings& render_settings, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 FilePath exposed_path; | 98 FilePath exposed_path; |
97 if (!StartProcess(true, exposed_path)) | 99 if (!StartProcess(true, exposed_path)) |
98 return false; | 100 return false; |
99 waiting_for_reply_ = true; | 101 waiting_for_reply_ = true; |
100 return child_process_host_->Send( | 102 return child_process_host_->Send( |
101 new ChromeUtilityMsg_GetPrinterCapsAndDefaults(printer_name)); | 103 new ChromeUtilityMsg_GetPrinterCapsAndDefaults(printer_name)); |
102 } | 104 } |
103 | 105 |
104 bool ServiceUtilityProcessHost::StartProcess(bool no_sandbox, | 106 bool ServiceUtilityProcessHost::StartProcess(bool no_sandbox, |
105 const FilePath& exposed_dir) { | 107 const FilePath& exposed_dir) { |
106 if (!child_process_host_->CreateChannel()) | 108 std::string channel_id = child_process_host_->CreateChannel(); |
| 109 if (channel_id.empty()) |
107 return false; | 110 return false; |
108 | 111 |
109 FilePath exe_path = GetUtilityProcessCmd(); | 112 FilePath exe_path = GetUtilityProcessCmd(); |
110 if (exe_path.empty()) { | 113 if (exe_path.empty()) { |
111 NOTREACHED() << "Unable to get utility process binary name."; | 114 NOTREACHED() << "Unable to get utility process binary name."; |
112 return false; | 115 return false; |
113 } | 116 } |
114 | 117 |
115 CommandLine cmd_line(exe_path); | 118 CommandLine cmd_line(exe_path); |
116 cmd_line.AppendSwitchASCII(switches::kProcessType, switches::kUtilityProcess); | 119 cmd_line.AppendSwitchASCII(switches::kProcessType, switches::kUtilityProcess); |
117 cmd_line.AppendSwitchASCII(switches::kProcessChannelID, | 120 cmd_line.AppendSwitchASCII(switches::kProcessChannelID, channel_id); |
118 child_process_host_->channel_id()); | |
119 cmd_line.AppendSwitch(switches::kLang); | 121 cmd_line.AppendSwitch(switches::kLang); |
120 | 122 |
121 return Launch(&cmd_line, no_sandbox, exposed_dir); | 123 return Launch(&cmd_line, no_sandbox, exposed_dir); |
122 } | 124 } |
123 | 125 |
124 bool ServiceUtilityProcessHost::Launch(CommandLine* cmd_line, | 126 bool ServiceUtilityProcessHost::Launch(CommandLine* cmd_line, |
125 bool no_sandbox, | 127 bool no_sandbox, |
126 const FilePath& exposed_dir) { | 128 const FilePath& exposed_dir) { |
127 #if !defined(OS_WIN) | 129 #if !defined(OS_WIN) |
128 // TODO(sanjeevr): Implement for non-Windows OSes. | 130 // TODO(sanjeevr): Implement for non-Windows OSes. |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 printing::Emf metafile; | 245 printing::Emf metafile; |
244 if (!metafile.InitFromFile(metafile_path)) { | 246 if (!metafile.InitFromFile(metafile_path)) { |
245 OnRenderPDFPagesToMetafileFailed(); | 247 OnRenderPDFPagesToMetafileFailed(); |
246 } else { | 248 } else { |
247 OnRenderPDFPagesToMetafileSucceeded(metafile, | 249 OnRenderPDFPagesToMetafileSucceeded(metafile, |
248 highest_rendered_page_number); | 250 highest_rendered_page_number); |
249 } | 251 } |
250 #endif // defined(OS_WIN) | 252 #endif // defined(OS_WIN) |
251 } | 253 } |
252 | 254 |
OLD | NEW |