Commit c92c81fd authored by Bence Béky's avatar Bence Béky Committed by Commit Bot

Reland "Store callback in DhcpPacFileFetcherChromeos."

Original CL landed at https://crrev.com/c/1073192.

Revert (with edits) landed at https://crrev.com/c/1230442.

This CL relands the original with the modification that |callback_| is
reset in DhcpPacFileFetcherChromeos::Cancel() and OnShutdown().  It is
believed that the crashes the original CL caused happened when Fetch()
was called after Cancel(), and this modification will prevent that from
happening.  Kudos to eroman@ for pointing this out at
https://crrev.com/c/1230442/3/chromeos/network/dhcp_pac_file_fetcher_chromeos.cc#63

Bug: 882996
Change-Id: I4747004c00fa3ac7a698d7a35c0b52999411adb5
Reviewed-on: https://chromium-review.googlesource.com/1232576Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Bence Béky <bnc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592518}
parent 203f9c7e
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include "chromeos/network/dhcp_pac_file_fetcher_chromeos.h" #include "chromeos/network/dhcp_pac_file_fetcher_chromeos.h"
#include "base/callback_helpers.h"
#include "base/location.h" #include "base/location.h"
#include "base/task_runner_util.h" #include "base/task_runner_util.h"
#include "chromeos/network/network_event_log.h" #include "chromeos/network/network_event_log.h"
...@@ -51,22 +50,27 @@ int DhcpPacFileFetcherChromeos::Fetch( ...@@ -51,22 +50,27 @@ int DhcpPacFileFetcherChromeos::Fetch(
if (!network_handler_task_runner_.get()) if (!network_handler_task_runner_.get())
return net::ERR_PAC_NOT_IN_DHCP; return net::ERR_PAC_NOT_IN_DHCP;
CHECK(callback); CHECK(callback);
// DhcpPacFileFetcher only allows one Fetch in progress at a time.
CHECK(!callback_);
callback_ = std::move(callback);
base::PostTaskAndReplyWithResult( base::PostTaskAndReplyWithResult(
network_handler_task_runner_.get(), FROM_HERE, network_handler_task_runner_.get(), FROM_HERE,
base::BindOnce(&GetPacUrlFromDefaultNetwork), base::BindOnce(&GetPacUrlFromDefaultNetwork),
base::BindOnce(&DhcpPacFileFetcherChromeos::ContinueFetch, base::BindOnce(&DhcpPacFileFetcherChromeos::ContinueFetch,
weak_ptr_factory_.GetWeakPtr(), utf16_text, weak_ptr_factory_.GetWeakPtr(), utf16_text,
std::move(callback), traffic_annotation)); traffic_annotation));
return net::ERR_IO_PENDING; return net::ERR_IO_PENDING;
} }
void DhcpPacFileFetcherChromeos::Cancel() { void DhcpPacFileFetcherChromeos::Cancel() {
callback_.Reset();
pac_file_fetcher_->Cancel(); pac_file_fetcher_->Cancel();
// Invalidate any pending callbacks (i.e. calls to ContinueFetch). // Invalidate any pending callbacks (i.e. calls to ContinueFetch).
weak_ptr_factory_.InvalidateWeakPtrs(); weak_ptr_factory_.InvalidateWeakPtrs();
} }
void DhcpPacFileFetcherChromeos::OnShutdown() { void DhcpPacFileFetcherChromeos::OnShutdown() {
callback_.Reset();
pac_file_fetcher_->OnShutdown(); pac_file_fetcher_->OnShutdown();
} }
...@@ -80,22 +84,26 @@ std::string DhcpPacFileFetcherChromeos::GetFetcherName() const { ...@@ -80,22 +84,26 @@ std::string DhcpPacFileFetcherChromeos::GetFetcherName() const {
void DhcpPacFileFetcherChromeos::ContinueFetch( void DhcpPacFileFetcherChromeos::ContinueFetch(
base::string16* utf16_text, base::string16* utf16_text,
net::CompletionOnceCallback callback,
const net::NetworkTrafficAnnotationTag traffic_annotation, const net::NetworkTrafficAnnotationTag traffic_annotation,
std::string pac_url) { std::string pac_url) {
NET_LOG_EVENT("DhcpPacFileFetcher", pac_url); NET_LOG_EVENT("DhcpPacFileFetcher", pac_url);
pac_url_ = GURL(pac_url); pac_url_ = GURL(pac_url);
if (pac_url_.is_empty()) { if (pac_url_.is_empty()) {
std::move(callback).Run(net::ERR_PAC_NOT_IN_DHCP); std::move(callback_).Run(net::ERR_PAC_NOT_IN_DHCP);
return; return;
} }
auto repeating_callback = int result = pac_file_fetcher_->Fetch(
base::AdaptCallbackForRepeating(std::move(callback)); pac_url_, utf16_text,
int res = pac_file_fetcher_->Fetch(pac_url_, utf16_text, repeating_callback, base::BindOnce(&DhcpPacFileFetcherChromeos::OnFetchCompleted,
traffic_annotation); weak_ptr_factory_.GetWeakPtr()),
if (res != net::ERR_IO_PENDING) traffic_annotation);
repeating_callback.Run(res); if (result != net::ERR_IO_PENDING)
std::move(callback_).Run(result);
}
void DhcpPacFileFetcherChromeos::OnFetchCompleted(int result) {
std::move(callback_).Run(result);
} }
} // namespace chromeos } // namespace chromeos
...@@ -39,10 +39,6 @@ class CHROMEOS_EXPORT DhcpPacFileFetcherChromeos ...@@ -39,10 +39,6 @@ class CHROMEOS_EXPORT DhcpPacFileFetcherChromeos
~DhcpPacFileFetcherChromeos() override; ~DhcpPacFileFetcherChromeos() override;
// net::DhcpPacFileFetcher implementation // net::DhcpPacFileFetcher implementation
// TODO(https://crbug.com/882996) Even though it is documented at
// DhcpPacFileFetcher::Fetch() that only one fetch is allowed to be
// outstanding at any given time, crashes show that this is not obeyed.
int Fetch(base::string16* utf16_text, int Fetch(base::string16* utf16_text,
net::CompletionOnceCallback callback, net::CompletionOnceCallback callback,
const net::NetLogWithSource& net_log, const net::NetLogWithSource& net_log,
...@@ -54,10 +50,12 @@ class CHROMEOS_EXPORT DhcpPacFileFetcherChromeos ...@@ -54,10 +50,12 @@ class CHROMEOS_EXPORT DhcpPacFileFetcherChromeos
private: private:
void ContinueFetch(base::string16* utf16_text, void ContinueFetch(base::string16* utf16_text,
net::CompletionOnceCallback callback,
const net::NetworkTrafficAnnotationTag traffic_annotation, const net::NetworkTrafficAnnotationTag traffic_annotation,
std::string pac_url); std::string pac_url);
void OnFetchCompleted(int result);
net::CompletionOnceCallback callback_;
std::unique_ptr<net::PacFileFetcher> pac_file_fetcher_; std::unique_ptr<net::PacFileFetcher> pac_file_fetcher_;
scoped_refptr<base::SingleThreadTaskRunner> network_handler_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> network_handler_task_runner_;
......
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