electron_bindings.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright (c) 2013 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_COMMON_API_ELECTRON_BINDINGS_H_
  5. #define ELECTRON_SHELL_COMMON_API_ELECTRON_BINDINGS_H_
  6. #include <list>
  7. #include <memory>
  8. #include "base/files/file_path.h"
  9. #include "base/memory/scoped_refptr.h"
  10. #include "base/process/process_metrics.h"
  11. #include "shell/common/gin_helper/promise.h"
  12. #include "shell/common/node_bindings.h"
  13. #include "uv.h" // NOLINT(build/include_directory)
  14. namespace gin_helper {
  15. class Arguments;
  16. class Dictionary;
  17. } // namespace gin_helper
  18. namespace memory_instrumentation {
  19. class GlobalMemoryDump;
  20. }
  21. namespace node {
  22. class Environment;
  23. }
  24. namespace electron {
  25. class ElectronBindings {
  26. public:
  27. explicit ElectronBindings(uv_loop_t* loop);
  28. virtual ~ElectronBindings();
  29. // disable copy
  30. ElectronBindings(const ElectronBindings&) = delete;
  31. ElectronBindings& operator=(const ElectronBindings&) = delete;
  32. // Add process._linkedBinding function, which behaves like process.binding
  33. // but load native code from Electron instead.
  34. void BindTo(v8::Isolate* isolate, v8::Local<v8::Object> process);
  35. // Should be called when a node::Environment has been destroyed.
  36. void EnvironmentDestroyed(node::Environment* env);
  37. static void BindProcess(v8::Isolate* isolate,
  38. gin_helper::Dictionary* process,
  39. base::ProcessMetrics* metrics);
  40. static void Crash();
  41. static void DidReceiveMemoryDump(
  42. v8::Global<v8::Context> context,
  43. gin_helper::Promise<gin_helper::Dictionary> promise,
  44. base::ProcessId target_pid,
  45. bool success,
  46. std::unique_ptr<memory_instrumentation::GlobalMemoryDump> dump);
  47. private:
  48. static void Hang();
  49. static v8::Local<v8::Value> GetHeapStatistics(v8::Isolate* isolate);
  50. static v8::Local<v8::Value> GetCreationTime(v8::Isolate* isolate);
  51. static v8::Local<v8::Value> GetSystemMemoryInfo(v8::Isolate* isolate,
  52. gin_helper::Arguments* args);
  53. static v8::Local<v8::Promise> GetProcessMemoryInfo(v8::Isolate* isolate);
  54. static v8::Local<v8::Value> GetBlinkMemoryInfo(v8::Isolate* isolate);
  55. static v8::Local<v8::Value> GetCPUUsage(base::ProcessMetrics* metrics,
  56. v8::Isolate* isolate);
  57. static v8::Local<v8::Value> GetIOCounters(v8::Isolate* isolate);
  58. static bool TakeHeapSnapshot(v8::Isolate* isolate,
  59. const base::FilePath& file_path);
  60. void ActivateUVLoop(v8::Isolate* isolate);
  61. static void OnCallNextTick(uv_async_t* handle);
  62. UvHandle<uv_async_t> call_next_tick_async_;
  63. std::list<node::Environment*> pending_next_ticks_;
  64. std::unique_ptr<base::ProcessMetrics> metrics_;
  65. };
  66. } // namespace electron
  67. #endif // ELECTRON_SHELL_COMMON_API_ELECTRON_BINDINGS_H_