Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 part of 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. (This is, in fact, made redundant by rule | |
| 39 // 3, but it's included anyway in case rule 3 changes.) | |
| 40 // | |
| 41 // 2. An endpoint can only be the target of one delivery at once -- if | |
| 42 // SendReports is called again with reports that could be delivered to that | |
| 43 // endpoint, it won't be chosen. This may mean that the new reports are not | |
| 44 // delivered at all. | |
| 45 // | |
| 46 // 3. Reports for an (origin, group) tuple can only be included in one delivery | |
| 47 // at once -- if SendReports is called again with reports in that (origin, | |
| 48 // group), they won't be included in any delivery. (This prevents the agent | |
| 49 // from getting around rule 2 by using other endpoints.) | |
| 50 // | |
| 51 // 4. Reports for an origin *can* be included in multiple deliveries if they are | |
| 52 // in different groups. | |
| 53 class NET_EXPORT ReportingDeliveryAgent { | |
| 54 public: | |
| 55 ReportingDeliveryAgent(base::TickClock* clock, | |
| 56 ReportingCache* cache, | |
| 57 ReportingUploader* uploader, | |
| 58 const BackoffEntry::Policy* endpoint_backoff_policy); | |
|
shivanisha
2017/03/30 20:16:11
Document lifetime assumptions for clock, cache, up
| |
| 59 ~ReportingDeliveryAgent(); | |
| 60 | |
| 61 // Tries to deliver all of the reports in the cache. Reports that are already | |
| 62 // being delivered will not be attempted a second time, and reports that do | |
| 63 // not have a viable endpoint will be neither attempted nor removed. | |
| 64 void SendReports(); | |
| 65 | |
| 66 private: | |
| 67 class Delivery; | |
| 68 | |
| 69 using OriginGroup = std::pair<url::Origin, std::string>; | |
| 70 | |
| 71 void OnUploadComplete(const std::unique_ptr<Delivery>& delivery, | |
| 72 ReportingUploader::Outcome outcome); | |
| 73 | |
| 74 base::TickClock* clock_; | |
| 75 ReportingCache* cache_; | |
| 76 ReportingUploader* uploader_; | |
| 77 | |
| 78 ReportingEndpointManager endpoint_manager_; | |
| 79 // Would be an unordered_set, but there's no hash on pair. | |
| 80 std::set<OriginGroup> pending_origin_groups_; | |
| 81 | |
| 82 base::WeakPtrFactory<ReportingDeliveryAgent> weak_factory_; | |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(ReportingDeliveryAgent); | |
| 85 }; | |
| 86 | |
| 87 } // namespace net | |
| 88 | |
| 89 #endif // NET_REPORTING_REPORTING_DELIVERY_AGENT_H_ | |
| OLD | NEW |