Merge pull request #13658 from trop-bot/3-0-x-bp-fix--don't-invoke-callback-after-framesubscriber-is-destroyed-1531475760693

fix: don't invoke callback after FrameSubscriber is destroyed (backport: 3-0-x)
This commit is contained in:
John Kleinschmidt 2018-07-13 11:51:07 -04:00 committed by GitHub
commit 74e6e063d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View file

@ -26,7 +26,8 @@ FrameSubscriber::FrameSubscriber(v8::Isolate* isolate,
: content::WebContentsObserver(web_contents), : content::WebContentsObserver(web_contents),
isolate_(isolate), isolate_(isolate),
callback_(callback), callback_(callback),
only_dirty_(only_dirty) {} only_dirty_(only_dirty),
weak_ptr_factory_(this) {}
FrameSubscriber::~FrameSubscriber() = default; FrameSubscriber::~FrameSubscriber() = default;
@ -64,7 +65,7 @@ void FrameSubscriber::DidReceiveCompositorFrame() {
view->CopyFromSurface( view->CopyFromSurface(
gfx::Rect(), view->GetViewBounds().size(), gfx::Rect(), view->GetViewBounds().size(),
base::BindOnce(&FrameSubscriber::Done, base::Unretained(this), base::BindOnce(&FrameSubscriber::Done, weak_ptr_factory_.GetWeakPtr(),
GetDamageRect())); GetDamageRect()));
} }

View file

@ -8,6 +8,7 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "components/viz/common/frame_sinks/copy_output_result.h" #include "components/viz/common/frame_sinks/copy_output_result.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
@ -39,6 +40,8 @@ class FrameSubscriber : public content::WebContentsObserver {
FrameCaptureCallback callback_; FrameCaptureCallback callback_;
bool only_dirty_; bool only_dirty_;
base::WeakPtrFactory<FrameSubscriber> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(FrameSubscriber); DISALLOW_COPY_AND_ASSIGN(FrameSubscriber);
}; };