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