process_stubs.cc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/process/process.h"
  5. #include <limits>
  6. #include "base/immediate_crash.h"
  7. namespace base {
  8. static constexpr ProcessHandle kCurrentProcessHandle =
  9. std::numeric_limits<ProcessHandle>::max();
  10. Process::Process(ProcessHandle handle) : process_(handle) {
  11. DCHECK(handle == kNullProcessHandle || handle == kCurrentProcessHandle);
  12. }
  13. Process::Process(Process&& other) : process_(other.process_) {
  14. other.Close();
  15. }
  16. Process::~Process() = default;
  17. Process& Process::operator=(Process&& other) {
  18. process_ = other.process_;
  19. other.Close();
  20. return *this;
  21. }
  22. // static
  23. Process Process::Current() {
  24. return Process(kCurrentProcessHandle);
  25. }
  26. // static
  27. Process Process::Open(ProcessId pid) {
  28. return Process(pid);
  29. }
  30. // static
  31. Process Process::OpenWithExtraPrivileges(ProcessId pid) {
  32. return Process(pid);
  33. }
  34. // static
  35. void Process::TerminateCurrentProcessImmediately(int exit_code) {
  36. // This method is marked noreturn, so we crash rather than just provide an
  37. // empty stub implementation.
  38. IMMEDIATE_CRASH();
  39. }
  40. bool Process::IsValid() const {
  41. return process_ != kNullProcessHandle;
  42. }
  43. ProcessHandle Process::Handle() const {
  44. return process_;
  45. }
  46. Process Process::Duplicate() const {
  47. return Process(process_);
  48. }
  49. ProcessHandle Process::Release() {
  50. ProcessHandle handle = process_;
  51. Close();
  52. return handle;
  53. }
  54. ProcessId Process::Pid() const {
  55. return process_;
  56. }
  57. Time Process::CreationTime() const {
  58. return Time();
  59. }
  60. bool Process::is_current() const {
  61. return Handle() == kCurrentProcessHandle;
  62. }
  63. void Process::Close() {
  64. process_ = kNullProcessHandle;
  65. }
  66. bool Process::WaitForExit(int* exit_code) const {
  67. return false;
  68. }
  69. bool Process::WaitForExitWithTimeout(TimeDelta timeout, int* exit_code) const {
  70. return false;
  71. }
  72. void Process::Exited(int exit_code) const {}
  73. bool Process::IsProcessBackgrounded() const {
  74. return false;
  75. }
  76. bool Process::SetProcessBackgrounded(bool value) {
  77. return false;
  78. }
  79. int Process::GetPriority() const {
  80. return -1;
  81. }
  82. } // namespace base