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

Unified Diff: media/gpu/ipc/client/gpu_jpeg_decode_accelerator_host.cc

Issue 2783273002: Fix DCHECK getting hit on destruction of GpuJpegDecodeAcceleratorHost (Closed)
Patch Set: Created 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/gpu/ipc/client/gpu_jpeg_decode_accelerator_host.cc
diff --git a/media/gpu/ipc/client/gpu_jpeg_decode_accelerator_host.cc b/media/gpu/ipc/client/gpu_jpeg_decode_accelerator_host.cc
index fca7a5b7741e500bcc18d6ebda152630076e6747..7b815772b47ac303710189dc57270e969232b84e 100644
--- a/media/gpu/ipc/client/gpu_jpeg_decode_accelerator_host.cc
+++ b/media/gpu/ipc/client/gpu_jpeg_decode_accelerator_host.cc
@@ -31,15 +31,20 @@ class GpuJpegDecodeAcceleratorHost::Receiver : public IPC::Listener,
const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
: client_(client),
io_task_runner_(io_task_runner),
- weak_factory_for_io_(this) {
+ weak_factory_for_io_(
+ base::MakeUnique<base::WeakPtrFactory<Receiver>>(this)) {
sandersd (OOO until July 31) 2017/03/30 20:58:50 I recommend creating a WeakPtr here in the constru
chfremer 2017/03/30 21:19:45 Done.
DCHECK(CalledOnValidThread());
}
- ~Receiver() override { DCHECK(CalledOnValidThread()); }
+ ~Receiver() override {
+ DCHECK(CalledOnValidThread());
+ if (weak_factory_for_io_->HasWeakPtrs())
sandersd (OOO until July 31) 2017/03/30 20:58:49 I recommend always posting this task, it would be
chfremer 2017/03/30 21:19:45 Done.
+ io_task_runner_->DeleteSoon(FROM_HERE, weak_factory_for_io_.release());
+ }
- void InvalidateWeakPtr(base::WaitableEvent* event) {
+ void InvalidateWeakPtrOnIOThread(base::WaitableEvent* event) {
DCHECK(io_task_runner_->BelongsToCurrentThread());
- weak_factory_for_io_.InvalidateWeakPtrs();
+ weak_factory_for_io_->InvalidateWeakPtrs();
event->Signal();
}
@@ -63,7 +68,7 @@ class GpuJpegDecodeAcceleratorHost::Receiver : public IPC::Listener,
}
base::WeakPtr<IPC::Listener> AsWeakPtrForIO() {
- return weak_factory_for_io_.GetWeakPtr();
+ return weak_factory_for_io_->GetWeakPtr();
}
private:
@@ -91,7 +96,7 @@ class GpuJpegDecodeAcceleratorHost::Receiver : public IPC::Listener,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
// Weak pointers will be invalidated on IO thread.
- base::WeakPtrFactory<Receiver> weak_factory_for_io_;
+ std::unique_ptr<base::WeakPtrFactory<Receiver>> weak_factory_for_io_;
DISALLOW_COPY_AND_ASSIGN(Receiver);
};
@@ -119,7 +124,7 @@ GpuJpegDecodeAcceleratorHost::~GpuJpegDecodeAcceleratorHost() {
base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC,
base::WaitableEvent::InitialState::NOT_SIGNALED);
bool task_expected_to_run = io_task_runner_->PostTask(
- FROM_HERE, base::Bind(&Receiver::InvalidateWeakPtr,
+ FROM_HERE, base::Bind(&Receiver::InvalidateWeakPtrOnIOThread,
base::Unretained(receiver_.get()),
sandersd (OOO until July 31) 2017/03/30 20:58:50 I'd add a comment here explaining that Unretained
chfremer 2017/03/30 21:19:45 Done.
base::Unretained(&event)));
// If the current call is happening during the browser shutdown, the
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698