| 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> |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 int current_page_; | 162 int current_page_; |
| 163 int pages_in_progress_; | 163 int pages_in_progress_; |
| 164 }; | 164 }; |
| 165 | 165 |
| 166 ServiceUtilityProcessHost::ServiceUtilityProcessHost( | 166 ServiceUtilityProcessHost::ServiceUtilityProcessHost( |
| 167 Client* client, | 167 Client* client, |
| 168 base::SingleThreadTaskRunner* client_task_runner) | 168 base::SingleThreadTaskRunner* client_task_runner) |
| 169 : client_(client), | 169 : client_(client), |
| 170 client_task_runner_(client_task_runner), | 170 client_task_runner_(client_task_runner), |
| 171 waiting_for_reply_(false), | 171 waiting_for_reply_(false), |
| 172 mojo_child_token_(mojo::edk::GenerateRandomToken()), | |
| 173 weak_ptr_factory_(this) { | 172 weak_ptr_factory_(this) { |
| 174 child_process_host_.reset(ChildProcessHost::Create(this)); | 173 child_process_host_.reset(ChildProcessHost::Create(this)); |
| 175 } | 174 } |
| 176 | 175 |
| 177 ServiceUtilityProcessHost::~ServiceUtilityProcessHost() { | 176 ServiceUtilityProcessHost::~ServiceUtilityProcessHost() { |
| 178 // We need to kill the child process when the host dies. | 177 // We need to kill the child process when the host dies. |
| 179 process_.Terminate(content::RESULT_CODE_NORMAL_EXIT, false); | 178 process_.Terminate(content::RESULT_CODE_NORMAL_EXIT, false); |
| 180 } | 179 } |
| 181 | 180 |
| 182 bool ServiceUtilityProcessHost::StartRenderPDFPagesToMetafile( | 181 bool ServiceUtilityProcessHost::StartRenderPDFPagesToMetafile( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 if (!StartProcess(true)) | 213 if (!StartProcess(true)) |
| 215 return false; | 214 return false; |
| 216 DCHECK(!waiting_for_reply_); | 215 DCHECK(!waiting_for_reply_); |
| 217 waiting_for_reply_ = true; | 216 waiting_for_reply_ = true; |
| 218 return Send( | 217 return Send( |
| 219 new ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults(printer_name)); | 218 new ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults(printer_name)); |
| 220 } | 219 } |
| 221 | 220 |
| 222 bool ServiceUtilityProcessHost::StartProcess(bool no_sandbox) { | 221 bool ServiceUtilityProcessHost::StartProcess(bool no_sandbox) { |
| 223 std::string mojo_channel_token = | 222 std::string mojo_channel_token = |
| 224 child_process_host_->CreateChannelMojo(mojo_child_token_); | 223 child_process_host_->CreateChannelMojo(process_connection_); |
| 225 if (mojo_channel_token.empty()) | 224 if (mojo_channel_token.empty()) |
| 226 return false; | 225 return false; |
| 227 | 226 |
| 228 base::FilePath exe_path = GetUtilityProcessCmd(); | 227 base::FilePath exe_path = GetUtilityProcessCmd(); |
| 229 if (exe_path.empty()) { | 228 if (exe_path.empty()) { |
| 230 NOTREACHED() << "Unable to get utility process binary name."; | 229 NOTREACHED() << "Unable to get utility process binary name."; |
| 231 return false; | 230 return false; |
| 232 } | 231 } |
| 233 | 232 |
| 234 base::CommandLine cmd_line(exe_path); | 233 base::CommandLine cmd_line(exe_path); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 ServiceSandboxedProcessLauncherDelegate delegate; | 270 ServiceSandboxedProcessLauncherDelegate delegate; |
| 272 base::Process process; | 271 base::Process process; |
| 273 sandbox::ResultCode result = content::StartSandboxedProcess( | 272 sandbox::ResultCode result = content::StartSandboxedProcess( |
| 274 &delegate, cmd_line, handles, &process); | 273 &delegate, cmd_line, handles, &process); |
| 275 if (result == sandbox::SBOX_ALL_OK) { | 274 if (result == sandbox::SBOX_ALL_OK) { |
| 276 process_ = std::move(process); | 275 process_ = std::move(process); |
| 277 success = true; | 276 success = true; |
| 278 } | 277 } |
| 279 } | 278 } |
| 280 | 279 |
| 281 if (success) { | 280 if (success) |
| 282 mojo::edk::ChildProcessLaunched(process_.Handle(), | 281 process_connection_.Connect(process_.Handle(), std::move(parent_handle)); |
| 283 std::move(parent_handle), | 282 |
| 284 mojo_child_token_); | |
| 285 } else { | |
| 286 mojo::edk::ChildProcessLaunchFailed(mojo_child_token_); | |
| 287 } | |
| 288 return success; | 283 return success; |
| 289 } | 284 } |
| 290 | 285 |
| 291 bool ServiceUtilityProcessHost::Send(IPC::Message* msg) { | 286 bool ServiceUtilityProcessHost::Send(IPC::Message* msg) { |
| 292 if (child_process_host_) | 287 if (child_process_host_) |
| 293 return child_process_host_->Send(msg); | 288 return child_process_host_->Send(msg); |
| 294 delete msg; | 289 delete msg; |
| 295 return false; | 290 return false; |
| 296 } | 291 } |
| 297 | 292 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 return false; | 452 return false; |
| 458 } | 453 } |
| 459 printing::Emf emf; | 454 printing::Emf emf; |
| 460 if (!emf.InitFromData(data.data(), data.size())) { | 455 if (!emf.InitFromData(data.data(), data.size())) { |
| 461 OnRenderPDFPagesToMetafileDone(false); | 456 OnRenderPDFPagesToMetafileDone(false); |
| 462 return false; | 457 return false; |
| 463 } | 458 } |
| 464 OnRenderPDFPagesToMetafilePageDone(scale_factor, emf); | 459 OnRenderPDFPagesToMetafilePageDone(scale_factor, emf); |
| 465 return true; | 460 return true; |
| 466 } | 461 } |
| OLD | NEW |