Use weak pointer instead of manual bookkeeping

This commit is contained in:
Cheng Zhao 2016-02-16 10:44:10 +08:00
parent ed1966ac76
commit 66bb6a8534
3 changed files with 16 additions and 62 deletions

View file

@ -6,6 +6,7 @@
#define ATOM_BROWSER_API_FRAME_SUBSCRIBER_H_
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "content/public/browser/render_widget_host_view_frame_subscriber.h"
#include "ui/gfx/geometry/size.h"
#include "v8/include/v8.h"
@ -14,43 +15,28 @@ namespace atom {
namespace api {
class FrameSubscriber {
class FrameSubscriber : public content::RenderWidgetHostViewFrameSubscriber {
public:
using FrameCaptureCallback = base::Callback<void(v8::Local<v8::Value>)>;
// Inner class that is the actual subscriber sent to chromium
class Subscriber :
public content::RenderWidgetHostViewFrameSubscriber {
public:
explicit Subscriber(FrameSubscriber* frame_subscriber);
bool ShouldCaptureFrame(const gfx::Rect& damage_rect,
base::TimeTicks present_time,
scoped_refptr<media::VideoFrame>* storage,
DeliverFrameCallback* callback) override;
~Subscriber();
private:
FrameSubscriber* frame_subscriber_;
};
FrameSubscriber(v8::Isolate* isolate,
const gfx::Size& size,
const FrameCaptureCallback& callback);
Subscriber* GetSubscriber();
bool ShouldCaptureFrame(const gfx::Rect& damage_rect,
base::TimeTicks present_time,
scoped_refptr<media::VideoFrame>* storage,
DeliverFrameCallback* callback) override;
private:
void OnFrameDelivered(
scoped_refptr<media::VideoFrame> frame, base::TimeTicks, bool);
bool RequestDestruct();
v8::Isolate* isolate_;
gfx::Size size_;
FrameCaptureCallback callback_;
Subscriber* subscriber_;
int pending_frames;
base::WeakPtrFactory<FrameSubscriber> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(FrameSubscriber);
};