Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/app_switches.h" | 7 #include "app/app_switches.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/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 return false; | 40 return false; |
| 41 #else // !defined(OS_WIN) | 41 #else // !defined(OS_WIN) |
| 42 scratch_metafile_dir_.reset(new ScopedTempDir); | 42 scratch_metafile_dir_.reset(new ScopedTempDir); |
| 43 if (!scratch_metafile_dir_->CreateUniqueTempDir()) | 43 if (!scratch_metafile_dir_->CreateUniqueTempDir()) |
| 44 return false; | 44 return false; |
| 45 if (!file_util::CreateTemporaryFileInDir(scratch_metafile_dir_->path(), | 45 if (!file_util::CreateTemporaryFileInDir(scratch_metafile_dir_->path(), |
| 46 &metafile_path_)) { | 46 &metafile_path_)) { |
| 47 return false; | 47 return false; |
| 48 } | 48 } |
| 49 | 49 |
| 50 if (!StartProcess(scratch_metafile_dir_->path())) | 50 if (!StartProcess(false, scratch_metafile_dir_->path())) |
| 51 return false; | 51 return false; |
| 52 | 52 |
| 53 ScopedHandle pdf_file( | 53 ScopedHandle pdf_file( |
| 54 ::CreateFile(pdf_path.value().c_str(), | 54 ::CreateFile(pdf_path.value().c_str(), |
| 55 GENERIC_READ, | 55 GENERIC_READ, |
| 56 FILE_SHARE_READ | FILE_SHARE_WRITE, | 56 FILE_SHARE_READ | FILE_SHARE_WRITE, |
| 57 NULL, | 57 NULL, |
| 58 OPEN_EXISTING, | 58 OPEN_EXISTING, |
| 59 FILE_ATTRIBUTE_NORMAL, | 59 FILE_ATTRIBUTE_NORMAL, |
| 60 NULL)); | 60 NULL)); |
| 61 if (pdf_file == INVALID_HANDLE_VALUE) | 61 if (pdf_file == INVALID_HANDLE_VALUE) |
| 62 return false; | 62 return false; |
| 63 HANDLE pdf_file_in_utility_process = NULL; | 63 HANDLE pdf_file_in_utility_process = NULL; |
| 64 ::DuplicateHandle(::GetCurrentProcess(), pdf_file, handle(), | 64 ::DuplicateHandle(::GetCurrentProcess(), pdf_file, handle(), |
| 65 &pdf_file_in_utility_process, 0, false, | 65 &pdf_file_in_utility_process, 0, false, |
| 66 DUPLICATE_SAME_ACCESS); | 66 DUPLICATE_SAME_ACCESS); |
| 67 if (!pdf_file_in_utility_process) | 67 if (!pdf_file_in_utility_process) |
| 68 return false; | 68 return false; |
| 69 waiting_for_reply_ = true; | 69 waiting_for_reply_ = true; |
| 70 return Send( | 70 return Send( |
| 71 new UtilityMsg_RenderPDFPagesToMetafile(pdf_file_in_utility_process, | 71 new UtilityMsg_RenderPDFPagesToMetafile(pdf_file_in_utility_process, |
| 72 metafile_path_, | 72 metafile_path_, |
| 73 render_area, | 73 render_area, |
| 74 render_dpi, | 74 render_dpi, |
| 75 page_ranges)); | 75 page_ranges)); |
| 76 #endif // !defined(OS_WIN) | 76 #endif // !defined(OS_WIN) |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool ServiceUtilityProcessHost::StartProcess(const FilePath& exposed_dir) { | 79 bool ServiceUtilityProcessHost::StartGetPrinterCapsAndDefaults( |
| 80 const std::string& printer_name) { | |
| 81 FilePath exposed_path; | |
| 82 if (!StartProcess(true, exposed_path)) | |
| 83 return false; | |
| 84 waiting_for_reply_ = true; | |
| 85 return Send(new UtilityMsg_GetPrinterCapsAndDefaults(printer_name)); | |
| 86 } | |
| 87 | |
| 88 bool ServiceUtilityProcessHost::StartProcess(bool no_sandbox, | |
| 89 const FilePath& exposed_dir) { | |
| 80 // Name must be set or metrics_service will crash in any test which | 90 // Name must be set or metrics_service will crash in any test which |
| 81 // launches a UtilityProcessHost. | 91 // launches a UtilityProcessHost. |
| 82 set_name(L"utility process"); | 92 set_name(L"utility process"); |
| 83 | 93 |
| 84 if (!CreateChannel()) | 94 if (!CreateChannel()) |
| 85 return false; | 95 return false; |
| 86 | 96 |
| 87 FilePath exe_path = GetUtilityProcessCmd(); | 97 FilePath exe_path = GetUtilityProcessCmd(); |
| 88 if (exe_path.empty()) { | 98 if (exe_path.empty()) { |
| 89 NOTREACHED() << "Unable to get utility process binary name."; | 99 NOTREACHED() << "Unable to get utility process binary name."; |
| 90 return false; | 100 return false; |
| 91 } | 101 } |
| 92 | 102 |
| 93 CommandLine cmd_line(exe_path); | 103 CommandLine cmd_line(exe_path); |
| 94 cmd_line.AppendSwitchASCII(switches::kProcessType, switches::kUtilityProcess); | 104 cmd_line.AppendSwitchASCII(switches::kProcessType, switches::kUtilityProcess); |
| 95 cmd_line.AppendSwitchASCII(switches::kProcessChannelID, channel_id()); | 105 cmd_line.AppendSwitchASCII(switches::kProcessChannelID, channel_id()); |
| 96 cmd_line.AppendSwitch(switches::kLang); | 106 cmd_line.AppendSwitch(switches::kLang); |
| 107 if (no_sandbox) | |
| 108 cmd_line.AppendSwitch(switches::kNoSandbox); | |
|
gene
2010/12/20 22:52:31
Why this is needed? Since we are passing no_sandbo
sanjeevr
2010/12/21 21:28:45
Moved to lower layer.
| |
| 97 | 109 |
| 98 return Launch(&cmd_line, exposed_dir); | 110 return Launch(&cmd_line, no_sandbox, exposed_dir); |
| 99 } | 111 } |
| 100 | 112 |
| 101 FilePath ServiceUtilityProcessHost::GetUtilityProcessCmd() { | 113 FilePath ServiceUtilityProcessHost::GetUtilityProcessCmd() { |
| 102 return GetChildPath(true); | 114 return GetChildPath(true); |
| 103 } | 115 } |
| 104 | 116 |
| 105 bool ServiceUtilityProcessHost::CanShutdown() { | 117 bool ServiceUtilityProcessHost::CanShutdown() { |
| 106 return true; | 118 return true; |
| 107 } | 119 } |
| 108 | 120 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 metafile_path_, | 172 metafile_path_, |
| 161 highest_rendered_page_number)); | 173 highest_rendered_page_number)); |
| 162 waiting_for_reply_ = false; | 174 waiting_for_reply_ = false; |
| 163 } | 175 } |
| 164 | 176 |
| 165 void ServiceUtilityProcessHost::Client::OnMessageReceived( | 177 void ServiceUtilityProcessHost::Client::OnMessageReceived( |
| 166 const IPC::Message& message) { | 178 const IPC::Message& message) { |
| 167 IPC_BEGIN_MESSAGE_MAP(ServiceUtilityProcessHost, message) | 179 IPC_BEGIN_MESSAGE_MAP(ServiceUtilityProcessHost, message) |
| 168 IPC_MESSAGE_HANDLER(UtilityHostMsg_RenderPDFPagesToMetafile_Failed, | 180 IPC_MESSAGE_HANDLER(UtilityHostMsg_RenderPDFPagesToMetafile_Failed, |
| 169 Client::OnRenderPDFPagesToMetafileFailed) | 181 Client::OnRenderPDFPagesToMetafileFailed) |
| 182 IPC_MESSAGE_HANDLER(UtilityHostMsg_GetPrinterCapsAndDefaults_Succeeded, | |
| 183 Client::OnGetPrinterCapsAndDefaultsSucceeded) | |
| 184 IPC_MESSAGE_HANDLER(UtilityHostMsg_GetPrinterCapsAndDefaults_Failed, | |
| 185 Client::OnGetPrinterCapsAndDefaultsFailed) | |
| 170 IPC_END_MESSAGE_MAP_EX() | 186 IPC_END_MESSAGE_MAP_EX() |
| 171 } | 187 } |
| 172 | 188 |
| 173 void ServiceUtilityProcessHost::Client::MetafileAvailable( | 189 void ServiceUtilityProcessHost::Client::MetafileAvailable( |
| 174 const FilePath& metafile_path, | 190 const FilePath& metafile_path, |
| 175 int highest_rendered_page_number) { | 191 int highest_rendered_page_number) { |
| 176 // The metafile was created in a temp folder which needs to get deleted after | 192 // The metafile was created in a temp folder which needs to get deleted after |
| 177 // we have processed it. | 193 // we have processed it. |
| 178 ScopedTempDir scratch_metafile_dir; | 194 ScopedTempDir scratch_metafile_dir; |
| 179 scratch_metafile_dir.Set(metafile_path.DirName()); | 195 scratch_metafile_dir.Set(metafile_path.DirName()); |
| 180 #if defined(OS_WIN) | 196 #if defined(OS_WIN) |
| 181 printing::NativeMetafile metafile; | 197 printing::NativeMetafile metafile; |
| 182 if (!metafile.CreateFromFile(metafile_path)) { | 198 if (!metafile.CreateFromFile(metafile_path)) { |
| 183 OnRenderPDFPagesToMetafileFailed(); | 199 OnRenderPDFPagesToMetafileFailed(); |
| 184 } else { | 200 } else { |
| 185 OnRenderPDFPagesToMetafileSucceeded(metafile, highest_rendered_page_number); | 201 OnRenderPDFPagesToMetafileSucceeded(metafile, highest_rendered_page_number); |
| 186 // Close it so that ScopedTempDir can delete the folder. | 202 // Close it so that ScopedTempDir can delete the folder. |
| 187 metafile.CloseEmf(); | 203 metafile.CloseEmf(); |
| 188 } | 204 } |
| 189 #endif // defined(OS_WIN) | 205 #endif // defined(OS_WIN) |
| 190 } | 206 } |
| 191 | 207 |
| OLD | NEW |