• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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_FILTERED_SERVICE_DIRECTORY_H_
6 #define BASE_FUCHSIA_FILTERED_SERVICE_DIRECTORY_H_
7 
8 #include <fuchsia/io/cpp/fidl.h>
9 #include <lib/fidl/cpp/interface_handle.h>
10 #include <lib/sys/cpp/outgoing_directory.h>
11 #include <lib/sys/cpp/service_directory.h>
12 #include <lib/zx/channel.h>
13 #include <memory>
14 
15 #include "base/base_export.h"
16 #include "base/strings/string_piece.h"
17 
18 namespace base {
19 
20 // ServiceDirectory that uses the supplied sys::ServiceDirectory to satisfy
21 // requests for only a restricted set of services.
22 class BASE_EXPORT FilteredServiceDirectory {
23  public:
24   // Creates a directory that proxies requests to the specified service
25   // |directory|.
26   explicit FilteredServiceDirectory(
27       std::shared_ptr<sys::ServiceDirectory> directory);
28 
29   FilteredServiceDirectory(const FilteredServiceDirectory&) = delete;
30   FilteredServiceDirectory& operator=(const FilteredServiceDirectory&) = delete;
31 
32   ~FilteredServiceDirectory();
33 
34   // Adds the specified service to the list of allowed services.
35   // Returns a status other than ZX_OK if the service cannot be added, e.g.
36   // because it is already in the list of allowed services.
37   [[nodiscard]] zx_status_t AddService(StringPiece service_name);
38 
39   // Connects a directory client. The directory can be passed to a sandboxed
40   // process to be used for /svc namespace.
41   [[nodiscard]] zx_status_t ConnectClient(
42       fidl::InterfaceRequest<::fuchsia::io::Directory> dir_request);
43 
44   // Accessor for the OutgoingDirectory, used to add handlers for services
45   // in addition to those provided from |directory| via AddService().
outgoing_directory()46   sys::OutgoingDirectory* outgoing_directory() { return &outgoing_directory_; }
47 
48  private:
49   const std::shared_ptr<sys::ServiceDirectory> directory_;
50   sys::OutgoingDirectory outgoing_directory_;
51 };
52 
53 }  // namespace base
54 
55 #endif  // BASE_FUCHSIA_FILTERED_SERVICE_DIRECTORY_H_
56