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 @@ ...@@ -18,57 +18,27 @@
namespace cr_fuchsia { namespace cr_fuchsia {
// Utility class to get the JSON value of the list URL for a DevTools service on base::Value GetDevToolsListFromPort(uint16_t port) {
// localhost. GURL url(base::StringPrintf("http://127.0.0.1:%d/json/list", port));
class DevToolsListFetcher : public net::URLFetcherDelegate { net::TestURLRequestContext request_context;
public: net::TestDelegate delegate;
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; std::unique_ptr<net::URLRequest> request(request_context.CreateRequest(
on_url_fetch_complete_ack_ = run_loop.QuitClosure(); url, net::DEFAULT_PRIORITY, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS));
run_loop.Run(); request->Start();
delegate.RunUntilComplete();
if (fetcher->GetError() != net::OK) if (delegate.request_status() < 0)
return base::Value(); return base::Value();
if (fetcher->GetResponseCode() != net::HTTP_OK) if (request->response_headers()->response_code() != net::HTTP_OK)
return base::Value(); return base::Value();
std::string result; const std::string& result = delegate.data_received();
if (!fetcher->GetResponseAsString(&result)) if (result.empty())
return base::Value(); return base::Value();
return base::JSONReader::Read(result).value_or(base::Value()); return base::JSONReader::Read(result).value_or(base::Value());
}
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();
}
scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_;
base::OnceClosure on_url_fetch_complete_ack_;
DISALLOW_COPY_AND_ASSIGN(DevToolsListFetcher);
};
base::Value GetDevToolsListFromPort(uint16_t port) {
DevToolsListFetcher devtools_fetcher;
return devtools_fetcher.GetDevToolsListFromPort(port);
} }
} // namespace cr_fuchsia } // namespace cr_fuchsia
...@@ -9,9 +9,6 @@ ...@@ -9,9 +9,6 @@
namespace cr_fuchsia { 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 // Returns the JSON value of the list URL for the DevTools service listening
// on port |port| on localhost. Returns an empty value on error. // on port |port| on localhost. Returns an empty value on error.
base::Value GetDevToolsListFromPort(uint16_t port); base::Value GetDevToolsListFromPort(uint16_t port);
......
...@@ -40,10 +40,6 @@ namespace cloud_print { ...@@ -40,10 +40,6 @@ namespace cloud_print {
class CloudPrintURLFetcher; class CloudPrintURLFetcher;
} }
namespace cr_fuchsia {
class DevToolsListFetcher;
}
namespace device { namespace device {
class UsbTestGadgetImpl; class UsbTestGadgetImpl;
} }
...@@ -348,7 +344,6 @@ class NET_EXPORT URLFetcher { ...@@ -348,7 +344,6 @@ class NET_EXPORT URLFetcher {
// This class is deprecated, and no new code should be using it. Construction // This class is deprecated, and no new code should be using it. Construction
// methods are private and pre-existing consumers are friended. // methods are private and pre-existing consumers are friended.
friend class cloud_print::CloudPrintURLFetcher; friend class cloud_print::CloudPrintURLFetcher;
friend class cr_fuchsia::DevToolsListFetcher;
friend class device::UsbTestGadgetImpl; friend class device::UsbTestGadgetImpl;
friend class remoting::GstaticJsonFetcher; 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