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

Unified Diff: net/reporting/reporting_delivery_agent.h

Issue 2739483002: Reporting: Implement delivery agent. (Closed)
Patch Set: Make requested changes. Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/BUILD.gn ('k') | net/reporting/reporting_delivery_agent.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..f6cda8139e24ccddab1a9af6e803b097ae63ab4b
--- /dev/null
+++ b/net/reporting/reporting_delivery_agent.h
@@ -0,0 +1,99 @@
+// 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 included in one delivery at once -- if
+// SendReports is called again while a report is being delivered, it won't
+// be included in another delivery during that call to SendReports. (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, they won't be delivered to that endpoint.
+//
+// 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 during that call to
+// SendReports. (This prevents the agent from getting around rule 2 by using
+// other endpoints in the same group.)
+//
+// 4. Reports for the same origin *can* be included in multiple parallel
+// deliveries if they are in different groups within that origin.
+//
+// (Note that a single delivery can contain an infinite number of reports.)
+//
+// TODO(juliatuttle): Consider capping the maximum number of reports per
+// delivery attempt.
+class NET_EXPORT ReportingDeliveryAgent {
+ public:
+ // |clock|, |cache|, |uploader|, and |endpoint_backoff_policy| must all
+ // outlive the ReportingDeliveryAgent.
+ ReportingDeliveryAgent(base::TickClock* clock,
+ ReportingCache* cache,
+ ReportingUploader* uploader,
+ const BackoffEntry::Policy* endpoint_backoff_policy);
+ ~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_;
+
+ // Tracks OriginGroup tuples for which there is a pending delivery running.
+ // (Would be an unordered_set, but there's no hash on pair.)
+ std::set<OriginGroup> pending_origin_groups_;
+
+ base::WeakPtrFactory<ReportingDeliveryAgent> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(ReportingDeliveryAgent);
+};
+
+} // namespace net
+
+#endif // NET_REPORTING_REPORTING_DELIVERY_AGENT_H_
« no previous file with comments | « net/BUILD.gn ('k') | net/reporting/reporting_delivery_agent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698