Index: components/reporting/content/browser/reporting_network_delegate.cc |
diff --git a/components/reporting/content/browser/reporting_network_delegate.cc b/components/reporting/content/browser/reporting_network_delegate.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2c8e7b4c68c52ccb762f2cc43959f57335eb2d4a |
--- /dev/null |
+++ b/components/reporting/content/browser/reporting_network_delegate.cc |
@@ -0,0 +1,87 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/reporting/content/browser/reporting_network_delegate.h" |
+ |
+#include "components/reporting/content/browser/reporting_service_factory.h" |
+#include "components/reporting/core/browser/reporting_service.h" |
+#include "content/public/browser/browser_context.h" |
+#include "content/public/common/origin_util.h" |
+#include "net/http/http_response_headers.h" |
+#include "net/url_request/url_request.h" |
+ |
+namespace reporting { |
+ |
+ReportingNetworkDelegate::Handle::Handle() {} |
+ReportingNetworkDelegate::Handle::~Handle() {} |
+ |
+// static |
+const char ReportingNetworkDelegate::kReportingHeaderName[] = "Report-To"; |
+ |
+ReportingNetworkDelegate::ReportingNetworkDelegate( |
+ std::unique_ptr<net::NetworkDelegate> nested_network_delegate, |
+ std::unique_ptr<Handle> handle) |
+ : net::LayeredNetworkDelegate(std::move(nested_network_delegate)), |
+ ui_task_runner_(handle->task_runner), |
+ ui_process_header_( |
+ base::Bind(&ReportingNetworkDelegate::ProcessHeaderOnUIThread, |
+ handle->browser_context_is_valid, |
+ handle->browser_context)) { |
+ DCHECK(handle); |
+} |
+ |
+ReportingNetworkDelegate::~ReportingNetworkDelegate() {} |
+ |
+void ReportingNetworkDelegate::OnHeadersReceivedInternal( |
+ net::URLRequest* request, |
+ const net::CompletionCallback& callback, |
+ const net::HttpResponseHeaders* original_response_headers, |
+ scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
+ GURL* allowed_unsafe_redirect_url) { |
+ DCHECK(request); |
+ DCHECK(original_response_headers); |
+ |
+ GURL origin = request->url().GetOrigin(); |
+ |
+ if (!content::IsOriginSecure(origin)) |
+ return; |
+ |
+ std::string header_value; |
+ if (!original_response_headers->GetNormalizedHeader(kReportingHeaderName, |
+ &header_value)) { |
+ return; |
+ } |
+ |
+ ProcessHeader(origin, header_value); |
+} |
+ |
+void ReportingNetworkDelegate::ProcessHeader(const GURL& origin, |
+ const std::string& header_value) { |
+ ui_task_runner_->PostTask( |
+ FROM_HERE, base::Bind(ui_process_header_, origin, header_value)); |
Randy Smith (Not in Mondays)
2016/10/21 20:15:10
So we're adding a thread hop for every response th
Julia Tuttle
2016/11/02 20:44:39
We're adding a thread hop for every response that
|
+} |
+ |
+// static |
+void ReportingNetworkDelegate::ProcessHeaderOnUIThread( |
+ const base::Callback<bool(void)>& browser_context_is_valid, |
+ content::BrowserContext* browser_context, |
+ const GURL& origin, |
+ const std::string& header_value) { |
+ if (!browser_context_is_valid.Run()) { |
+ LOG(WARNING) << "ProcessHeaderOnUIThread: BrowserContext is invalid."; |
+ return; |
+ } |
+ |
+ ReportingService* service = |
+ ReportingServiceFactory::GetForBrowserContext(browser_context, |
+ /* create= */ false); |
+ if (!service) { |
+ LOG(WARNING) << "ProcessHeaderOnUIThread: ReportingService is missing."; |
+ return; |
+ } |
+ |
+ service->ProcessHeader(origin, header_value); |
+} |
+ |
+} // namespace reporting |