electron_bindings.h 2.6 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 ATOM_COMMON_API_ELECTRON_BINDINGS_H_
  5. #define ATOM_COMMON_API_ELECTRON_BINDINGS_H_
  6. #include <list>
  7. #include <memory>
  8. #include "atom/common/promise_util.h"
  9. #include "base/files/file_path.h"
  10. #include "base/macros.h"
  11. #include "base/memory/scoped_refptr.h"
  12. #include "base/process/process_metrics.h"
  13. #include "base/strings/string16.h"
  14. #include "native_mate/arguments.h"
  15. #include "uv.h" // NOLINT(build/include)
  16. #include "v8/include/v8.h"
  17. namespace mate {
  18. class Dictionary;
  19. }
  20. namespace memory_instrumentation {
  21. class GlobalMemoryDump;
  22. }
  23. namespace node {
  24. class Environment;
  25. }
  26. namespace atom {
  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. mate::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. mate::Arguments* args);
  47. static v8::Local<v8::Promise> GetProcessMemoryInfo(v8::Isolate* isolate);
  48. static v8::Local<v8::Value> GetCPUUsage(base::ProcessMetrics* metrics,
  49. v8::Isolate* isolate);
  50. static v8::Local<v8::Value> GetIOCounters(v8::Isolate* isolate);
  51. static bool TakeHeapSnapshot(v8::Isolate* isolate,
  52. const base::FilePath& file_path);
  53. void ActivateUVLoop(v8::Isolate* isolate);
  54. static void OnCallNextTick(uv_async_t* handle);
  55. static void DidReceiveMemoryDump(
  56. v8::Global<v8::Context> context,
  57. util::Promise promise,
  58. bool success,
  59. std::unique_ptr<memory_instrumentation::GlobalMemoryDump> dump);
  60. 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 atom
  66. #endif // ATOM_COMMON_API_ELECTRON_BINDINGS_H_