process_util.cc 1.5 KB

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