Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
Vladimir Levin | 11a23b1 | 2017-09-11 23:13:30 | [diff] [blame] | 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 CONTENT_BROWSER_SANDBOX_HOST_LINUX_H_ |
| 6 | #define CONTENT_BROWSER_SANDBOX_HOST_LINUX_H_ |
| 7 | |
| 8 | #include <memory> |
Vladimir Levin | 11a23b1 | 2017-09-11 23:13:30 | [diff] [blame] | 9 | |
Hans Wennborg | f30ad80 | 2020-06-20 16:50:20 | [diff] [blame] | 10 | #include "base/check.h" |
Avi Drissman | ded7717 | 2021-07-02 18:23:00 | [diff] [blame] | 11 | #include "base/no_destructor.h" |
Vladimir Levin | 11a23b1 | 2017-09-11 23:13:30 | [diff] [blame] | 12 | #include "base/threading/simple_thread.h" |
| 13 | #include "content/browser/sandbox_ipc_linux.h" |
Vladimir Levin | 11a23b1 | 2017-09-11 23:13:30 | [diff] [blame] | 14 | |
Vladimir Levin | 11a23b1 | 2017-09-11 23:13:30 | [diff] [blame] | 15 | namespace content { |
| 16 | |
| 17 | // This is a singleton object which handles sandbox requests from the |
| 18 | // sandboxed processes. |
Lei Zhang | ed9be3a | 2021-11-17 22:01:18 | [diff] [blame] | 19 | class SandboxHostLinux { |
Vladimir Levin | 11a23b1 | 2017-09-11 23:13:30 | [diff] [blame] | 20 | public: |
| 21 | // Returns the singleton instance. |
| 22 | static SandboxHostLinux* GetInstance(); |
| 23 | |
Peter Boström | 9b03653 | 2021-10-28 23:37:28 | [diff] [blame] | 24 | SandboxHostLinux(const SandboxHostLinux&) = delete; |
| 25 | SandboxHostLinux& operator=(const SandboxHostLinux&) = delete; |
| 26 | |
Vladimir Levin | 11a23b1 | 2017-09-11 23:13:30 | [diff] [blame] | 27 | // Get the file descriptor which sandboxed processes should be given in order |
| 28 | // to communicate with the browser. This is used for things like communicating |
| 29 | // renderer crashes to the browser, as well as requesting fonts from sandboxed |
| 30 | // processes. |
| 31 | int GetChildSocket() const { |
| 32 | DCHECK(initialized_); |
| 33 | return child_socket_; |
| 34 | } |
| 35 | void Init(); |
| 36 | |
Xi Han | baf7fa8 | 2018-04-12 14:42:18 | [diff] [blame] | 37 | bool IsInitialized() const { return initialized_; } |
| 38 | |
Vladimir Levin | 11a23b1 | 2017-09-11 23:13:30 | [diff] [blame] | 39 | private: |
Gabriel Charette | 7d7d33a | 2019-01-16 20:59:58 | [diff] [blame] | 40 | friend class base::NoDestructor<SandboxHostLinux>; |
| 41 | // This object must be constructed on the main thread. It then lives for the |
| 42 | // lifetime of the process (and resources are reclaimed by the OS when the |
| 43 | // process dies). |
Vladimir Levin | 11a23b1 | 2017-09-11 23:13:30 | [diff] [blame] | 44 | SandboxHostLinux(); |
Gabriel Charette | 7d7d33a | 2019-01-16 20:59:58 | [diff] [blame] | 45 | ~SandboxHostLinux() = delete; |
Vladimir Levin | 11a23b1 | 2017-09-11 23:13:30 | [diff] [blame] | 46 | |
| 47 | // Whether Init() has been called yet. |
| 48 | bool initialized_ = false; |
| 49 | |
| 50 | int child_socket_ = 0; |
| 51 | int childs_lifeline_fd_ = 0; |
| 52 | |
| 53 | std::unique_ptr<SandboxIPCHandler> ipc_handler_; |
| 54 | std::unique_ptr<base::DelegateSimpleThread> ipc_thread_; |
Vladimir Levin | 11a23b1 | 2017-09-11 23:13:30 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | } // namespace content |
| 58 | |
Lei Zhang | 02a0ad7 | 2021-04-21 05:26:08 | [diff] [blame] | 59 | #endif // CONTENT_BROWSER_SANDBOX_HOST_LINUX_H_ |