atom_bindings.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 "base/macros.h"
  8. #include "base/process/process_metrics.h"
  9. #include "base/strings/string16.h"
  10. #include "native_mate/arguments.h"
  11. #include "uv.h" // NOLINT(build/include)
  12. #include "v8/include/v8.h"
  13. namespace node {
  14. class Environment;
  15. }
  16. namespace atom {
  17. class AtomBindings {
  18. public:
  19. explicit AtomBindings(uv_loop_t* loop);
  20. virtual ~AtomBindings();
  21. // Add process.atomBinding function, which behaves like process.binding but
  22. // load native code from Electron instead.
  23. void BindTo(v8::Isolate* isolate, v8::Local<v8::Object> process);
  24. // Should be called when a node::Environment has been destroyed.
  25. void EnvironmentDestroyed(node::Environment* env);
  26. static void Log(const base::string16& message);
  27. static void Crash();
  28. static void Hang();
  29. static v8::Local<v8::Value> GetHeapStatistics(v8::Isolate* isolate);
  30. static v8::Local<v8::Value> GetProcessMemoryInfo(v8::Isolate* isolate);
  31. static v8::Local<v8::Value> GetSystemMemoryInfo(v8::Isolate* isolate,
  32. mate::Arguments* args);
  33. v8::Local<v8::Value> GetCPUUsage(v8::Isolate* isolate);
  34. static v8::Local<v8::Value> GetIOCounters(v8::Isolate* isolate);
  35. private:
  36. void ActivateUVLoop(v8::Isolate* isolate);
  37. static void OnCallNextTick(uv_async_t* handle);
  38. uv_async_t call_next_tick_async_;
  39. std::list<node::Environment*> pending_next_ticks_;
  40. std::unique_ptr<base::ProcessMetrics> metrics_;
  41. DISALLOW_COPY_AND_ASSIGN(AtomBindings);
  42. };
  43. } // namespace atom
  44. #endif // ATOM_COMMON_API_ATOM_BINDINGS_H_