OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/common/sandbox_init_wrapper.h" | 5 #include "chrome/common/sandbox_init_wrapper.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 | 9 |
10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
11 | 11 |
12 void SandboxInitWrapper::SetServices(sandbox::SandboxInterfaceInfo* info) { | 12 void SandboxInitWrapper::SetServices(sandbox::SandboxInterfaceInfo* info) { |
13 if (info) { | 13 if (!info) |
14 return; | |
15 if (info->legacy) { | |
16 // Looks like we are in the case when the new chrome.dll is being launched | |
17 // by the old chrome.exe, the old chrome exe has SandboxInterfaceInfo as a | |
18 // union, while now we have a struct. | |
19 // TODO(cpu): Reomove this nasty hack after M10 release. | |
rvargas (doing something else)
2011/02/25 22:26:17
typo
| |
20 broker_services_ = reinterpret_cast<sandbox::BrokerServices*>(info->legacy); | |
21 target_services_ = reinterpret_cast<sandbox::TargetServices*>(info->legacy); | |
22 } else { | |
23 // Normal case, both the exe and the dll are the same version. Both | |
24 // interface pointers cannot be non-zero. A process can either be a target | |
25 // or a broker but not both. | |
14 broker_services_ = info->broker_services; | 26 broker_services_ = info->broker_services; |
15 target_services_ = info->target_services; | 27 target_services_ = info->target_services; |
28 DCHECK(!(target_services_ && broker_services_)); | |
16 } | 29 } |
17 // Both interface pointers cannot be non-zero. A process can either | |
18 // be a target or a broker but not both. | |
19 DCHECK(!(target_services_ && broker_services_)); | |
20 } | 30 } |
21 | 31 |
22 bool SandboxInitWrapper::InitializeSandbox(const CommandLine& command_line, | 32 bool SandboxInitWrapper::InitializeSandbox(const CommandLine& command_line, |
23 const std::string& process_type) { | 33 const std::string& process_type) { |
24 if (command_line.HasSwitch(switches::kNoSandbox)) | 34 if (command_line.HasSwitch(switches::kNoSandbox)) |
25 return true; | 35 return true; |
26 if ((process_type == switches::kRendererProcess) || | 36 if ((process_type == switches::kRendererProcess) || |
27 (process_type == switches::kExtensionProcess) || | 37 (process_type == switches::kExtensionProcess) || |
28 (process_type == switches::kWorkerProcess) || | 38 (process_type == switches::kWorkerProcess) || |
29 (process_type == switches::kNaClLoaderProcess) || | 39 (process_type == switches::kNaClLoaderProcess) || |
30 (process_type == switches::kUtilityProcess)) { | 40 (process_type == switches::kUtilityProcess)) { |
31 // The above five process types must be sandboxed unless --no-sandbox | 41 // The above five process types must be sandboxed unless --no-sandbox |
32 // is present in the command line. | 42 // is present in the command line. |
33 if (!target_services_) | 43 if (!target_services_) |
34 return false; | 44 return false; |
35 } else { | 45 } else { |
36 // Other process types might or might not be sandboxed. | 46 // Other process types might or might not be sandboxed. |
37 // TODO(cpu): clean this mess. | 47 // TODO(cpu): clean this mess. |
38 if (!target_services_) | 48 if (!target_services_) |
39 return true; | 49 return true; |
40 } | 50 } |
41 return (sandbox::SBOX_ALL_OK == target_services_->Init()); | 51 return (sandbox::SBOX_ALL_OK == target_services_->Init()); |
42 } | 52 } |
OLD | NEW |