OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/net/reporting_service_proxy.h" | 5 #include "content/browser/net/reporting_service_proxy.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "content/public/browser/browser_context.h" | 13 #include "content/public/browser/browser_context.h" |
14 #include "content/public/browser/site_instance.h" | 14 #include "content/public/browser/site_instance.h" |
15 #include "content/public/browser/storage_partition.h" | 15 #include "content/public/browser/storage_partition.h" |
16 #include "mojo/public/cpp/bindings/strong_binding.h" | 16 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 17 #include "net/reporting/reporting_report.h" |
17 #include "net/reporting/reporting_service.h" | 18 #include "net/reporting/reporting_service.h" |
18 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
19 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
20 #include "third_party/WebKit/public/platform/reporting.mojom.h" | 21 #include "third_party/WebKit/public/platform/reporting.mojom.h" |
21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
22 | 23 |
23 namespace content { | 24 namespace content { |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 class ReportingServiceProxyImpl : public mojom::ReportingServiceProxy { | 28 class ReportingServiceProxyImpl : public mojom::ReportingServiceProxy { |
28 public: | 29 public: |
29 ReportingServiceProxyImpl( | 30 ReportingServiceProxyImpl( |
30 scoped_refptr<net::URLRequestContextGetter> request_context_getter) | 31 scoped_refptr<net::URLRequestContextGetter> request_context_getter) |
31 : request_context_getter_(std::move(request_context_getter)) {} | 32 : request_context_getter_(std::move(request_context_getter)) {} |
32 | 33 |
33 // mojom::ReportingServiceProxy: | 34 // mojom::ReportingServiceProxy: |
34 void QueueReport(const GURL& url, | 35 void QueueReport(const GURL& url, |
35 const std::string& group, | 36 const std::string& group, |
36 const std::string& type, | 37 const std::string& type, |
37 std::unique_ptr<base::Value> body) override { | 38 std::unique_ptr<base::Value> body) override { |
38 std::unique_ptr<const base::Value> const_body = | 39 std::unique_ptr<const base::Value> const_body = |
39 base::WrapUnique(body.release()); | 40 base::WrapUnique(body.release()); |
40 | 41 |
41 net::URLRequestContext* request_context = | 42 net::URLRequestContext* request_context = |
42 request_context_getter_->GetURLRequestContext(); | 43 request_context_getter_->GetURLRequestContext(); |
43 if (!request_context) | 44 if (!request_context) { |
| 45 net::ReportingReport::RecordReportDiscardedForNoURLRequestContext(); |
44 return; | 46 return; |
| 47 } |
45 | 48 |
46 net::ReportingService* reporting_service = | 49 net::ReportingService* reporting_service = |
47 request_context->reporting_service(); | 50 request_context->reporting_service(); |
48 if (!reporting_service) | 51 if (!reporting_service) { |
| 52 net::ReportingReport::RecordReportDiscardedForNoReportingService(); |
49 return; | 53 return; |
| 54 } |
50 | 55 |
51 reporting_service->QueueReport(url, group, type, std::move(const_body)); | 56 reporting_service->QueueReport(url, group, type, std::move(const_body)); |
52 } | 57 } |
53 | 58 |
54 private: | 59 private: |
55 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 60 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
56 }; | 61 }; |
57 | 62 |
58 void CreateReportingServiceProxyOnNetworkTaskRunner( | 63 void CreateReportingServiceProxyOnNetworkTaskRunner( |
59 mojom::ReportingServiceProxyRequest request, | 64 mojom::ReportingServiceProxyRequest request, |
(...skipping 14 matching lines...) Expand all Loading... |
74 storage_partition->GetURLRequestContext()); | 79 storage_partition->GetURLRequestContext()); |
75 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner( | 80 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner( |
76 request_context_getter->GetNetworkTaskRunner()); | 81 request_context_getter->GetNetworkTaskRunner()); |
77 network_task_runner->PostTask( | 82 network_task_runner->PostTask( |
78 FROM_HERE, | 83 FROM_HERE, |
79 base::BindOnce(&CreateReportingServiceProxyOnNetworkTaskRunner, | 84 base::BindOnce(&CreateReportingServiceProxyOnNetworkTaskRunner, |
80 std::move(request), std::move(request_context_getter))); | 85 std::move(request), std::move(request_context_getter))); |
81 } | 86 } |
82 | 87 |
83 } // namespace content | 88 } // namespace content |
OLD | NEW |