electron_bindings.h 2.7 KB

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