| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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 "sandbox/mac/sandbox_compiler.h" |
| 6 |
| 7 #include <map> |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "sandbox/mac/seatbelt.h" |
| 12 |
| 13 namespace sandbox { |
| 14 |
| 15 SandboxCompiler::SandboxCompiler(const std::string& profile_str) |
| 16 : params_map_(), profile_str_(profile_str) {} |
| 17 |
| 18 SandboxCompiler::~SandboxCompiler() {} |
| 19 |
| 20 bool SandboxCompiler::InsertBooleanParam(const std::string& key, bool value) { |
| 21 return params_map_.insert(std::make_pair(key, value ? "TRUE" : "FALSE")) |
| 22 .second; |
| 23 } |
| 24 |
| 25 bool SandboxCompiler::InsertStringParam(const std::string& key, |
| 26 const std::string& value) { |
| 27 return params_map_.insert(std::make_pair(key, value)).second; |
| 28 } |
| 29 |
| 30 bool SandboxCompiler::CompileAndApplyProfile(std::string* error) { |
| 31 char* error_internal = nullptr; |
| 32 std::vector<const char*> params; |
| 33 |
| 34 for (const auto& kv : params_map_) { |
| 35 params.push_back(kv.first.c_str()); |
| 36 params.push_back(kv.second.c_str()); |
| 37 } |
| 38 // The parameters array must be null terminated. |
| 39 params.push_back(static_cast<const char*>(0)); |
| 40 |
| 41 if (sandbox::Seatbelt::InitWithParams(profile_str_.c_str(), 0, params.data(), |
| 42 &error_internal)) { |
| 43 error->assign(error_internal); |
| 44 sandbox::Seatbelt::FreeError(error_internal); |
| 45 return false; |
| 46 } |
| 47 return true; |
| 48 } |
| 49 |
| 50 } // namespace sandbox |
| OLD | NEW |