shared_memory_hooks.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2019 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 BASE_MEMORY_SHARED_MEMORY_HOOKS_H_
  5. #define BASE_MEMORY_SHARED_MEMORY_HOOKS_H_
  6. #include "base/memory/read_only_shared_memory_region.h"
  7. #include "base/memory/unsafe_shared_memory_region.h"
  8. #include "base/memory/writable_shared_memory_region.h"
  9. // TODO(https://crbug.com/1062136): This can be removed when Cloud Print support
  10. // is dropped.
  11. namespace content {
  12. struct MainFunctionParams;
  13. } // namespace content
  14. int CloudPrintServiceProcessMain(const content::MainFunctionParams& parameters);
  15. namespace mojo {
  16. class SharedMemoryUtils;
  17. } // namespace mojo
  18. namespace base {
  19. class SharedMemoryHooks {
  20. public:
  21. SharedMemoryHooks() = delete;
  22. private:
  23. friend class SharedMemoryHooksTest;
  24. friend int ::CloudPrintServiceProcessMain(
  25. const content::MainFunctionParams& parameters);
  26. friend mojo::SharedMemoryUtils;
  27. // Allows shared memory region creation to be hooked. Useful for sandboxed
  28. // processes that are restricted from invoking the platform APIs directly.
  29. // Intentionally private so callers need to be explicitly friended.
  30. static void SetCreateHooks(
  31. ReadOnlySharedMemoryRegion::CreateFunction* read_only_hook,
  32. UnsafeSharedMemoryRegion::CreateFunction* unsafe_hook,
  33. WritableSharedMemoryRegion::CreateFunction* writable_hook) {
  34. ReadOnlySharedMemoryRegion::set_create_hook(read_only_hook);
  35. UnsafeSharedMemoryRegion::set_create_hook(unsafe_hook);
  36. WritableSharedMemoryRegion::set_create_hook(writable_hook);
  37. }
  38. };
  39. } // namespace base
  40. #endif // BASE_MEMORY_SHARED_MEMORY_HOOKS_H_