Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(914)

Unified Diff: content/renderer/media/canvas_capture_handler.cc

Issue 1829563002: Handle early destruction of CanvasCaptureHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/canvas_capture_handler.cc
diff --git a/content/renderer/media/canvas_capture_handler.cc b/content/renderer/media/canvas_capture_handler.cc
index fd6e55f26818448d57e3964dac05b3526b0778f5..6056712c7e26771aeec93040d70aef26c9bc7f9f 100644
--- a/content/renderer/media/canvas_capture_handler.cc
+++ b/content/renderer/media/canvas_capture_handler.cc
@@ -23,8 +23,11 @@
namespace content {
-class CanvasCaptureHandler::VideoCapturerSource
- : public media::VideoCapturerSource {
+// Implementation VideoCapturerSource that is owned by
+// MediaStreamVideoCapturerSource and delegates the Start/Stop calls to
+// CanvasCaptureHandler.
+// This class is single threaded and pinned to main render thread.
+class VideoCapturerSource : public media::VideoCapturerSource {
public:
explicit VideoCapturerSource(base::WeakPtr<CanvasCaptureHandler>
canvas_handler,
@@ -58,15 +61,16 @@ class CanvasCaptureHandler::VideoCapturerSource
}
void StopCapture() override {
DCHECK(main_render_thread_checker_.CalledOnValidThread());
- canvas_handler_->StopVideoCapture();
+ if (canvas_handler_.get())
+ canvas_handler_->StopVideoCapture();
}
private:
- double frame_rate_;
+ const double frame_rate_;
// Bound to Main Render thread.
base::ThreadChecker main_render_thread_checker_;
- // CanvasCaptureHandler is owned by CanvasDrawListener in blink and
- // guaranteed to be alive during the lifetime of this class.
+ // CanvasCaptureHandler is owned by CanvasDrawListener in blink and might be
+ // destroyed before StopCapture() call.
base::WeakPtr<CanvasCaptureHandler> canvas_handler_;
};
@@ -113,8 +117,7 @@ CanvasCaptureHandler::CanvasCaptureHandler(
io_task_runner_(io_task_runner),
weak_ptr_factory_(this) {
scoped_ptr<media::VideoCapturerSource> video_source(
- new CanvasCaptureHandler::VideoCapturerSource(
- weak_ptr_factory_.GetWeakPtr(), frame_rate));
+ new VideoCapturerSource(weak_ptr_factory_.GetWeakPtr(), frame_rate));
AddVideoCapturerSourceToVideoTrack(std::move(video_source), track);
}
« no previous file with comments | « content/renderer/media/canvas_capture_handler.h ('k') | content/renderer/media/canvas_capture_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698