| 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); |
| 97 | 107 |
| 98 return Launch(&cmd_line, exposed_dir); | 108 return Launch(&cmd_line, no_sandbox, exposed_dir); |
| 99 } | 109 } |
| 100 | 110 |
| 101 FilePath ServiceUtilityProcessHost::GetUtilityProcessCmd() { | 111 FilePath ServiceUtilityProcessHost::GetUtilityProcessCmd() { |
| 102 return GetChildPath(true); | 112 return GetChildPath(true); |
| 103 } | 113 } |
| 104 | 114 |
| 105 bool ServiceUtilityProcessHost::CanShutdown() { | 115 bool ServiceUtilityProcessHost::CanShutdown() { |
| 106 return true; | 116 return true; |
| 107 } | 117 } |
| 108 | 118 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 metafile_path_, | 170 metafile_path_, |
| 161 highest_rendered_page_number)); | 171 highest_rendered_page_number)); |
| 162 waiting_for_reply_ = false; | 172 waiting_for_reply_ = false; |
| 163 } | 173 } |
| 164 | 174 |
| 165 void ServiceUtilityProcessHost::Client::OnMessageReceived( | 175 void ServiceUtilityProcessHost::Client::OnMessageReceived( |
| 166 const IPC::Message& message) { | 176 const IPC::Message& message) { |
| 167 IPC_BEGIN_MESSAGE_MAP(ServiceUtilityProcessHost, message) | 177 IPC_BEGIN_MESSAGE_MAP(ServiceUtilityProcessHost, message) |
| 168 IPC_MESSAGE_HANDLER(UtilityHostMsg_RenderPDFPagesToMetafile_Failed, | 178 IPC_MESSAGE_HANDLER(UtilityHostMsg_RenderPDFPagesToMetafile_Failed, |
| 169 Client::OnRenderPDFPagesToMetafileFailed) | 179 Client::OnRenderPDFPagesToMetafileFailed) |
| 180 IPC_MESSAGE_HANDLER(UtilityHostMsg_GetPrinterCapsAndDefaults_Succeeded, |
| 181 Client::OnGetPrinterCapsAndDefaultsSucceeded) |
| 182 IPC_MESSAGE_HANDLER(UtilityHostMsg_GetPrinterCapsAndDefaults_Failed, |
| 183 Client::OnGetPrinterCapsAndDefaultsFailed) |
| 170 IPC_END_MESSAGE_MAP_EX() | 184 IPC_END_MESSAGE_MAP_EX() |
| 171 } | 185 } |
| 172 | 186 |
| 173 void ServiceUtilityProcessHost::Client::MetafileAvailable( | 187 void ServiceUtilityProcessHost::Client::MetafileAvailable( |
| 174 const FilePath& metafile_path, | 188 const FilePath& metafile_path, |
| 175 int highest_rendered_page_number) { | 189 int highest_rendered_page_number) { |
| 176 // The metafile was created in a temp folder which needs to get deleted after | 190 // The metafile was created in a temp folder which needs to get deleted after |
| 177 // we have processed it. | 191 // we have processed it. |
| 178 ScopedTempDir scratch_metafile_dir; | 192 ScopedTempDir scratch_metafile_dir; |
| 179 scratch_metafile_dir.Set(metafile_path.DirName()); | 193 scratch_metafile_dir.Set(metafile_path.DirName()); |
| 180 #if defined(OS_WIN) | 194 #if defined(OS_WIN) |
| 181 printing::NativeMetafile metafile; | 195 printing::NativeMetafile metafile; |
| 182 if (!metafile.CreateFromFile(metafile_path)) { | 196 if (!metafile.CreateFromFile(metafile_path)) { |
| 183 OnRenderPDFPagesToMetafileFailed(); | 197 OnRenderPDFPagesToMetafileFailed(); |
| 184 } else { | 198 } else { |
| 185 OnRenderPDFPagesToMetafileSucceeded(metafile, highest_rendered_page_number); | 199 OnRenderPDFPagesToMetafileSucceeded(metafile, highest_rendered_page_number); |
| 186 // Close it so that ScopedTempDir can delete the folder. | 200 // Close it so that ScopedTempDir can delete the folder. |
| 187 metafile.CloseEmf(); | 201 metafile.CloseEmf(); |
| 188 } | 202 } |
| 189 #endif // defined(OS_WIN) | 203 #endif // defined(OS_WIN) |
| 190 } | 204 } |
| 191 | 205 |
| OLD | NEW |