Upload upstream chromium 76.0.3809.146
[platform/framework/web/chromium-efl.git] / base / fuchsia / filtered_service_directory.h
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.
4
5 #ifndef BASE_FUCHSIA_FILTERED_SERVICE_DIRECTORY_H_
6 #define BASE_FUCHSIA_FILTERED_SERVICE_DIRECTORY_H_
7
8 #include "base/fuchsia/service_directory.h"
9
10 #include <fuchsia/io/cpp/fidl.h>
11 #include <lib/fidl/cpp/interface_handle.h>
12 #include <lib/zx/channel.h>
13 #include <memory>
14
15 #include "base/macros.h"
16
17 namespace base {
18 namespace fuchsia {
19
20 class ServiceDirectoryClient;
21
22 // ServiceDirectory that uses the supplied ServiceDirectoryClient to satisfy
23 // requests for only a restricted set of services.
24 class BASE_EXPORT FilteredServiceDirectory {
25  public:
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();
30
31   // Adds the specified service to the list of whitelisted services.
32   void AddService(const char* service_name);
33
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();
37
38  private:
39   void HandleRequest(const char* service_name, zx::channel channel);
40
41   const ServiceDirectoryClient* const directory_;
42   std::unique_ptr<ServiceDirectory> outgoing_directory_;
43
44   // Client side of the channel used by |outgoing_directory_|.
45   fidl::InterfaceHandle<::fuchsia::io::Directory> outgoing_directory_client_;
46
47   DISALLOW_COPY_AND_ASSIGN(FilteredServiceDirectory);
48 };
49
50 }  // namespace fuchsia
51 }  // namespace base
52
53 #endif  // BASE_FUCHSIA_FILTERED_SERVICE_DIRECTORY_H_