| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/files/file.h" | 14 #include "base/files/file.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
| 17 #include "base/files/scoped_temp_dir.h" | 17 #include "base/files/scoped_temp_dir.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
| 21 #include "base/process/launch.h" | 21 #include "base/process/launch.h" |
| 22 #include "base/task_runner_util.h" | 22 #include "base/task_runner_util.h" |
| 23 #include "base/thread_task_runner_handle.h" | 23 #include "base/thread_task_runner_handle.h" |
| 24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/chrome_utility_printing_messages.h" | 26 #include "chrome/common/chrome_utility_printing_messages.h" |
| 27 #include "components/startup_metric_utils/common/pre_read_field_trial_utils_win.
h" |
| 27 #include "content/public/common/child_process_host.h" | 28 #include "content/public/common/child_process_host.h" |
| 28 #include "content/public/common/content_switches.h" | 29 #include "content/public/common/content_switches.h" |
| 29 #include "content/public/common/result_codes.h" | 30 #include "content/public/common/result_codes.h" |
| 30 #include "content/public/common/sandbox_init.h" | 31 #include "content/public/common/sandbox_init.h" |
| 31 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 32 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
| 32 #include "ipc/ipc_switches.h" | 33 #include "ipc/ipc_switches.h" |
| 33 #include "printing/emf_win.h" | 34 #include "printing/emf_win.h" |
| 34 #include "sandbox/win/src/sandbox_policy.h" | 35 #include "sandbox/win/src/sandbox_policy.h" |
| 35 #include "sandbox/win/src/sandbox_types.h" | 36 #include "sandbox/win/src/sandbox_types.h" |
| 36 #include "ui/base/ui_base_switches.h" | 37 #include "ui/base/ui_base_switches.h" |
| 37 | 38 |
| 38 #if defined(OS_WIN) | |
| 39 #include "components/startup_metric_utils/common/pre_read_field_trial_utils_win.
h" | |
| 40 #endif // defined(OS_WIN) | |
| 41 | |
| 42 namespace { | 39 namespace { |
| 43 | 40 |
| 44 using content::ChildProcessHost; | 41 using content::ChildProcessHost; |
| 45 | 42 |
| 46 enum ServiceUtilityProcessHostEvent { | 43 enum ServiceUtilityProcessHostEvent { |
| 47 SERVICE_UTILITY_STARTED, | 44 SERVICE_UTILITY_STARTED, |
| 48 SERVICE_UTILITY_DISCONNECTED, | 45 SERVICE_UTILITY_DISCONNECTED, |
| 49 SERVICE_UTILITY_METAFILE_REQUEST, | 46 SERVICE_UTILITY_METAFILE_REQUEST, |
| 50 SERVICE_UTILITY_METAFILE_SUCCEEDED, | 47 SERVICE_UTILITY_METAFILE_SUCCEEDED, |
| 51 SERVICE_UTILITY_METAFILE_FAILED, | 48 SERVICE_UTILITY_METAFILE_FAILED, |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 ServiceUtilityProcessHost::~ServiceUtilityProcessHost() { | 170 ServiceUtilityProcessHost::~ServiceUtilityProcessHost() { |
| 174 // We need to kill the child process when the host dies. | 171 // We need to kill the child process when the host dies. |
| 175 process_.Terminate(content::RESULT_CODE_NORMAL_EXIT, false); | 172 process_.Terminate(content::RESULT_CODE_NORMAL_EXIT, false); |
| 176 } | 173 } |
| 177 | 174 |
| 178 bool ServiceUtilityProcessHost::StartRenderPDFPagesToMetafile( | 175 bool ServiceUtilityProcessHost::StartRenderPDFPagesToMetafile( |
| 179 const base::FilePath& pdf_path, | 176 const base::FilePath& pdf_path, |
| 180 const printing::PdfRenderSettings& render_settings) { | 177 const printing::PdfRenderSettings& render_settings) { |
| 181 ReportUmaEvent(SERVICE_UTILITY_METAFILE_REQUEST); | 178 ReportUmaEvent(SERVICE_UTILITY_METAFILE_REQUEST); |
| 182 start_time_ = base::Time::Now(); | 179 start_time_ = base::Time::Now(); |
| 183 base::File pdf_file(pdf_path, base::File::FLAG_OPEN | base::File::FLAG_READ); | 180 base::File pdf_file(pdf_path, base::File::FLAG_OPEN | base::File::FLAG_READ | |
| 181 base::File::FLAG_DELETE_ON_CLOSE); |
| 184 if (!pdf_file.IsValid() || !StartProcess(false)) | 182 if (!pdf_file.IsValid() || !StartProcess(false)) |
| 185 return false; | 183 return false; |
| 186 | 184 |
| 187 DCHECK(!waiting_for_reply_); | 185 DCHECK(!waiting_for_reply_); |
| 188 waiting_for_reply_ = true; | 186 waiting_for_reply_ = true; |
| 189 | 187 |
| 190 pdf_to_emf_state_.reset(new PdfToEmfState(this)); | 188 pdf_to_emf_state_.reset(new PdfToEmfState(this)); |
| 191 return pdf_to_emf_state_->Start(std::move(pdf_file), render_settings); | 189 return pdf_to_emf_state_->Start(std::move(pdf_file), render_settings); |
| 192 } | 190 } |
| 193 | 191 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 223 if (exe_path.empty()) { | 221 if (exe_path.empty()) { |
| 224 NOTREACHED() << "Unable to get utility process binary name."; | 222 NOTREACHED() << "Unable to get utility process binary name."; |
| 225 return false; | 223 return false; |
| 226 } | 224 } |
| 227 | 225 |
| 228 base::CommandLine cmd_line(exe_path); | 226 base::CommandLine cmd_line(exe_path); |
| 229 cmd_line.AppendSwitchASCII(switches::kProcessType, switches::kUtilityProcess); | 227 cmd_line.AppendSwitchASCII(switches::kProcessType, switches::kUtilityProcess); |
| 230 cmd_line.AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 228 cmd_line.AppendSwitchASCII(switches::kProcessChannelID, channel_id); |
| 231 cmd_line.AppendSwitch(switches::kLang); | 229 cmd_line.AppendSwitch(switches::kLang); |
| 232 | 230 |
| 233 #if defined(OS_WIN) | |
| 234 if (startup_metric_utils::GetPreReadOptions().use_prefetch_argument) | 231 if (startup_metric_utils::GetPreReadOptions().use_prefetch_argument) |
| 235 cmd_line.AppendArg(switches::kPrefetchArgumentOther); | 232 cmd_line.AppendArg(switches::kPrefetchArgumentOther); |
| 236 #endif // defined(OS_WIN) | |
| 237 | 233 |
| 238 if (Launch(&cmd_line, no_sandbox)) { | 234 if (Launch(&cmd_line, no_sandbox)) { |
| 239 ReportUmaEvent(SERVICE_UTILITY_STARTED); | 235 ReportUmaEvent(SERVICE_UTILITY_STARTED); |
| 240 return true; | 236 return true; |
| 241 } | 237 } |
| 242 ReportUmaEvent(SERVICE_UTILITY_FAILED_TO_START); | 238 ReportUmaEvent(SERVICE_UTILITY_FAILED_TO_START); |
| 243 return false; | 239 return false; |
| 244 } | 240 } |
| 245 | 241 |
| 246 bool ServiceUtilityProcessHost::Launch(base::CommandLine* cmd_line, | 242 bool ServiceUtilityProcessHost::Launch(base::CommandLine* cmd_line, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 257 } | 253 } |
| 258 | 254 |
| 259 bool ServiceUtilityProcessHost::Send(IPC::Message* msg) { | 255 bool ServiceUtilityProcessHost::Send(IPC::Message* msg) { |
| 260 if (child_process_host_) | 256 if (child_process_host_) |
| 261 return child_process_host_->Send(msg); | 257 return child_process_host_->Send(msg); |
| 262 delete msg; | 258 delete msg; |
| 263 return false; | 259 return false; |
| 264 } | 260 } |
| 265 | 261 |
| 266 base::FilePath ServiceUtilityProcessHost::GetUtilityProcessCmd() { | 262 base::FilePath ServiceUtilityProcessHost::GetUtilityProcessCmd() { |
| 267 #if defined(OS_LINUX) | 263 return ChildProcessHost::GetChildPath(ChildProcessHost::CHILD_NORMAL); |
| 268 int flags = ChildProcessHost::CHILD_ALLOW_SELF; | |
| 269 #else | |
| 270 int flags = ChildProcessHost::CHILD_NORMAL; | |
| 271 #endif | |
| 272 return ChildProcessHost::GetChildPath(flags); | |
| 273 } | 264 } |
| 274 | 265 |
| 275 void ServiceUtilityProcessHost::OnChildDisconnected() { | 266 void ServiceUtilityProcessHost::OnChildDisconnected() { |
| 276 if (waiting_for_reply_) { | 267 if (waiting_for_reply_) { |
| 277 // If we are yet to receive a reply then notify the client that the | 268 // If we are yet to receive a reply then notify the client that the |
| 278 // child died. | 269 // child died. |
| 279 client_task_runner_->PostTask( | 270 client_task_runner_->PostTask( |
| 280 FROM_HERE, base::Bind(&Client::OnChildDied, client_.get())); | 271 FROM_HERE, base::Bind(&Client::OnChildDied, client_.get())); |
| 281 ReportUmaEvent(SERVICE_UTILITY_DISCONNECTED); | 272 ReportUmaEvent(SERVICE_UTILITY_DISCONNECTED); |
| 282 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityDisconnectTime", | 273 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityDisconnectTime", |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 return false; | 421 return false; |
| 431 } | 422 } |
| 432 printing::Emf emf; | 423 printing::Emf emf; |
| 433 if (!emf.InitFromData(data.data(), data.size())) { | 424 if (!emf.InitFromData(data.data(), data.size())) { |
| 434 OnRenderPDFPagesToMetafileDone(false); | 425 OnRenderPDFPagesToMetafileDone(false); |
| 435 return false; | 426 return false; |
| 436 } | 427 } |
| 437 OnRenderPDFPagesToMetafilePageDone(scale_factor, emf); | 428 OnRenderPDFPagesToMetafilePageDone(scale_factor, emf); |
| 438 return true; | 429 return true; |
| 439 } | 430 } |
| OLD | NEW |