Reporting and Network Error Logging: Add OnShutdown() methods

This CL adds methods to shut down the ReportingService and the
NetworkErrorLoggingService. Previously, we were destroying the
NEL service and the ReportingService when the NetworkContext was
torn down, leading to a use-after-free when destroying the
ReportingService caused pending uploads to be cancelled,
generating NEL reports for the cancelled requests, that would be sent
to the already-destroyed NEL service. This fixes the issue by shutting
down rather than destroying the NEL service and ReportingService in the
destructor of ContainerURLRequestContext.

Bug: 935209
Change-Id: Id53d8430a974336b8016d0cd73fa837f2a1e1d1b
Reviewed-on: https://chromium-review.googlesource.com/c/1489098
Reviewed-by: Martin Šrámek <[email protected]>
Reviewed-by: Matt Menke <[email protected]>
Commit-Queue: Lily Chen <[email protected]>
Cr-Commit-Position: refs/heads/master@{#636837}
diff --git a/net/reporting/reporting_service.h b/net/reporting/reporting_service.h
index b13c8f6d..c7671d1 100644
--- a/net/reporting/reporting_service.h
+++ b/net/reporting/reporting_service.h
@@ -72,10 +72,16 @@
   // filter.
   virtual void RemoveAllBrowsingData(int data_type_mask) = 0;
 
+  // Shuts down the Reporting service so that no new headers or reports are
+  // processed, and pending uploads are cancelled.
+  virtual void OnShutdown() = 0;
+
   virtual const ReportingPolicy& GetPolicy() const = 0;
 
   virtual base::Value StatusAsValue() const;
 
+  virtual ReportingContext* GetContextForTesting() const = 0;
+
  protected:
   ReportingService() {}