1 // Copyright 2018 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.
5 #ifndef BASE_FUCHSIA_FILTERED_SERVICE_DIRECTORY_H_
6 #define BASE_FUCHSIA_FILTERED_SERVICE_DIRECTORY_H_
8 #include "base/fuchsia/service_directory.h"
10 #include <fuchsia/io/cpp/fidl.h>
11 #include <lib/fidl/cpp/interface_handle.h>
12 #include <lib/zx/channel.h>
15 #include "base/macros.h"
20 class ServiceDirectoryClient;
22 // ServiceDirectory that uses the supplied ServiceDirectoryClient to satisfy
23 // requests for only a restricted set of services.
24 class BASE_EXPORT FilteredServiceDirectory {
26 // Creates proxy that proxies requests to the specified service |directory|,
27 // which must outlive the proxy.
28 explicit FilteredServiceDirectory(const ServiceDirectoryClient* directory);
29 ~FilteredServiceDirectory();
31 // Adds the specified service to the list of whitelisted services.
32 void AddService(const char* service_name);
34 // Returns a client channel connected to the directory. The returned channel
35 // can be passed to a sandboxed process to be used for /svc namespace.
36 fidl::InterfaceHandle<::fuchsia::io::Directory> ConnectClient();
39 void HandleRequest(const char* service_name, zx::channel channel);
41 const ServiceDirectoryClient* const directory_;
42 std::unique_ptr<ServiceDirectory> outgoing_directory_;
44 // Client side of the channel used by |outgoing_directory_|.
45 fidl::InterfaceHandle<::fuchsia::io::Directory> outgoing_directory_client_;
47 DISALLOW_COPY_AND_ASSIGN(FilteredServiceDirectory);
50 } // namespace fuchsia
53 #endif // BASE_FUCHSIA_FILTERED_SERVICE_DIRECTORY_H_