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

Unified Diff: sandbox/mac/sandbox_compiler.cc

Issue 2686433002: Move SandboxCompiler class into the sandbox library. (Closed)
Patch Set: Try getting rid of sysctl-read Created 3 years, 10 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sandbox/mac/sandbox_compiler.h ('k') | sandbox/mac/sandbox_mac_compiler_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/mac/sandbox_compiler.cc
diff --git a/sandbox/mac/sandbox_compiler.cc b/sandbox/mac/sandbox_compiler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e524aa7b851022abed1edac39e18d8d92e5349b4
--- /dev/null
+++ b/sandbox/mac/sandbox_compiler.cc
@@ -0,0 +1,50 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sandbox/mac/sandbox_compiler.h"
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "sandbox/mac/seatbelt.h"
+
+namespace sandbox {
+
+SandboxCompiler::SandboxCompiler(const std::string& profile_str)
+ : params_map_(), profile_str_(profile_str) {}
+
+SandboxCompiler::~SandboxCompiler() {}
+
+bool SandboxCompiler::InsertBooleanParam(const std::string& key, bool value) {
+ return params_map_.insert(std::make_pair(key, value ? "TRUE" : "FALSE"))
+ .second;
+}
+
+bool SandboxCompiler::InsertStringParam(const std::string& key,
+ const std::string& value) {
+ return params_map_.insert(std::make_pair(key, value)).second;
+}
+
+bool SandboxCompiler::CompileAndApplyProfile(std::string* error) {
+ char* error_internal = nullptr;
+ std::vector<const char*> params;
+
+ for (const auto& kv : params_map_) {
+ params.push_back(kv.first.c_str());
+ params.push_back(kv.second.c_str());
+ }
+ // The parameters array must be null terminated.
+ params.push_back(static_cast<const char*>(0));
+
+ if (sandbox::Seatbelt::InitWithParams(profile_str_.c_str(), 0, params.data(),
+ &error_internal)) {
+ error->assign(error_internal);
+ sandbox::Seatbelt::FreeError(error_internal);
+ return false;
+ }
+ return true;
+}
+
+} // namespace sandbox
« no previous file with comments | « sandbox/mac/sandbox_compiler.h ('k') | sandbox/mac/sandbox_mac_compiler_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698