Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors |
Kevin Marshall | 32eca51 | 2017-08-25 20:25:03 | [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 BASE_FUCHSIA_DEFAULT_JOB_H_ |
| 6 | #define BASE_FUCHSIA_DEFAULT_JOB_H_ |
| 7 | |
Wez | 82017b0e | 2018-07-09 17:21:10 | [diff] [blame] | 8 | #include <lib/zx/job.h> |
| 9 | |
Sergey Ulanov | 481a0489 | 2017-10-24 17:11:43 | [diff] [blame] | 10 | #include "base/base_export.h" |
Kevin Marshall | 32eca51 | 2017-08-25 20:25:03 | [diff] [blame] | 11 | |
| 12 | namespace base { |
| 13 | |
| 14 | // Gets and sets the job object used for creating new child processes, |
| 15 | // and looking them up by their process IDs. |
Wez | 82017b0e | 2018-07-09 17:21:10 | [diff] [blame] | 16 | // zx::job::default_job() will be returned if no job is explicitly set here. |
Kevin Marshall | 32eca51 | 2017-08-25 20:25:03 | [diff] [blame] | 17 | // Only valid handles may be passed to SetDefaultJob(). |
Wez | 82017b0e | 2018-07-09 17:21:10 | [diff] [blame] | 18 | BASE_EXPORT zx::unowned_job GetDefaultJob(); |
| 19 | BASE_EXPORT void SetDefaultJob(zx::job job); |
Kevin Marshall | 32eca51 | 2017-08-25 20:25:03 | [diff] [blame] | 20 | |
Wez | 5c40bf76 | 2019-02-01 23:08:18 | [diff] [blame] | 21 | // Replaces the current default job (if any) with the specified zx::job, and |
| 22 | // restores the original default job when going out-of-scope. |
| 23 | // Note that replacing the default job is not thread-safe! |
| 24 | class BASE_EXPORT ScopedDefaultJobForTest { |
| 25 | public: |
| 26 | ScopedDefaultJobForTest(zx::job new_default_job); |
Peter Boström | 7319bbd | 2021-09-15 22:59:38 | [diff] [blame] | 27 | |
| 28 | ScopedDefaultJobForTest(const ScopedDefaultJobForTest&) = delete; |
| 29 | ScopedDefaultJobForTest& operator=(const ScopedDefaultJobForTest&) = delete; |
| 30 | |
Wez | 5c40bf76 | 2019-02-01 23:08:18 | [diff] [blame] | 31 | ~ScopedDefaultJobForTest(); |
| 32 | |
| 33 | private: |
| 34 | zx::job old_default_job_; |
Wez | 5c40bf76 | 2019-02-01 23:08:18 | [diff] [blame] | 35 | }; |
| 36 | |
Kevin Marshall | 32eca51 | 2017-08-25 20:25:03 | [diff] [blame] | 37 | } // namespace base |
| 38 | |
| 39 | #endif // BASE_FUCHSIA_DEFAULT_JOB_H_ |