• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_FUCHSIA_STARTUP_CONTEXT_H_
6 #define BASE_FUCHSIA_STARTUP_CONTEXT_H_
7 
8 #include <fuchsia/component/runner/cpp/fidl.h>
9 #include <fuchsia/io/cpp/fidl.h>
10 #include <lib/sys/cpp/component_context.h>
11 #include <lib/zx/channel.h>
12 
13 #include <memory>
14 
15 #include "base/base_export.h"
16 
17 namespace sys {
18 class ServiceDirectory;
19 class OutgoingDirectory;
20 }  // namespace sys
21 
22 namespace base {
23 
24 // Helper for unpacking component start info and creating convenience
25 // wrappers for the various fields (e.g. the incoming & outgoing service
26 // directories, resolve launch URL etc).
27 // Embedders may derived from StartupContext to e.g. add bound pointers to
28 // embedder-specific services, as required.
29 class BASE_EXPORT StartupContext final {
30  public:
31   explicit StartupContext(
32       ::fuchsia::component::runner::ComponentStartInfo start_info);
33   ~StartupContext();
34 
35   StartupContext(const StartupContext&) = delete;
36   StartupContext& operator=(const StartupContext&) = delete;
37 
38   // Returns the ComponentContext for the current component.
component_context()39   sys::ComponentContext* component_context() const {
40     return component_context_.get();
41   }
42 
43   // Easy accessors for the incoming service directory, and outgoing directory.
svc()44   const sys::ServiceDirectory* svc() const {
45     return component_context_->svc().get();
46   }
outgoing()47   sys::OutgoingDirectory* outgoing() const {
48     return component_context_->outgoing().get();
49   }
50 
51   // Starts serving outgoing directory in the |component_context()|. Can be
52   // called at most once. All outgoing services should be published in
53   // |component_context()->outgoing()| before calling this function.
54   void ServeOutgoingDirectory();
55 
has_outgoing_directory_request()56   bool has_outgoing_directory_request() {
57     return outgoing_directory_request_.is_valid();
58   }
59 
60  private:
61   std::unique_ptr<sys::ComponentContext> component_context_;
62 
63   // Used to store outgoing directory until ServeOutgoingDirectory() is called.
64   fidl::InterfaceRequest<fuchsia::io::Directory> outgoing_directory_request_;
65 };
66 
67 }  // namespace base
68 
69 #endif  // BASE_FUCHSIA_STARTUP_CONTEXT_H_
70