Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: components/reporting/content/browser/reporting_network_delegate.cc

Issue 2249213002: [OBSOLETE] Reporting: Initial implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix ProfileImplIOData Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/reporting/content/browser/reporting_network_delegate.h"
6
7 #include "components/reporting/content/browser/reporting_service_factory.h"
8 #include "components/reporting/core/browser/reporting_service.h"
9 #include "content/public/browser/browser_context.h"
10 #include "content/public/common/origin_util.h"
11 #include "net/http/http_response_headers.h"
12 #include "net/url_request/url_request.h"
13
14 namespace reporting {
15
16 ReportingNetworkDelegate::Handle::Handle() {}
17 ReportingNetworkDelegate::Handle::~Handle() {}
18
19 // static
20 const char ReportingNetworkDelegate::kReportingHeaderName[] = "Report-To";
21
22 ReportingNetworkDelegate::ReportingNetworkDelegate(
23 std::unique_ptr<net::NetworkDelegate> nested_network_delegate,
24 std::unique_ptr<Handle> handle)
25 : net::LayeredNetworkDelegate(std::move(nested_network_delegate)),
26 ui_task_runner_(handle->task_runner),
27 ui_process_header_(
28 base::Bind(&ReportingNetworkDelegate::ProcessHeaderOnUIThread,
29 handle->browser_context_is_valid,
30 handle->browser_context)) {
31 DCHECK(handle);
32 }
33
34 ReportingNetworkDelegate::~ReportingNetworkDelegate() {}
35
36 void ReportingNetworkDelegate::OnHeadersReceivedInternal(
37 net::URLRequest* request,
38 const net::CompletionCallback& callback,
39 const net::HttpResponseHeaders* original_response_headers,
40 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
41 GURL* allowed_unsafe_redirect_url) {
42 DCHECK(request);
43 DCHECK(original_response_headers);
44
45 GURL origin = request->url().GetOrigin();
46
47 if (!content::IsOriginSecure(origin))
48 return;
49
50 std::string header_value;
51 if (!original_response_headers->GetNormalizedHeader(kReportingHeaderName,
52 &header_value)) {
53 return;
54 }
55
56 ProcessHeader(origin, header_value);
57 }
58
59 void ReportingNetworkDelegate::ProcessHeader(const GURL& origin,
60 const std::string& header_value) {
61 ui_task_runner_->PostTask(
62 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
63 }
64
65 // static
66 void ReportingNetworkDelegate::ProcessHeaderOnUIThread(
67 const base::Callback<bool(void)>& browser_context_is_valid,
68 content::BrowserContext* browser_context,
69 const GURL& origin,
70 const std::string& header_value) {
71 if (!browser_context_is_valid.Run()) {
72 LOG(WARNING) << "ProcessHeaderOnUIThread: BrowserContext is invalid.";
73 return;
74 }
75
76 ReportingService* service =
77 ReportingServiceFactory::GetForBrowserContext(browser_context,
78 /* create= */ false);
79 if (!service) {
80 LOG(WARNING) << "ProcessHeaderOnUIThread: ReportingService is missing.";
81 return;
82 }
83
84 service->ProcessHeader(origin, header_value);
85 }
86
87 } // namespace reporting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698