Chromium Code Reviews| Index: net/reporting/reporting_delivery_agent.h |
| diff --git a/net/reporting/reporting_delivery_agent.h b/net/reporting/reporting_delivery_agent.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3e62713fd9c69c8b6372dd94b0b80815eabbe0ce |
| --- /dev/null |
| +++ b/net/reporting/reporting_delivery_agent.h |
| @@ -0,0 +1,89 @@ |
| +// Copyright 2017 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. |
| + |
| +#ifndef NET_REPORTING_REPORTING_DELIVERY_AGENT_H_ |
| +#define NET_REPORTING_REPORTING_DELIVERY_AGENT_H_ |
| + |
| +#include <memory> |
| +#include <set> |
| +#include <string> |
| +#include <utility> |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "net/base/backoff_entry.h" |
| +#include "net/base/net_export.h" |
| +#include "net/reporting/reporting_endpoint_manager.h" |
| +#include "net/reporting/reporting_uploader.h" |
| +#include "url/gurl.h" |
| +#include "url/origin.h" |
| + |
| +namespace base { |
| +class TickClock; |
| +} // namespace base |
| + |
| +namespace net { |
| + |
| +class ReportingCache; |
| + |
| +// Takes reports from the ReportingCache, assembles reports into deliveries to |
| +// endpoints, and sends those deliveries using ReportingUploader. |
| +// |
| +// Since the Reporting spec is completely silent on issues of concurrency, the |
| +// delivery agent handles it as so: |
| +// |
| +// 1. An individual report can only be part of one delivery at once -- if |
| +// SendReports is called again while a report is being delivered, it won't |
| +// be included in another delivery. (This is, in fact, made redundant by rule |
| +// 3, but it's included anyway in case rule 3 changes.) |
| +// |
| +// 2. An endpoint can only be the target of one delivery at once -- if |
| +// SendReports is called again with reports that could be delivered to that |
| +// endpoint, it won't be chosen. This may mean that the new reports are not |
| +// delivered at all. |
| +// |
| +// 3. Reports for an (origin, group) tuple can only be included in one delivery |
| +// at once -- if SendReports is called again with reports in that (origin, |
| +// group), they won't be included in any delivery. (This prevents the agent |
| +// from getting around rule 2 by using other endpoints.) |
| +// |
| +// 4. Reports for an origin *can* be included in multiple deliveries if they are |
| +// in different groups. |
| +class NET_EXPORT ReportingDeliveryAgent { |
| + public: |
| + ReportingDeliveryAgent(base::TickClock* clock, |
| + ReportingCache* cache, |
| + ReportingUploader* uploader, |
| + const BackoffEntry::Policy* endpoint_backoff_policy); |
|
shivanisha
2017/03/30 20:16:11
Document the lifetime assumptions of clock, cache,
Julia Tuttle
2017/03/31 14:49:48
Done.
|
| + ~ReportingDeliveryAgent(); |
| + |
| + // Tries to deliver all of the reports in the cache. Reports that are already |
| + // being delivered will not be attempted a second time, and reports that do |
| + // not have a viable endpoint will be neither attempted nor removed. |
| + void SendReports(); |
| + |
| + private: |
| + class Delivery; |
| + |
| + using OriginGroup = std::pair<url::Origin, std::string>; |
| + |
| + void OnUploadComplete(const std::unique_ptr<Delivery>& delivery, |
| + ReportingUploader::Outcome outcome); |
| + |
| + base::TickClock* clock_; |
| + ReportingCache* cache_; |
| + ReportingUploader* uploader_; |
| + |
| + ReportingEndpointManager endpoint_manager_; |
| + // Would be an unordered_set, but there's no hash on pair. |
|
shivanisha
2017/03/30 20:16:11
new line before the comment.
Julia Tuttle
2017/03/31 14:49:48
Done.
|
| + std::set<OriginGroup> pending_origin_groups_; |
|
shivanisha
2017/03/30 20:16:11
A comment here on how pending_origin_groups_ would
Julia Tuttle
2017/03/31 14:49:48
Done.
|
| + |
| + base::WeakPtrFactory<ReportingDeliveryAgent> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ReportingDeliveryAgent); |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_REPORTING_REPORTING_DELIVERY_AGENT_H_ |