Commit 77d3c460 authored by Elad Alon's avatar Elad Alon Committed by Commit Bot

Use WeakPtr in WebRtcEventLogUploaderImpl

This takes care of the case where `url_loader_` posts the callback,
then Cancel() is called before the callback's task was executed,
deleting the object. Following this CL, since now a WeakPtr is used,
that task will just be nullified.

Bug: 1092071
Change-Id: If93c9f9ebef272a648d5eaf9578c5f060de48263
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2260614
Commit-Queue: Elad Alon <eladalon@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781933}
parent 0fd83141
......@@ -298,12 +298,10 @@ void WebRtcEventLogUploaderImpl::StartUpload(const std::string& upload_data) {
url_loader_->SetOnUploadProgressCallback(
base::BindRepeating(OnURLLoadUploadProgress));
// See comment in destructor for an explanation about why using
// base::Unretained(this) is safe here.
url_loader_->DownloadToString(
url_loader_factory_remote.get(),
base::BindOnce(&WebRtcEventLogUploaderImpl::OnURLLoadComplete,
base::Unretained(this)),
weak_ptr_factory_.GetWeakPtr()),
kWebRtcEventLogMaxUploadIdBytes);
}
......
......@@ -147,6 +147,9 @@ class WebRtcEventLogUploaderImpl : public WebRtcEventLogUploader {
// This object is in charge of the actual upload.
std::unique_ptr<network::SimpleURLLoader> url_loader_;
// Allows releasing `this` while a task from `url_loader_` is still pending.
base::WeakPtrFactory<WebRtcEventLogUploaderImpl> weak_ptr_factory_{this};
};
} // namespace webrtc_event_logging
......
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