blob: 9ef0a7d6fd86fd7289361e1ed9ee2f9ddf687857 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2017 The Chromium Authors
Kevin Marshall32eca512017-08-25 20:25:032// 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
Wez82017b0e2018-07-09 17:21:108#include <lib/zx/job.h>
9
Sergey Ulanov481a04892017-10-24 17:11:4310#include "base/base_export.h"
Kevin Marshall32eca512017-08-25 20:25:0311
12namespace base {
13
14// Gets and sets the job object used for creating new child processes,
15// and looking them up by their process IDs.
Wez82017b0e2018-07-09 17:21:1016// zx::job::default_job() will be returned if no job is explicitly set here.
Kevin Marshall32eca512017-08-25 20:25:0317// Only valid handles may be passed to SetDefaultJob().
Wez82017b0e2018-07-09 17:21:1018BASE_EXPORT zx::unowned_job GetDefaultJob();
19BASE_EXPORT void SetDefaultJob(zx::job job);
Kevin Marshall32eca512017-08-25 20:25:0320
Wez5c40bf762019-02-01 23:08:1821// 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!
24class BASE_EXPORT ScopedDefaultJobForTest {
25 public:
26 ScopedDefaultJobForTest(zx::job new_default_job);
Peter Boström7319bbd2021-09-15 22:59:3827
28 ScopedDefaultJobForTest(const ScopedDefaultJobForTest&) = delete;
29 ScopedDefaultJobForTest& operator=(const ScopedDefaultJobForTest&) = delete;
30
Wez5c40bf762019-02-01 23:08:1831 ~ScopedDefaultJobForTest();
32
33 private:
34 zx::job old_default_job_;
Wez5c40bf762019-02-01 23:08:1835};
36
Kevin Marshall32eca512017-08-25 20:25:0337} // namespace base
38
39#endif // BASE_FUCHSIA_DEFAULT_JOB_H_