Wait until all SafeBrowsing checks complete before calling NotifyResult.

This CL is the first step in having NotifyResult select the check with the
highest priority.  In order to do that (and not store intermediate data), all of
the checks must have finished prior to NotifyResult being called.

This *may* regress performance, and we should track the potential regression in
SubresourceFilter.PageLoad.SafeBrowsingDelay.

Bug: 823414
Change-Id: I1339e3795e9178dd7dd789ac98fcd21a2b76d726
Reviewed-on: https://chromium-review.googlesource.com/984672
Commit-Queue: Eric Robinson <[email protected]>
Reviewed-by: Varun Khaneja <[email protected]>
Reviewed-by: Asanka Herath <[email protected]>
Reviewed-by: Charlie Harrison <[email protected]>
Cr-Commit-Position: refs/heads/master@{#558178}
diff --git a/net/test/embedded_test_server/http_response.cc b/net/test/embedded_test_server/http_response.cc
index 168049e..cc5e99b 100644
--- a/net/test/embedded_test_server/http_response.cc
+++ b/net/test/embedded_test_server/http_response.cc
@@ -4,10 +4,12 @@
 
 #include "net/test/embedded_test_server/http_response.h"
 
+#include "base/bind.h"
 #include "base/format_macros.h"
 #include "base/logging.h"
 #include "base/strings/string_util.h"
 #include "base/strings/stringprintf.h"
+#include "base/threading/sequenced_task_runner_handle.h"
 #include "net/http/http_status_code.h"
 
 namespace net {
@@ -85,6 +87,17 @@
   send.Run(ToResponseString(), done);
 }
 
+DelayedHttpResponse::DelayedHttpResponse(const base::TimeDelta delay)
+    : delay_(delay) {}
+
+DelayedHttpResponse::~DelayedHttpResponse() = default;
+
+void DelayedHttpResponse::SendResponse(const SendBytesCallback& send,
+                                       const SendCompleteCallback& done) {
+  base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
+      FROM_HERE, base::BindOnce(send, ToResponseString(), done), delay_);
+}
+
 void HungResponse::SendResponse(const SendBytesCallback& send,
                                 const SendCompleteCallback& done) {}