startup_context.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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_FUCHSIA_STARTUP_CONTEXT_H_
  5. #define BASE_FUCHSIA_STARTUP_CONTEXT_H_
  6. #include <fuchsia/sys/cpp/fidl.h>
  7. #include <lib/sys/cpp/component_context.h>
  8. #include <lib/zx/channel.h>
  9. #include <memory>
  10. #include "base/base_export.h"
  11. namespace sys {
  12. class ComponentContext;
  13. class ServiceDirectory;
  14. class OutgoingDirectory;
  15. } // namespace sys
  16. namespace base {
  17. namespace fuchsia {
  18. // Helper for unpacking a fuchsia.sys.StartupInfo and creating convenience
  19. // wrappers for the various fields (e.g. the incoming & outgoing service
  20. // directories, resolve launch URL etc).
  21. // Embedders may derived from StartupContext to e.g. add bound pointers to
  22. // embedder-specific services, as required.
  23. class BASE_EXPORT StartupContext {
  24. public:
  25. explicit StartupContext(::fuchsia::sys::StartupInfo startup_info);
  26. virtual ~StartupContext();
  27. StartupContext(const StartupContext&) = delete;
  28. StartupContext& operator=(const StartupContext&) = delete;
  29. // Returns the ComponentContext for the current component.
  30. sys::ComponentContext* component_context() const {
  31. return component_context_.get();
  32. }
  33. // Easy accessors for the incoming service directory, and outgoing directory.
  34. const sys::ServiceDirectory* svc() const {
  35. return component_context_->svc().get();
  36. }
  37. const sys::OutgoingDirectory* outgoing() const {
  38. return component_context_->outgoing().get();
  39. }
  40. // Starts serving outgoing directory in the |component_context()|. Can be
  41. // called at most once. All outgoing services should be published in
  42. // |component_context()->outgoing()| before calling this function.
  43. void ServeOutgoingDirectory();
  44. bool has_outgoing_directory_request() {
  45. return outgoing_directory_request_.is_valid();
  46. }
  47. private:
  48. // TODO(https://crbug.com/933834): Remove these when we migrate to the new
  49. // component manager APIs.
  50. ::fuchsia::sys::ServiceProviderPtr additional_services_;
  51. std::unique_ptr<sys::OutgoingDirectory> additional_services_directory_;
  52. std::unique_ptr<sys::ComponentContext> component_context_;
  53. // Used to store outgoing directory until ServeOutgoingDirectory() is called.
  54. zx::channel outgoing_directory_request_;
  55. };
  56. } // namespace fuchsia
  57. } // namespace base
  58. #endif // BASE_FUCHSIA_STARTUP_CONTEXT_H_