sandbox_compiler.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #ifndef SANDBOX_MAC_SANDBOX_COMPILER_H_
  5. #define SANDBOX_MAC_SANDBOX_COMPILER_H_
  6. #include <map>
  7. #include <string>
  8. #include "sandbox/mac/seatbelt_export.h"
  9. namespace sandbox {
  10. // This class wraps the C-style sandbox APIs in a class to ensure proper
  11. // initialization and cleanup.
  12. class SEATBELT_EXPORT SandboxCompiler {
  13. public:
  14. explicit SandboxCompiler(const std::string& profile_str);
  15. ~SandboxCompiler();
  16. SandboxCompiler(const SandboxCompiler& other) = delete;
  17. SandboxCompiler& operator=(const SandboxCompiler& other) = delete;
  18. // Inserts a boolean into the parameters key/value map. A duplicate key is not
  19. // allowed, and will cause the function to return false. The value is not
  20. // inserted in this case.
  21. bool InsertBooleanParam(const std::string& key, bool value);
  22. // Inserts a string into the parameters key/value map. A duplicate key is not
  23. // allowed, and will cause the function to return false. The value is not
  24. // inserted in this case.
  25. bool InsertStringParam(const std::string& key, const std::string& value);
  26. // Compiles and applies the profile; returns true on success.
  27. bool CompileAndApplyProfile(std::string* error);
  28. private:
  29. // Storage of the key/value pairs of strings that are used in the sandbox
  30. // profile.
  31. std::map<std::string, std::string> params_map_;
  32. // The sandbox profile source code.
  33. const std::string profile_str_;
  34. };
  35. } // namespace sandbox
  36. #endif // SANDBOX_MAC_SANDBOX_COMPILER_H_