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

Side by Side Diff: net/reporting/reporting_delivery_agent.h

Issue 2751103002: Reporting: Wrap existing classes in context. (Closed)
Patch Set: rebase 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
« no previous file with comments | « net/reporting/reporting_delegate.cc ('k') | net/reporting/reporting_delivery_agent.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef NET_REPORTING_REPORTING_DELIVERY_AGENT_H_ 5 #ifndef NET_REPORTING_REPORTING_DELIVERY_AGENT_H_
6 #define NET_REPORTING_REPORTING_DELIVERY_AGENT_H_ 6 #define NET_REPORTING_REPORTING_DELIVERY_AGENT_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "net/base/backoff_entry.h" 15 #include "net/base/backoff_entry.h"
16 #include "net/base/net_export.h" 16 #include "net/base/net_export.h"
17 #include "net/reporting/reporting_endpoint_manager.h" 17 #include "net/reporting/reporting_context.h"
18 #include "net/reporting/reporting_uploader.h" 18 #include "net/reporting/reporting_uploader.h"
19 #include "url/gurl.h" 19 #include "url/gurl.h"
20 #include "url/origin.h" 20 #include "url/origin.h"
21 21
22 namespace base { 22 namespace base {
23 class TickClock; 23 class TickClock;
24 } // namespace base 24 } // namespace base
25 25
26 namespace net { 26 namespace net {
27 27
28 class ReportingCache; 28 class ReportingCache;
29 class ReportingEndpointManager;
29 30
30 // Takes reports from the ReportingCache, assembles reports into deliveries to 31 // Takes reports from the ReportingCache, assembles reports into deliveries to
31 // endpoints, and sends those deliveries using ReportingUploader. 32 // endpoints, and sends those deliveries using ReportingUploader.
32 // 33 //
33 // Since the Reporting spec is completely silent on issues of concurrency, the 34 // Since the Reporting spec is completely silent on issues of concurrency, the
34 // delivery agent handles it as so: 35 // delivery agent handles it as so:
35 // 36 //
36 // 1. An individual report can only be included in one delivery at once -- if 37 // 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 // 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 // be included in another delivery during that call to SendReports. (This is,
(...skipping 12 matching lines...) Expand all
51 // 52 //
52 // 4. Reports for the same origin *can* be included in multiple parallel 53 // 4. Reports for the same origin *can* be included in multiple parallel
53 // deliveries if they are in different groups within that origin. 54 // deliveries if they are in different groups within that origin.
54 // 55 //
55 // (Note that a single delivery can contain an infinite number of reports.) 56 // (Note that a single delivery can contain an infinite number of reports.)
56 // 57 //
57 // TODO(juliatuttle): Consider capping the maximum number of reports per 58 // TODO(juliatuttle): Consider capping the maximum number of reports per
58 // delivery attempt. 59 // delivery attempt.
59 class NET_EXPORT ReportingDeliveryAgent { 60 class NET_EXPORT ReportingDeliveryAgent {
60 public: 61 public:
61 // |clock|, |cache|, |uploader|, and |endpoint_backoff_policy| must all 62 // |context| must outlive the ReportingDeliveryAgent.
62 // outlive the ReportingDeliveryAgent. 63 ReportingDeliveryAgent(ReportingContext* context);
63 ReportingDeliveryAgent(base::TickClock* clock,
64 ReportingCache* cache,
65 ReportingUploader* uploader,
66 const BackoffEntry::Policy* endpoint_backoff_policy);
67 ~ReportingDeliveryAgent(); 64 ~ReportingDeliveryAgent();
68 65
69 // Tries to deliver all of the reports in the cache. Reports that are already 66 // Tries to deliver all of the reports in the cache. Reports that are already
70 // being delivered will not be attempted a second time, and reports that do 67 // being delivered will not be attempted a second time, and reports that do
71 // not have a viable endpoint will be neither attempted nor removed. 68 // not have a viable endpoint will be neither attempted nor removed.
72 void SendReports(); 69 void SendReports();
73 70
74 private: 71 private:
75 class Delivery; 72 class Delivery;
76 73
77 using OriginGroup = std::pair<url::Origin, std::string>; 74 using OriginGroup = std::pair<url::Origin, std::string>;
78 75
79 void OnUploadComplete(const std::unique_ptr<Delivery>& delivery, 76 void OnUploadComplete(const std::unique_ptr<Delivery>& delivery,
80 ReportingUploader::Outcome outcome); 77 ReportingUploader::Outcome outcome);
81 78
82 base::TickClock* clock_; 79 base::TickClock* tick_clock() { return context_->tick_clock(); }
83 ReportingCache* cache_; 80 ReportingCache* cache() { return context_->cache(); }
84 ReportingUploader* uploader_; 81 ReportingUploader* uploader() { return context_->uploader(); }
82 ReportingEndpointManager* endpoint_manager() {
83 return context_->endpoint_manager();
84 }
85 85
86 ReportingEndpointManager endpoint_manager_; 86 ReportingContext* context_;
87 87
88 // Tracks OriginGroup tuples for which there is a pending delivery running. 88 // Tracks OriginGroup tuples for which there is a pending delivery running.
89 // (Would be an unordered_set, but there's no hash on pair.) 89 // (Would be an unordered_set, but there's no hash on pair.)
90 std::set<OriginGroup> pending_origin_groups_; 90 std::set<OriginGroup> pending_origin_groups_;
91 91
92 base::WeakPtrFactory<ReportingDeliveryAgent> weak_factory_; 92 base::WeakPtrFactory<ReportingDeliveryAgent> weak_factory_;
93 93
94 DISALLOW_COPY_AND_ASSIGN(ReportingDeliveryAgent); 94 DISALLOW_COPY_AND_ASSIGN(ReportingDeliveryAgent);
95 }; 95 };
96 96
97 } // namespace net 97 } // namespace net
98 98
99 #endif // NET_REPORTING_REPORTING_DELIVERY_AGENT_H_ 99 #endif // NET_REPORTING_REPORTING_DELIVERY_AGENT_H_
OLDNEW
« no previous file with comments | « net/reporting/reporting_delegate.cc ('k') | net/reporting/reporting_delivery_agent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698