Reporting: Check upload permissions asynchronously

This changes the signature of the CanSendReport method so that it works
asynchronously.  We need this to able to check the background sync
permission, since that can only be checked from the UI thread; we need
the async logic to pass control between the IO and UI threads in the
right way.

To reduce the number of async calls, the method has also been updated to
check several origins all at once, instead of having a single method
call for each origin.  You pass in a set of origins that you'd like to
upload reports for, and the method passes back the set of origins that
you're allowed to.

Bug: 704259
Change-Id: I431b2fe1c1eb4e65cea91a86fd213e3204b852a1
Reviewed-on: https://chromium-review.googlesource.com/937566
Reviewed-by: Julia Tuttle <[email protected]>
Commit-Queue: Douglas Creager <[email protected]>
Cr-Commit-Position: refs/heads/master@{#539546}
diff --git a/net/base/layered_network_delegate.cc b/net/base/layered_network_delegate.cc
index 46bd4b2..e771fa9 100644
--- a/net/base/layered_network_delegate.cc
+++ b/net/base/layered_network_delegate.cc
@@ -262,14 +262,16 @@
 void LayeredNetworkDelegate::OnCanQueueReportingReportInternal(
     const url::Origin& origin) const {}
 
-bool LayeredNetworkDelegate::OnCanSendReportingReport(
-    const url::Origin& origin) const {
-  OnCanSendReportingReportInternal(origin);
-  return nested_network_delegate_->CanSendReportingReport(origin);
+void LayeredNetworkDelegate::OnCanSendReportingReports(
+    std::set<url::Origin> origins,
+    base::OnceCallback<void(std::set<url::Origin>)> result_callback) const {
+  OnCanSendReportingReportsInternal(origins);
+  nested_network_delegate_->CanSendReportingReports(std::move(origins),
+                                                    std::move(result_callback));
 }
 
-void LayeredNetworkDelegate::OnCanSendReportingReportInternal(
-    const url::Origin& origin) const {}
+void LayeredNetworkDelegate::OnCanSendReportingReportsInternal(
+    const std::set<url::Origin>& origins) const {}
 
 bool LayeredNetworkDelegate::OnCanSetReportingClient(
     const url::Origin& origin,