Commit 7dc10fe1 authored by Mark Pilgrim's avatar Mark Pilgrim Committed by Commit Bot

Migrate captive_portal to BindOnce

Bug: 714018
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ia2bf1a8fa963f7540272a0d28961bfc961f14dd0
Reviewed-on: https://chromium-review.googlesource.com/1131994Reviewed-by: default avatarAdrienne Porter Felt <felt@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Commit-Queue: Mark Pilgrim <pilgrim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#574620}
parent 3753827a
......@@ -278,8 +278,8 @@ void CaptivePortalService::DetectCaptivePortalInternal() {
})");
captive_portal_detector_->DetectCaptivePortal(
test_url_,
base::Bind(&CaptivePortalService::OnPortalDetectionCompleted,
base::Unretained(this)),
base::BindOnce(&CaptivePortalService::OnPortalDetectionCompleted,
base::Unretained(this)),
traffic_annotation);
}
......
......@@ -27,13 +27,13 @@ CaptivePortalDetector::~CaptivePortalDetector() {
void CaptivePortalDetector::DetectCaptivePortal(
const GURL& url,
const DetectionCallback& detection_callback,
DetectionCallback detection_callback,
const net::NetworkTrafficAnnotationTag& traffic_annotation) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!FetchingURL());
DCHECK(detection_callback_.is_null());
detection_callback_ = detection_callback;
detection_callback_ = std::move(detection_callback);
auto resource_request = std::make_unique<network::ResourceRequest>();
resource_request->url = url;
......@@ -85,10 +85,8 @@ void CaptivePortalDetector::OnSimpleLoaderCompleteInternal(
Results results;
GetCaptivePortalResultFromResponse(net_error, response_code, url, headers,
&results);
DetectionCallback callback = detection_callback_;
simple_loader_.reset();
detection_callback_.Reset();
callback.Run(results);
std::move(detection_callback_).Run(results);
}
void CaptivePortalDetector::GetCaptivePortalResultFromResponse(
......
......@@ -33,7 +33,7 @@ class CAPTIVE_PORTAL_EXPORT CaptivePortalDetector {
GURL landing_url;
};
typedef base::Callback<void(const Results& results)> DetectionCallback;
typedef base::OnceCallback<void(const Results& results)> DetectionCallback;
// The test URL. When connected to the Internet, it should return a
// blank page with a 204 status code. When behind a captive portal,
......@@ -50,7 +50,7 @@ class CAPTIVE_PORTAL_EXPORT CaptivePortalDetector {
// |callback|.
void DetectCaptivePortal(
const GURL& url,
const DetectionCallback& callback,
DetectionCallback callback,
const net::NetworkTrafficAnnotationTag& traffic_annotation);
// Cancels captive portal check.
......
......@@ -74,8 +74,8 @@ class CaptivePortalDetectorTest : public testing::Test,
detector()->DetectCaptivePortal(
url,
base::Bind(&CaptivePortalClient::OnPortalDetectionCompleted,
base::Unretained(&client)),
base::BindOnce(&CaptivePortalClient::OnPortalDetectionCompleted,
base::Unretained(&client)),
TRAFFIC_ANNOTATION_FOR_TESTS);
ASSERT_TRUE(FetchingURL());
......@@ -100,8 +100,8 @@ class CaptivePortalDetectorTest : public testing::Test,
detector()->DetectCaptivePortal(
url,
base::Bind(&CaptivePortalClient::OnPortalDetectionCompleted,
base::Unretained(&client)),
base::BindOnce(&CaptivePortalClient::OnPortalDetectionCompleted,
base::Unretained(&client)),
TRAFFIC_ANNOTATION_FOR_TESTS);
ASSERT_TRUE(FetchingURL());
......
......@@ -36,7 +36,7 @@ class CaptivePortalMetricsTabHelper
// Tests if network access is currently blocked by a captive portal.
void TestForCaptivePortal(
const captive_portal::CaptivePortalDetector::DetectionCallback& callback);
captive_portal::CaptivePortalDetector::DetectionCallback callback);
// Tests for a captive portal and logs the resulting metric.
void TimerTriggered();
......
......@@ -39,19 +39,20 @@ CaptivePortalMetricsTabHelper::CaptivePortalMetricsTabHelper(
CaptivePortalMetricsTabHelper::~CaptivePortalMetricsTabHelper() = default;
void CaptivePortalMetricsTabHelper::TimerTriggered() {
TestForCaptivePortal(base::Bind(&HandleTimeoutCaptivePortalDetectionResult));
TestForCaptivePortal(
base::BindOnce(&HandleTimeoutCaptivePortalDetectionResult));
}
void CaptivePortalMetricsTabHelper::TestForCaptivePortal(
const captive_portal::CaptivePortalDetector::DetectionCallback& callback) {
captive_portal::CaptivePortalDetector::DetectionCallback callback) {
CaptivePortalDetectorTabHelper* tab_helper =
CaptivePortalDetectorTabHelper::FromWebState(web_state_);
// TODO(crbug.com/760873): replace test with DCHECK when this method is only
// called on WebStates attached to tabs.
if (tab_helper) {
tab_helper->detector()->DetectCaptivePortal(
GURL(captive_portal::CaptivePortalDetector::kDefaultURL), callback,
NO_TRAFFIC_ANNOTATION_YET);
GURL(captive_portal::CaptivePortalDetector::kDefaultURL),
std::move(callback), NO_TRAFFIC_ANNOTATION_YET);
}
}
......
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