blob: ee95b17accd0ef46f8d1afefc8bd1121767e43da [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2012 The Chromium Authors
Vladimir Levin11a23b12017-09-11 23:13:302// 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 Levin11a23b12017-09-11 23:13:309
Hans Wennborgf30ad802020-06-20 16:50:2010#include "base/check.h"
Avi Drissmanded77172021-07-02 18:23:0011#include "base/no_destructor.h"
Vladimir Levin11a23b12017-09-11 23:13:3012#include "base/threading/simple_thread.h"
13#include "content/browser/sandbox_ipc_linux.h"
Vladimir Levin11a23b12017-09-11 23:13:3014
Vladimir Levin11a23b12017-09-11 23:13:3015namespace content {
16
17// This is a singleton object which handles sandbox requests from the
18// sandboxed processes.
Lei Zhanged9be3a2021-11-17 22:01:1819class SandboxHostLinux {
Vladimir Levin11a23b12017-09-11 23:13:3020 public:
21 // Returns the singleton instance.
22 static SandboxHostLinux* GetInstance();
23
Peter Boström9b036532021-10-28 23:37:2824 SandboxHostLinux(const SandboxHostLinux&) = delete;
25 SandboxHostLinux& operator=(const SandboxHostLinux&) = delete;
26
Vladimir Levin11a23b12017-09-11 23:13:3027 // 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 Hanbaf7fa82018-04-12 14:42:1837 bool IsInitialized() const { return initialized_; }
38
Vladimir Levin11a23b12017-09-11 23:13:3039 private:
Gabriel Charette7d7d33a2019-01-16 20:59:5840 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 Levin11a23b12017-09-11 23:13:3044 SandboxHostLinux();
Gabriel Charette7d7d33a2019-01-16 20:59:5845 ~SandboxHostLinux() = delete;
Vladimir Levin11a23b12017-09-11 23:13:3046
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 Levin11a23b12017-09-11 23:13:3055};
56
57} // namespace content
58
Lei Zhang02a0ad72021-04-21 05:26:0859#endif // CONTENT_BROWSER_SANDBOX_HOST_LINUX_H_