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
3 // found in the LICENSE file.
4
5 #include "content/public/common/sandbox_init.h"
6
7 #include <string>
8
9 #include "base/base_switches.h"
10 #include "base/logging.h"
11 #include "base/trace_event/trace_event.h"
12 #include "base/win/scoped_process_information.h"
13 #include "content/public/common/content_switches.h"
14 #include "content/public/common/sandbox_init.h"
15 #include "content/public/common/sandboxed_process_launcher_delegate.h"
16 #include "sandbox/win/src/sandbox.h"
17 #include "sandbox/win/src/sandbox_types.h"
18 #include "services/service_manager/sandbox/sandbox.h"
19 #include "services/service_manager/sandbox/win/sandbox_win.h"
20
21 namespace content {
22
InitializeSandbox(service_manager::SandboxType sandbox_type,sandbox::SandboxInterfaceInfo * sandbox_info)23 bool InitializeSandbox(service_manager::SandboxType sandbox_type,
24 sandbox::SandboxInterfaceInfo* sandbox_info) {
25 return service_manager::Sandbox::Initialize(sandbox_type, sandbox_info);
26 }
27
StartSandboxedProcess(SandboxedProcessLauncherDelegate * delegate,base::CommandLine * child_command_line,const base::HandlesToInheritVector & handles_to_inherit,base::Process * process)28 sandbox::ResultCode StartSandboxedProcess(
29 SandboxedProcessLauncherDelegate* delegate,
30 base::CommandLine* child_command_line,
31 const base::HandlesToInheritVector& handles_to_inherit,
32 base::Process* process) {
33 std::string type_str =
34 child_command_line->GetSwitchValueASCII(switches::kProcessType);
35 TRACE_EVENT1("startup", "StartProcessWithAccess", "type", type_str);
36
37 // Updates the command line arguments with debug-related flags. If debug
38 // flags have been used with this process, they will be filtered and added
39 // to child_command_line as needed.
40 const base::CommandLine* current_command_line =
41 base::CommandLine::ForCurrentProcess();
42 if (current_command_line->HasSwitch(switches::kWaitForDebuggerChildren)) {
43 std::string value = current_command_line->GetSwitchValueASCII(
44 switches::kWaitForDebuggerChildren);
45 child_command_line->AppendSwitchASCII(switches::kWaitForDebuggerChildren,
46 value);
47 if (value.empty() || value == type_str)
48 child_command_line->AppendSwitch(switches::kWaitForDebugger);
49 }
50
51 return service_manager::SandboxWin::StartSandboxedProcess(
52 child_command_line, type_str, handles_to_inherit, delegate, process);
53 }
54
55 } // namespace content
56