atom_bindings.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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_ATOM_BINDINGS_H_
  5. #define ATOM_COMMON_API_ATOM_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 "native_mate/arguments.h"
  14. #include "uv.h" // NOLINT(build/include)
  15. #include "v8/include/v8.h"
  16. namespace memory_instrumentation {
  17. class GlobalMemoryDump;
  18. }
  19. namespace node {
  20. class Environment;
  21. }
  22. namespace atom {
  23. namespace util {
  24. class Promise;
  25. }
  26. class AtomBindings {
  27. public:
  28. explicit AtomBindings(uv_loop_t* loop);
  29. virtual ~AtomBindings();
  30. // Add process.atomBinding function, which behaves like process.binding but
  31. // 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 Log(const base::string16& message);
  36. static void Crash();
  37. static void Hang();
  38. static v8::Local<v8::Value> GetHeapStatistics(v8::Isolate* isolate);
  39. static v8::Local<v8::Value> GetCreationTime(v8::Isolate* isolate);
  40. static v8::Local<v8::Value> GetSystemMemoryInfo(v8::Isolate* isolate,
  41. mate::Arguments* args);
  42. static v8::Local<v8::Promise> GetProcessMemoryInfo(v8::Isolate* isolate);
  43. static v8::Local<v8::Value> GetCPUUsage(base::ProcessMetrics* metrics,
  44. v8::Isolate* isolate);
  45. static v8::Local<v8::Value> GetIOCounters(v8::Isolate* isolate);
  46. static bool TakeHeapSnapshot(v8::Isolate* isolate,
  47. const base::FilePath& file_path);
  48. private:
  49. void ActivateUVLoop(v8::Isolate* isolate);
  50. static void OnCallNextTick(uv_async_t* handle);
  51. static void DidReceiveMemoryDump(
  52. const v8::Global<v8::Context>& context,
  53. scoped_refptr<util::Promise> promise,
  54. bool success,
  55. std::unique_ptr<memory_instrumentation::GlobalMemoryDump> dump);
  56. uv_async_t call_next_tick_async_;
  57. std::list<node::Environment*> pending_next_ticks_;
  58. std::unique_ptr<base::ProcessMetrics> metrics_;
  59. DISALLOW_COPY_AND_ASSIGN(AtomBindings);
  60. };
  61. } // namespace atom
  62. #endif // ATOM_COMMON_API_ATOM_BINDINGS_H_