1 // Copyright 2017 The Chromium Authors 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 8 #include <lib/zx/job.h> 9 10 #include "base/base_export.h" 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. 16 // zx::job::default_job() will be returned if no job is explicitly set here. 17 // Only valid handles may be passed to SetDefaultJob(). 18 BASE_EXPORT zx::unowned_job GetDefaultJob(); 19 BASE_EXPORT void SetDefaultJob(zx::job job); 20 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); 27 28 ScopedDefaultJobForTest(const ScopedDefaultJobForTest&) = delete; 29 ScopedDefaultJobForTest& operator=(const ScopedDefaultJobForTest&) = delete; 30 31 ~ScopedDefaultJobForTest(); 32 33 private: 34 zx::job old_default_job_; 35 }; 36 37 } // namespace base 38 39 #endif // BASE_FUCHSIA_DEFAULT_JOB_H_ 40