Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(593)

Side by Side Diff: chrome/service/service_utility_process_host.cc

Issue 725353003: Don't pass ProcessHandle through ChildProcessHostDelegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <queue> 7 #include <queue>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file.h" 11 #include "base/files/file.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/files/scoped_temp_dir.h" 14 #include "base/files/scoped_temp_dir.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/message_loop/message_loop_proxy.h" 16 #include "base/message_loop/message_loop_proxy.h"
17 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
18 #include "base/process/kill.h" 18 #include "base/process/kill.h"
19 #include "base/process/launch.h" 19 #include "base/process/launch.h"
20 #include "base/process/process_handle.h"
20 #include "base/task_runner_util.h" 21 #include "base/task_runner_util.h"
21 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/chrome_utility_printing_messages.h" 23 #include "chrome/common/chrome_utility_printing_messages.h"
23 #include "content/public/common/child_process_host.h" 24 #include "content/public/common/child_process_host.h"
24 #include "content/public/common/result_codes.h" 25 #include "content/public/common/result_codes.h"
25 #include "content/public/common/sandbox_init.h" 26 #include "content/public/common/sandbox_init.h"
26 #include "content/public/common/sandboxed_process_launcher_delegate.h" 27 #include "content/public/common/sandboxed_process_launcher_delegate.h"
27 #include "ipc/ipc_switches.h" 28 #include "ipc/ipc_switches.h"
28 #include "printing/emf_win.h" 29 #include "printing/emf_win.h"
29 #include "sandbox/win/src/sandbox_policy_base.h" 30 #include "sandbox/win/src/sandbox_policy_base.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 ServiceUtilityProcessHost* host_; 147 ServiceUtilityProcessHost* host_;
147 std::queue<base::File> emf_files_; 148 std::queue<base::File> emf_files_;
148 int page_count_; 149 int page_count_;
149 int current_page_; 150 int current_page_;
150 int pages_in_progress_; 151 int pages_in_progress_;
151 }; 152 };
152 153
153 ServiceUtilityProcessHost::ServiceUtilityProcessHost( 154 ServiceUtilityProcessHost::ServiceUtilityProcessHost(
154 Client* client, 155 Client* client,
155 base::MessageLoopProxy* client_message_loop_proxy) 156 base::MessageLoopProxy* client_message_loop_proxy)
156 : handle_(base::kNullProcessHandle), 157 : client_(client),
157 client_(client),
158 client_message_loop_proxy_(client_message_loop_proxy), 158 client_message_loop_proxy_(client_message_loop_proxy),
159 waiting_for_reply_(false), 159 waiting_for_reply_(false),
160 weak_ptr_factory_(this) { 160 weak_ptr_factory_(this) {
161 child_process_host_.reset(ChildProcessHost::Create(this)); 161 child_process_host_.reset(ChildProcessHost::Create(this));
162 } 162 }
163 163
164 ServiceUtilityProcessHost::~ServiceUtilityProcessHost() { 164 ServiceUtilityProcessHost::~ServiceUtilityProcessHost() {
165 // We need to kill the child process when the host dies. 165 // We need to kill the child process when the host dies.
166 base::KillProcess(handle_, content::RESULT_CODE_NORMAL_EXIT, false); 166 base::KillProcess(process_.Handle(), content::RESULT_CODE_NORMAL_EXIT, false);
167 } 167 }
168 168
169 bool ServiceUtilityProcessHost::StartRenderPDFPagesToMetafile( 169 bool ServiceUtilityProcessHost::StartRenderPDFPagesToMetafile(
170 const base::FilePath& pdf_path, 170 const base::FilePath& pdf_path,
171 const printing::PdfRenderSettings& render_settings) { 171 const printing::PdfRenderSettings& render_settings) {
172 ReportUmaEvent(SERVICE_UTILITY_METAFILE_REQUEST); 172 ReportUmaEvent(SERVICE_UTILITY_METAFILE_REQUEST);
173 start_time_ = base::Time::Now(); 173 start_time_ = base::Time::Now();
174 base::File pdf_file(pdf_path, base::File::FLAG_OPEN | base::File::FLAG_READ); 174 base::File pdf_file(pdf_path, base::File::FLAG_OPEN | base::File::FLAG_READ);
175 if (!pdf_file.IsValid() || !StartProcess(false)) 175 if (!pdf_file.IsValid() || !StartProcess(false))
176 return false; 176 return false;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 return true; 226 return true;
227 } 227 }
228 ReportUmaEvent(SERVICE_UTILITY_FAILED_TO_START); 228 ReportUmaEvent(SERVICE_UTILITY_FAILED_TO_START);
229 return false; 229 return false;
230 } 230 }
231 231
232 bool ServiceUtilityProcessHost::Launch(base::CommandLine* cmd_line, 232 bool ServiceUtilityProcessHost::Launch(base::CommandLine* cmd_line,
233 bool no_sandbox) { 233 bool no_sandbox) {
234 if (no_sandbox) { 234 if (no_sandbox) {
235 cmd_line->AppendSwitch(switches::kNoSandbox); 235 cmd_line->AppendSwitch(switches::kNoSandbox);
236 base::LaunchProcess(*cmd_line, base::LaunchOptions(), &handle_); 236 base::ProcessHandle handle;
237 if (base::LaunchProcess(*cmd_line, base::LaunchOptions(), &handle))
238 process_ = base::Process(handle);
237 } else { 239 } else {
238 ServiceSandboxedProcessLauncherDelegate delegate; 240 ServiceSandboxedProcessLauncherDelegate delegate;
239 handle_ = content::StartSandboxedProcess(&delegate, cmd_line); 241 process_ =
242 base::Process(content::StartSandboxedProcess(&delegate, cmd_line));
240 } 243 }
241 return (handle_ != base::kNullProcessHandle); 244 return process_.IsValid();
242 } 245 }
243 246
244 bool ServiceUtilityProcessHost::Send(IPC::Message* msg) { 247 bool ServiceUtilityProcessHost::Send(IPC::Message* msg) {
245 if (child_process_host_) 248 if (child_process_host_)
246 return child_process_host_->Send(msg); 249 return child_process_host_->Send(msg);
247 delete msg; 250 delete msg;
248 return false; 251 return false;
249 } 252 }
250 253
251 base::FilePath ServiceUtilityProcessHost::GetUtilityProcessCmd() { 254 base::FilePath ServiceUtilityProcessHost::GetUtilityProcessCmd() {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Succeeded, 290 ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Succeeded,
288 OnGetPrinterSemanticCapsAndDefaultsSucceeded) 291 OnGetPrinterSemanticCapsAndDefaultsSucceeded)
289 IPC_MESSAGE_HANDLER( 292 IPC_MESSAGE_HANDLER(
290 ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed, 293 ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed,
291 OnGetPrinterSemanticCapsAndDefaultsFailed) 294 OnGetPrinterSemanticCapsAndDefaultsFailed)
292 IPC_MESSAGE_UNHANDLED(handled = false) 295 IPC_MESSAGE_UNHANDLED(handled = false)
293 IPC_END_MESSAGE_MAP() 296 IPC_END_MESSAGE_MAP()
294 return handled; 297 return handled;
295 } 298 }
296 299
297 base::ProcessHandle ServiceUtilityProcessHost::GetHandle() const { 300 const base::Process& ServiceUtilityProcessHost::GetProcess() const {
298 return handle_; 301 return process_;
299 } 302 }
300 303
301 void ServiceUtilityProcessHost::OnMetafileSpooled(bool success) { 304 void ServiceUtilityProcessHost::OnMetafileSpooled(bool success) {
302 if (!success || pdf_to_emf_state_->OnPageProcessed()) 305 if (!success || pdf_to_emf_state_->OnPageProcessed())
303 OnPDFToEmfFinished(success); 306 OnPDFToEmfFinished(success);
304 } 307 }
305 308
306 void ServiceUtilityProcessHost::OnRenderPDFPagesToMetafilesPageCount( 309 void ServiceUtilityProcessHost::OnRenderPDFPagesToMetafilesPageCount(
307 int page_count) { 310 int page_count) {
308 DCHECK(waiting_for_reply_); 311 DCHECK(waiting_for_reply_);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 return false; 424 return false;
422 } 425 }
423 printing::Emf emf; 426 printing::Emf emf;
424 if (!emf.InitFromData(data.data(), data.size())) { 427 if (!emf.InitFromData(data.data(), data.size())) {
425 OnRenderPDFPagesToMetafileDone(false); 428 OnRenderPDFPagesToMetafileDone(false);
426 return false; 429 return false;
427 } 430 }
428 OnRenderPDFPagesToMetafilePageDone(scale_factor, emf); 431 OnRenderPDFPagesToMetafilePageDone(scale_factor, emf);
429 return true; 432 return true;
430 } 433 }
OLDNEW
« no previous file with comments | « chrome/service/service_utility_process_host.h ('k') | content/browser/browser_child_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698