process_util.cc 938 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright (c) 2019 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/common/process_util.h"
  5. #include <string_view>
  6. #include "base/command_line.h"
  7. #include "content/public/common/content_switches.h"
  8. namespace electron {
  9. std::string GetProcessType() {
  10. auto* command_line = base::CommandLine::ForCurrentProcess();
  11. return command_line->GetSwitchValueASCII(switches::kProcessType);
  12. }
  13. bool IsBrowserProcess() {
  14. static bool result = GetProcessType().empty();
  15. return result;
  16. }
  17. bool IsRendererProcess() {
  18. static bool result = GetProcessType() == switches::kRendererProcess;
  19. return result;
  20. }
  21. bool IsUtilityProcess() {
  22. static bool result = GetProcessType() == switches::kUtilityProcess;
  23. return result;
  24. }
  25. bool IsZygoteProcess() {
  26. static bool result = GetProcessType() == switches::kZygoteProcess;
  27. return result;
  28. }
  29. } // namespace electron