Commit 92730f7b authored by Tal Pressman's avatar Tal Pressman Committed by Commit Bot

Clean-up BrowserMessageFilter::Send.

Wrap the message in a unique_ptr to make sure it isn't leaked, if some
branch doesn't pass it on to another sender or delete it.
Also change a conditional NOTREACHED to a DCHECK following the style
guide[1].


[1] chromium.googlesource.com/chromium/src/+/master/styleguide/c++/c++.md#check_dcheck_and-notreached

Change-Id: I149d2b28d462be32b7170c0b8973fe74ad74ed6b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2507277Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Tal Pressman <talp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822558}
parent 4e055126
...@@ -140,27 +140,26 @@ void BrowserMessageFilter::OnDestruct() const { ...@@ -140,27 +140,26 @@ void BrowserMessageFilter::OnDestruct() const {
} }
bool BrowserMessageFilter::Send(IPC::Message* message) { bool BrowserMessageFilter::Send(IPC::Message* message) {
if (message->is_sync()) { std::unique_ptr<IPC::Message> msg(message);
// We don't support sending synchronous messages from the browser. If we // We don't support sending synchronous messages from the browser. If we
// really needed it, we can make this class derive from SyncMessageFilter // really needed it, we can make this class derive from SyncMessageFilter
// but it seems better to not allow sending synchronous messages from the // but it seems better to not allow sending synchronous messages from the
// browser, since it might allow a corrupt/malicious renderer to hang us. // browser, since it might allow a corrupt/malicious renderer to hang us.
NOTREACHED() << "Can't send sync message through BrowserMessageFilter!"; DCHECK(!msg->is_sync())
return false; << "Can't send sync message through BrowserMessageFilter!";
}
if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
GetIOThreadTaskRunner({})->PostTask( GetIOThreadTaskRunner({})->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(base::IgnoreResult(&BrowserMessageFilter::Send), this, base::BindOnce(base::IgnoreResult(&BrowserMessageFilter::Send), this,
message)); msg.release()));
return true; return true;
} }
if (sender_) if (sender_)
return sender_->Send(message); return sender_->Send(msg.release());
delete message;
return false; return false;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment