process_util.cc 957 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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>
  6. #include <string_view>
  7. #include "base/command_line.h"
  8. #include "content/public/common/content_switches.h"
  9. namespace electron {
  10. std::string GetProcessType() {
  11. auto* command_line = base::CommandLine::ForCurrentProcess();
  12. return command_line->GetSwitchValueASCII(switches::kProcessType);
  13. }
  14. bool IsBrowserProcess() {
  15. static bool result = GetProcessType().empty();
  16. return result;
  17. }
  18. bool IsRendererProcess() {
  19. static bool result = GetProcessType() == switches::kRendererProcess;
  20. return result;
  21. }
  22. bool IsUtilityProcess() {
  23. static bool result = GetProcessType() == switches::kUtilityProcess;
  24. return result;
  25. }
  26. bool IsZygoteProcess() {
  27. static bool result = GetProcessType() == switches::kZygoteProcess;
  28. return result;
  29. }
  30. } // namespace electron