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 "net/reporting/reporting_service.h" | 5 #include "net/reporting/reporting_service.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/time/tick_clock.h" | 12 #include "base/time/tick_clock.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "net/reporting/reporting_browsing_data_remover.h" | 15 #include "net/reporting/reporting_browsing_data_remover.h" |
16 #include "net/reporting/reporting_cache.h" | 16 #include "net/reporting/reporting_cache.h" |
17 #include "net/reporting/reporting_context.h" | 17 #include "net/reporting/reporting_context.h" |
| 18 #include "net/reporting/reporting_delegate.h" |
18 #include "net/reporting/reporting_header_parser.h" | 19 #include "net/reporting/reporting_header_parser.h" |
19 #include "net/reporting/reporting_persister.h" | 20 #include "net/reporting/reporting_persister.h" |
20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
21 | 22 |
22 namespace net { | 23 namespace net { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 class ReportingServiceImpl : public ReportingService { | 27 class ReportingServiceImpl : public ReportingService { |
27 public: | 28 public: |
28 ReportingServiceImpl(std::unique_ptr<ReportingContext> context) | 29 ReportingServiceImpl(std::unique_ptr<ReportingContext> context) |
29 : context_(std::move(context)) {} | 30 : context_(std::move(context)) {} |
30 | 31 |
31 ~ReportingServiceImpl() override {} | 32 ~ReportingServiceImpl() override {} |
32 | 33 |
33 void QueueReport(const GURL& url, | 34 void QueueReport(const GURL& url, |
34 const std::string& group, | 35 const std::string& group, |
35 const std::string& type, | 36 const std::string& type, |
36 std::unique_ptr<const base::Value> body) override { | 37 std::unique_ptr<const base::Value> body) override { |
| 38 if (!context_->delegate()->CanQueueReport(url::Origin(url))) |
| 39 return; |
| 40 |
37 context_->cache()->AddReport(url, group, type, std::move(body), | 41 context_->cache()->AddReport(url, group, type, std::move(body), |
38 context_->tick_clock()->NowTicks(), 0); | 42 context_->tick_clock()->NowTicks(), 0); |
39 } | 43 } |
40 | 44 |
41 void ProcessHeader(const GURL& url, | 45 void ProcessHeader(const GURL& url, |
42 const std::string& header_value) override { | 46 const std::string& header_value) override { |
43 ReportingHeaderParser::ParseHeader(context_.get(), url, header_value); | 47 ReportingHeaderParser::ParseHeader(context_.get(), url, header_value); |
44 } | 48 } |
45 | 49 |
46 void RemoveBrowsingData( | 50 void RemoveBrowsingData( |
(...skipping 21 matching lines...) Expand all Loading... |
68 ReportingContext::Create(policy, request_context)); | 72 ReportingContext::Create(policy, request_context)); |
69 } | 73 } |
70 | 74 |
71 // static | 75 // static |
72 std::unique_ptr<ReportingService> ReportingService::CreateForTesting( | 76 std::unique_ptr<ReportingService> ReportingService::CreateForTesting( |
73 std::unique_ptr<ReportingContext> reporting_context) { | 77 std::unique_ptr<ReportingContext> reporting_context) { |
74 return base::MakeUnique<ReportingServiceImpl>(std::move(reporting_context)); | 78 return base::MakeUnique<ReportingServiceImpl>(std::move(reporting_context)); |
75 } | 79 } |
76 | 80 |
77 } // namespace net | 81 } // namespace net |
OLD | NEW |