| 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_delivery_agent.h" | 5 #include "net/reporting/reporting_delivery_agent.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/time/tick_clock.h" | 15 #include "base/time/tick_clock.h" |
| 16 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "net/reporting/reporting_cache.h" | 18 #include "net/reporting/reporting_cache.h" |
| 19 #include "net/reporting/reporting_delegate.h" |
| 19 #include "net/reporting/reporting_endpoint_manager.h" | 20 #include "net/reporting/reporting_endpoint_manager.h" |
| 20 #include "net/reporting/reporting_observer.h" | 21 #include "net/reporting/reporting_observer.h" |
| 21 #include "net/reporting/reporting_report.h" | 22 #include "net/reporting/reporting_report.h" |
| 22 #include "net/reporting/reporting_uploader.h" | 23 #include "net/reporting/reporting_uploader.h" |
| 23 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 24 #include "url/origin.h" | 25 #include "url/origin.h" |
| 25 | 26 |
| 26 namespace net { | 27 namespace net { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 } | 109 } |
| 109 | 110 |
| 110 void SendReports() { | 111 void SendReports() { |
| 111 std::vector<const ReportingReport*> reports; | 112 std::vector<const ReportingReport*> reports; |
| 112 cache()->GetReports(&reports); | 113 cache()->GetReports(&reports); |
| 113 | 114 |
| 114 // Sort reports into (origin, group) buckets. | 115 // Sort reports into (origin, group) buckets. |
| 115 std::map<OriginGroup, std::vector<const ReportingReport*>> | 116 std::map<OriginGroup, std::vector<const ReportingReport*>> |
| 116 origin_group_reports; | 117 origin_group_reports; |
| 117 for (const ReportingReport* report : reports) { | 118 for (const ReportingReport* report : reports) { |
| 119 url::Origin origin(report->url); |
| 120 if (!delegate()->CanSendReport(origin)) |
| 121 continue; |
| 118 OriginGroup origin_group(url::Origin(report->url), report->group); | 122 OriginGroup origin_group(url::Origin(report->url), report->group); |
| 119 origin_group_reports[origin_group].push_back(report); | 123 origin_group_reports[origin_group].push_back(report); |
| 120 } | 124 } |
| 121 | 125 |
| 122 // Find endpoint for each (origin, group) bucket and sort reports into | 126 // Find endpoint for each (origin, group) bucket and sort reports into |
| 123 // endpoint buckets. Don't allow concurrent deliveries to the same (origin, | 127 // endpoint buckets. Don't allow concurrent deliveries to the same (origin, |
| 124 // group) bucket. | 128 // group) bucket. |
| 125 std::map<GURL, std::vector<const ReportingReport*>> endpoint_reports; | 129 std::map<GURL, std::vector<const ReportingReport*>> endpoint_reports; |
| 126 for (auto& it : origin_group_reports) { | 130 for (auto& it : origin_group_reports) { |
| 127 const OriginGroup& origin_group = it.first; | 131 const OriginGroup& origin_group = it.first; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 pending_origin_groups_.erase( | 183 pending_origin_groups_.erase( |
| 180 OriginGroup(url::Origin(report->url), report->group)); | 184 OriginGroup(url::Origin(report->url), report->group)); |
| 181 } | 185 } |
| 182 | 186 |
| 183 endpoint_manager()->ClearEndpointPending(delivery->endpoint); | 187 endpoint_manager()->ClearEndpointPending(delivery->endpoint); |
| 184 cache()->ClearReportsPending(delivery->reports); | 188 cache()->ClearReportsPending(delivery->reports); |
| 185 } | 189 } |
| 186 | 190 |
| 187 const ReportingPolicy& policy() { return context_->policy(); } | 191 const ReportingPolicy& policy() { return context_->policy(); } |
| 188 base::TickClock* tick_clock() { return context_->tick_clock(); } | 192 base::TickClock* tick_clock() { return context_->tick_clock(); } |
| 193 ReportingDelegate* delegate() { return context_->delegate(); } |
| 189 ReportingCache* cache() { return context_->cache(); } | 194 ReportingCache* cache() { return context_->cache(); } |
| 190 ReportingUploader* uploader() { return context_->uploader(); } | 195 ReportingUploader* uploader() { return context_->uploader(); } |
| 191 ReportingEndpointManager* endpoint_manager() { | 196 ReportingEndpointManager* endpoint_manager() { |
| 192 return context_->endpoint_manager(); | 197 return context_->endpoint_manager(); |
| 193 } | 198 } |
| 194 | 199 |
| 195 ReportingContext* context_; | 200 ReportingContext* context_; |
| 196 | 201 |
| 197 std::unique_ptr<base::Timer> timer_; | 202 std::unique_ptr<base::Timer> timer_; |
| 198 | 203 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 209 | 214 |
| 210 // static | 215 // static |
| 211 std::unique_ptr<ReportingDeliveryAgent> ReportingDeliveryAgent::Create( | 216 std::unique_ptr<ReportingDeliveryAgent> ReportingDeliveryAgent::Create( |
| 212 ReportingContext* context) { | 217 ReportingContext* context) { |
| 213 return base::MakeUnique<ReportingDeliveryAgentImpl>(context); | 218 return base::MakeUnique<ReportingDeliveryAgentImpl>(context); |
| 214 } | 219 } |
| 215 | 220 |
| 216 ReportingDeliveryAgent::~ReportingDeliveryAgent() {} | 221 ReportingDeliveryAgent::~ReportingDeliveryAgent() {} |
| 217 | 222 |
| 218 } // namespace net | 223 } // namespace net |
| OLD | NEW |