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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef NET_REPORTING_REPORTING_DELIVERY_AGENT_H_
6 #define NET_REPORTING_REPORTING_DELIVERY_AGENT_H_
7
8 #include <memory>
9 #include <set>
10 #include <string>
11 #include <utility>
12
13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h"
15 #include "net/base/backoff_entry.h"
16 #include "net/base/net_export.h"
17 #include "net/reporting/reporting_endpoint_manager.h"
18 #include "net/reporting/reporting_uploader.h"
19 #include "url/gurl.h"
20 #include "url/origin.h"
21
22 namespace base {
23 class TickClock;
24 } // namespace base
25
26 namespace net {
27
28 class ReportingCache;
29
30 // Takes reports from the ReportingCache, assembles reports into deliveries to
31 // endpoints, and sends those deliveries using ReportingUploader.
32 //
33 // Since the Reporting spec is completely silent on issues of concurrency, the
34 // delivery agent handles it as so:
35 //
36 // 1. An individual report can only be included in one delivery at once -- if
37 // SendReports is called again while a report is being delivered, it won't
38 // be included in another delivery during that call to SendReports. (This is,
39 // in fact, made redundant by rule 3, but it's included anyway in case rule 3
40 // changes.)
41 //
42 // 2. An endpoint can only be the target of one delivery at once -- if
43 // SendReports is called again with reports that could be delivered to that
44 // endpoint, it won't be chosen. This may mean that the new reports are not
Randy Smith (Not in Mondays) 2017/04/05 19:02:38 The antecedent of "it" isn't clear to me in this s
Julia Tuttle 2017/04/06 17:03:14 Done.
45 // delivered anywhere during that call to SendReports.
46 //
47 // 3. Reports for an (origin, group) tuple can only be included in one delivery
48 // at once -- if SendReports is called again with reports in that (origin,
49 // group), they won't be included in any delivery during that call to
50 // SendReports. (This prevents the agent from getting around rule 2 by using
51 // other endpoints.)
52 //
53 // 4. Reports for the same origin *can* be included in multiple parallel
54 // deliveries if they are in different groups within that origin.
55 //
56 // (Note that a single delivery can contain an infinite number of reports.)
57 //
58 // TODO(juliatuttle): Consider capping the maximum number of reports per
59 // delivery attempt.
60 class NET_EXPORT ReportingDeliveryAgent {
61 public:
62 // |clock|, |cache|, |uploader|, and |endpoint_backoff_policy| must all
63 // outlive the ReportingDeliveryAgent.
64 ReportingDeliveryAgent(base::TickClock* clock,
65 ReportingCache* cache,
66 ReportingUploader* uploader,
67 const BackoffEntry::Policy* endpoint_backoff_policy);
68 ~ReportingDeliveryAgent();
69
70 // Tries to deliver all of the reports in the cache. Reports that are already
71 // being delivered will not be attempted a second time, and reports that do
72 // not have a viable endpoint will be neither attempted nor removed.
73 void SendReports();
Randy Smith (Not in Mondays) 2017/04/05 19:02:38 Why is this controlled by a consumer rather than b
Julia Tuttle 2017/04/06 17:03:14 It'll be doing exactly that eventually, but I want
74
75 private:
76 class Delivery;
77
78 using OriginGroup = std::pair<url::Origin, std::string>;
79
80 void OnUploadComplete(const std::unique_ptr<Delivery>& delivery,
81 ReportingUploader::Outcome outcome);
82
83 base::TickClock* clock_;
84 ReportingCache* cache_;
85 ReportingUploader* uploader_;
86
87 ReportingEndpointManager endpoint_manager_;
88
89 // Tracks OriginGroup tuples for which there is a pending delivery running.
90 // (Would be an unordered_set, but there's no hash on pair.)
Randy Smith (Not in Mondays) 2017/04/05 19:02:38 Suggestion: I'd erase this last sentence. It invi
Julia Tuttle 2017/04/06 17:03:14 The parenthetical note is there because otherwise
91 std::set<OriginGroup> pending_origin_groups_;
92
93 base::WeakPtrFactory<ReportingDeliveryAgent> weak_factory_;
94
95 DISALLOW_COPY_AND_ASSIGN(ReportingDeliveryAgent);
96 };
97
98 } // namespace net
99
100 #endif // NET_REPORTING_REPORTING_DELIVERY_AGENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698