sandbox_factory.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (c) 2006-2008 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_WIN_SRC_SANDBOX_FACTORY_H_
  5. #define SANDBOX_WIN_SRC_SANDBOX_FACTORY_H_
  6. #include "sandbox/win/src/sandbox.h"
  7. // SandboxFactory is a set of static methods to get access to the broker
  8. // or target services object. Only one of the two methods (GetBrokerServices,
  9. // GetTargetServices) will return a non-null pointer and that should be used
  10. // as the indication that the process is the broker or the target:
  11. //
  12. // BrokerServices* broker_services = SandboxFactory::GetBrokerServices();
  13. // if (broker_services) {
  14. // //we are the broker, call broker api here
  15. // broker_services->Init();
  16. // } else {
  17. // TargetServices* target_services = SandboxFactory::GetTargetServices();
  18. // if (target_services) {
  19. // //we are the target, call target api here
  20. // target_services->Init();
  21. // }
  22. //
  23. // The methods in this class are expected to be called from a single thread
  24. //
  25. // The Sandbox library needs to be linked against the main executable, but
  26. // sometimes the API calls are issued from a DLL that loads into the exe
  27. // process. These factory methods then need to be called from the main
  28. // exe and the interface pointers then can be safely passed to the DLL where
  29. // the Sandbox API calls are made.
  30. namespace sandbox {
  31. class SandboxFactory {
  32. public:
  33. SandboxFactory() = delete;
  34. SandboxFactory(const SandboxFactory&) = delete;
  35. SandboxFactory& operator=(const SandboxFactory&) = delete;
  36. // Returns the Broker API interface, returns nullptr if this process is the
  37. // target.
  38. static BrokerServices* GetBrokerServices();
  39. // Returns the Target API interface, returns nullptr if this process is the
  40. // broker.
  41. static TargetServices* GetTargetServices();
  42. };
  43. } // namespace sandbox
  44. #endif // SANDBOX_WIN_SRC_SANDBOX_FACTORY_H_