object_life_monitor.h 936 B

1234567891011121314151617181920212223242526272829303132333435
  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_OBJECT_LIFE_MONITOR_H_
  5. #define ATOM_COMMON_API_OBJECT_LIFE_MONITOR_H_
  6. #include "base/macros.h"
  7. #include "base/memory/weak_ptr.h"
  8. #include "v8/include/v8.h"
  9. namespace atom {
  10. class ObjectLifeMonitor {
  11. protected:
  12. ObjectLifeMonitor(v8::Isolate* isolate, v8::Local<v8::Object> target);
  13. virtual ~ObjectLifeMonitor();
  14. virtual void RunDestructor() = 0;
  15. private:
  16. static void OnObjectGC(const v8::WeakCallbackInfo<ObjectLifeMonitor>& data);
  17. static void Free(const v8::WeakCallbackInfo<ObjectLifeMonitor>& data);
  18. v8::Global<v8::Context> context_;
  19. v8::Global<v8::Object> target_;
  20. base::WeakPtrFactory<ObjectLifeMonitor> weak_ptr_factory_;
  21. DISALLOW_COPY_AND_ASSIGN(ObjectLifeMonitor);
  22. };
  23. } // namespace atom
  24. #endif // ATOM_COMMON_API_OBJECT_LIFE_MONITOR_H_