process_util.cc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #include "gin/dictionary.h"
  9. #include "shell/common/gin_converters/callback_converter.h"
  10. #include "shell/common/node_includes.h"
  11. namespace electron {
  12. void EmitWarning(node::Environment* env,
  13. const std::string& warning_msg,
  14. const std::string& warning_type) {
  15. v8::HandleScope scope(env->isolate());
  16. gin::Dictionary process(env->isolate(), env->process_object());
  17. base::RepeatingCallback<void(std::string_view, std::string_view,
  18. std::string_view)>
  19. emit_warning;
  20. process.Get("emitWarning", &emit_warning);
  21. emit_warning.Run(warning_msg, warning_type, "");
  22. }
  23. std::string GetProcessType() {
  24. auto* command_line = base::CommandLine::ForCurrentProcess();
  25. return command_line->GetSwitchValueASCII(switches::kProcessType);
  26. }
  27. bool IsBrowserProcess() {
  28. static bool result = GetProcessType().empty();
  29. return result;
  30. }
  31. bool IsRendererProcess() {
  32. static bool result = GetProcessType() == switches::kRendererProcess;
  33. return result;
  34. }
  35. bool IsUtilityProcess() {
  36. static bool result = GetProcessType() == switches::kUtilityProcess;
  37. return result;
  38. }
  39. bool IsZygoteProcess() {
  40. static bool result = GetProcessType() == switches::kZygoteProcess;
  41. return result;
  42. }
  43. } // namespace electron