Commit 58c5823d authored by Kinuko Yasuda's avatar Kinuko Yasuda Committed by Chromium LUCI CQ

Use TestDelegate instead of URLFetcher in DevToolsListFetcher

Bug: 1010491
Change-Id: Ic86d00d46d6dad7a0f3db31562e68e268273c496
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2586454Reviewed-by: default avatarWez <wez@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Commit-Queue: Kinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836716}
parent 9f07c522
......@@ -18,57 +18,27 @@
namespace cr_fuchsia {
// Utility class to get the JSON value of the list URL for a DevTools service on
// localhost.
class DevToolsListFetcher : public net::URLFetcherDelegate {
public:
DevToolsListFetcher() {
request_context_getter_ =
base::MakeRefCounted<net::TestURLRequestContextGetter>(
base::ThreadTaskRunnerHandle::Get());
}
~DevToolsListFetcher() override = default;
base::Value GetDevToolsListFromPort(uint16_t port) {
std::string url = base::StringPrintf("http://127.0.0.1:%d/json/list", port);
std::unique_ptr<net::URLFetcher> fetcher = net::URLFetcher::Create(
GURL(url), net::URLFetcher::GET, this, TRAFFIC_ANNOTATION_FOR_TESTS);
fetcher->SetRequestContext(request_context_getter_.get());
fetcher->Start();
base::RunLoop run_loop;
on_url_fetch_complete_ack_ = run_loop.QuitClosure();
run_loop.Run();
if (fetcher->GetError() != net::OK)
return base::Value();
if (fetcher->GetResponseCode() != net::HTTP_OK)
return base::Value();
std::string result;
if (!fetcher->GetResponseAsString(&result))
return base::Value();
base::Value GetDevToolsListFromPort(uint16_t port) {
GURL url(base::StringPrintf("http://127.0.0.1:%d/json/list", port));
net::TestURLRequestContext request_context;
net::TestDelegate delegate;
return base::JSONReader::Read(result).value_or(base::Value());
}
std::unique_ptr<net::URLRequest> request(request_context.CreateRequest(
url, net::DEFAULT_PRIORITY, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS));
request->Start();
delegate.RunUntilComplete();
private:
// fuchsia::web::URLFetcherDelegate implementation.
void OnURLFetchComplete(const net::URLFetcher* source) override {
DCHECK(on_url_fetch_complete_ack_);
std::move(on_url_fetch_complete_ack_).Run();
}
if (delegate.request_status() < 0)
return base::Value();
scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_;
base::OnceClosure on_url_fetch_complete_ack_;
if (request->response_headers()->response_code() != net::HTTP_OK)
return base::Value();
DISALLOW_COPY_AND_ASSIGN(DevToolsListFetcher);
};
const std::string& result = delegate.data_received();
if (result.empty())
return base::Value();
base::Value GetDevToolsListFromPort(uint16_t port) {
DevToolsListFetcher devtools_fetcher;
return devtools_fetcher.GetDevToolsListFromPort(port);
return base::JSONReader::Read(result).value_or(base::Value());
}
} // namespace cr_fuchsia
......@@ -9,9 +9,6 @@
namespace cr_fuchsia {
// Outside of anonymous namespace so deprecated net::URLFetcher can friend it
class DevToolsListFetcher;
// Returns the JSON value of the list URL for the DevTools service listening
// on port |port| on localhost. Returns an empty value on error.
base::Value GetDevToolsListFromPort(uint16_t port);
......
......@@ -40,10 +40,6 @@ namespace cloud_print {
class CloudPrintURLFetcher;
}
namespace cr_fuchsia {
class DevToolsListFetcher;
}
namespace device {
class UsbTestGadgetImpl;
}
......@@ -348,7 +344,6 @@ class NET_EXPORT URLFetcher {
// This class is deprecated, and no new code should be using it. Construction
// methods are private and pre-existing consumers are friended.
friend class cloud_print::CloudPrintURLFetcher;
friend class cr_fuchsia::DevToolsListFetcher;
friend class device::UsbTestGadgetImpl;
friend class remoting::GstaticJsonFetcher;
......
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