| 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 "base/bind.h" | 7 #include "base/bind.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/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
| 14 #include "base/process_util.h" | 14 #include "base/process_util.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/chrome_utility_messages.h" | 17 #include "chrome/common/chrome_utility_messages.h" |
| 18 #include "content/public/common/child_process_host.h" | 18 #include "content/public/common/child_process_host.h" |
| 19 #include "content/public/common/result_codes.h" | 19 #include "content/public/common/result_codes.h" |
| 20 #include "content/public/common/sandbox_init.h" | 20 #include "content/public/common/sandbox_init.h" |
| 21 #include "ipc/ipc_switches.h" | 21 #include "ipc/ipc_switches.h" |
| 22 #include "printing/page_range.h" | 22 #include "printing/page_range.h" |
| 23 #include "ui/base/ui_base_switches.h" | 23 #include "ui/base/ui_base_switches.h" |
| 24 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
| 25 | 25 |
| 26 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
| 27 #include "base/files/file_path.h" | 27 #include "base/files/file_path.h" |
| 28 #include "base/memory/scoped_ptr.h" | 28 #include "base/memory/scoped_ptr.h" |
| 29 #include "base/win/scoped_handle.h" | 29 #include "base/win/scoped_handle.h" |
| 30 #include "content/public/common/sandbox_init.h" |
| 31 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
| 30 #include "printing/emf_win.h" | 32 #include "printing/emf_win.h" |
| 31 #endif | 33 |
| 34 namespace { |
| 35 class ServiceSandboxedProcessLauncherDelegate |
| 36 : public content::SandboxedProcessLauncherDelegate { |
| 37 public: |
| 38 explicit ServiceSandboxedProcessLauncherDelegate( |
| 39 const base::FilePath& exposed_dir) |
| 40 : exposed_dir_(exposed_dir) { |
| 41 } |
| 42 |
| 43 virtual void PreSandbox(bool* disable_sandbox, base::FilePath* exposed_dir) { |
| 44 *exposed_dir = exposed_dir_; |
| 45 } |
| 46 |
| 47 private: |
| 48 base::FilePath exposed_dir_; |
| 49 }; |
| 50 } |
| 51 |
| 52 #endif // OS_WIN |
| 32 | 53 |
| 33 using content::ChildProcessHost; | 54 using content::ChildProcessHost; |
| 34 | 55 |
| 35 ServiceUtilityProcessHost::ServiceUtilityProcessHost( | 56 ServiceUtilityProcessHost::ServiceUtilityProcessHost( |
| 36 Client* client, base::MessageLoopProxy* client_message_loop_proxy) | 57 Client* client, base::MessageLoopProxy* client_message_loop_proxy) |
| 37 : handle_(base::kNullProcessHandle), | 58 : handle_(base::kNullProcessHandle), |
| 38 client_(client), | 59 client_(client), |
| 39 client_message_loop_proxy_(client_message_loop_proxy), | 60 client_message_loop_proxy_(client_message_loop_proxy), |
| 40 waiting_for_reply_(false) { | 61 waiting_for_reply_(false) { |
| 41 child_process_host_.reset(ChildProcessHost::Create(this)); | 62 child_process_host_.reset(ChildProcessHost::Create(this)); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // TODO(sanjeevr): Implement for non-Windows OSes. | 152 // TODO(sanjeevr): Implement for non-Windows OSes. |
| 132 NOTIMPLEMENTED(); | 153 NOTIMPLEMENTED(); |
| 133 return false; | 154 return false; |
| 134 #else // !defined(OS_WIN) | 155 #else // !defined(OS_WIN) |
| 135 | 156 |
| 136 if (no_sandbox) { | 157 if (no_sandbox) { |
| 137 base::ProcessHandle process = base::kNullProcessHandle; | 158 base::ProcessHandle process = base::kNullProcessHandle; |
| 138 cmd_line->AppendSwitch(switches::kNoSandbox); | 159 cmd_line->AppendSwitch(switches::kNoSandbox); |
| 139 base::LaunchProcess(*cmd_line, base::LaunchOptions(), &handle_); | 160 base::LaunchProcess(*cmd_line, base::LaunchOptions(), &handle_); |
| 140 } else { | 161 } else { |
| 141 handle_ = content::StartProcessWithAccess(cmd_line, exposed_dir); | 162 ServiceSandboxedProcessLauncherDelegate delegate(exposed_dir); |
| 163 handle_ = content::StartSandboxedProcess(&delegate, cmd_line); |
| 142 } | 164 } |
| 143 return (handle_ != base::kNullProcessHandle); | 165 return (handle_ != base::kNullProcessHandle); |
| 144 #endif // !defined(OS_WIN) | 166 #endif // !defined(OS_WIN) |
| 145 } | 167 } |
| 146 | 168 |
| 147 base::FilePath ServiceUtilityProcessHost::GetUtilityProcessCmd() { | 169 base::FilePath ServiceUtilityProcessHost::GetUtilityProcessCmd() { |
| 148 #if defined(OS_LINUX) | 170 #if defined(OS_LINUX) |
| 149 int flags = ChildProcessHost::CHILD_ALLOW_SELF; | 171 int flags = ChildProcessHost::CHILD_ALLOW_SELF; |
| 150 #else | 172 #else |
| 151 int flags = ChildProcessHost::CHILD_NORMAL; | 173 int flags = ChildProcessHost::CHILD_NORMAL; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 if (!metafile.InitFromFile(metafile_path)) { | 264 if (!metafile.InitFromFile(metafile_path)) { |
| 243 OnRenderPDFPagesToMetafileFailed(); | 265 OnRenderPDFPagesToMetafileFailed(); |
| 244 } else { | 266 } else { |
| 245 OnRenderPDFPagesToMetafileSucceeded(metafile, | 267 OnRenderPDFPagesToMetafileSucceeded(metafile, |
| 246 highest_rendered_page_number, | 268 highest_rendered_page_number, |
| 247 scale_factor); | 269 scale_factor); |
| 248 } | 270 } |
| 249 #endif // defined(OS_WIN) | 271 #endif // defined(OS_WIN) |
| 250 } | 272 } |
| 251 | 273 |
| OLD | NEW |