| OLD | NEW |
| 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_CACHE_H_ | 5 #ifndef NET_REPORTING_REPORTING_CACHE_H_ |
| 6 #define NET_REPORTING_REPORTING_CACHE_H_ | 6 #define NET_REPORTING_REPORTING_CACHE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <unordered_map> | 12 #include <unordered_map> |
| 13 #include <unordered_set> | 13 #include <unordered_set> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "net/base/net_export.h" | 20 #include "net/base/net_export.h" |
| 21 #include "net/reporting/reporting_client.h" | 21 #include "net/reporting/reporting_client.h" |
| 22 #include "net/reporting/reporting_report.h" |
| 22 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 23 #include "url/origin.h" | 24 #include "url/origin.h" |
| 24 | 25 |
| 25 namespace base { | 26 namespace base { |
| 26 class TickClock; | 27 class TickClock; |
| 27 } // namespace base | 28 } // namespace base |
| 28 | 29 |
| 29 namespace net { | 30 namespace net { |
| 30 | 31 |
| 31 class ReportingContext; | 32 class ReportingContext; |
| 32 struct ReportingReport; | |
| 33 | 33 |
| 34 // The cache holds undelivered reports and clients (per-origin endpoint | 34 // The cache holds undelivered reports and clients (per-origin endpoint |
| 35 // configurations) in memory. (It is not responsible for persisting them.) | 35 // configurations) in memory. (It is not responsible for persisting them.) |
| 36 // | 36 // |
| 37 // This corresponds roughly to the "Reporting cache" in the spec, except that | 37 // This corresponds roughly to the "Reporting cache" in the spec, except that |
| 38 // endpoints and clients are stored in a more structurally-convenient way, and | 38 // endpoints and clients are stored in a more structurally-convenient way, and |
| 39 // endpoint failures/retry-after are tracked in ReportingEndpointManager. | 39 // endpoint failures/retry-after are tracked in ReportingEndpointManager. |
| 40 // | 40 // |
| 41 // The cache implementation has the notion of "pending" reports. These are | 41 // The cache implementation has the notion of "pending" reports. These are |
| 42 // reports that are part of an active delivery attempt, so they won't be | 42 // reports that are part of an active delivery attempt, so they won't be |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // pending. | 76 // pending. |
| 77 void ClearReportsPending(const std::vector<const ReportingReport*>& reports); | 77 void ClearReportsPending(const std::vector<const ReportingReport*>& reports); |
| 78 | 78 |
| 79 // Increments |attempts| on a set of reports. | 79 // Increments |attempts| on a set of reports. |
| 80 void IncrementReportsAttempts( | 80 void IncrementReportsAttempts( |
| 81 const std::vector<const ReportingReport*>& reports); | 81 const std::vector<const ReportingReport*>& reports); |
| 82 | 82 |
| 83 // Removes a set of reports. Any reports that are pending will not be removed | 83 // Removes a set of reports. Any reports that are pending will not be removed |
| 84 // immediately, but rather marked doomed and removed once they are no longer | 84 // immediately, but rather marked doomed and removed once they are no longer |
| 85 // pending. | 85 // pending. |
| 86 void RemoveReports(const std::vector<const ReportingReport*>& reports); | 86 void RemoveReports(const std::vector<const ReportingReport*>& reports, |
| 87 ReportingReport::Outcome outcome); |
| 87 | 88 |
| 88 // Removes all reports. Like |RemoveReports()|, pending reports are doomed | 89 // Removes all reports. Like |RemoveReports()|, pending reports are doomed |
| 89 // until no longer pending. | 90 // until no longer pending. |
| 90 void RemoveAllReports(); | 91 void RemoveAllReports(ReportingReport::Outcome outcome); |
| 91 | 92 |
| 92 // Creates or updates a client for a particular origin and a particular | 93 // Creates or updates a client for a particular origin and a particular |
| 93 // endpoint. | 94 // endpoint. |
| 94 // | 95 // |
| 95 // All parameters correspond to the desired values for the fields in | 96 // All parameters correspond to the desired values for the fields in |
| 96 // |Client|. | 97 // |Client|. |
| 97 // | 98 // |
| 98 // |endpoint| must use a cryptographic scheme. | 99 // |endpoint| must use a cryptographic scheme. |
| 99 void SetClient(const url::Origin& origin, | 100 void SetClient(const url::Origin& origin, |
| 100 const GURL& endpoint, | 101 const GURL& endpoint, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 159 |
| 159 bool IsReportPendingForTesting(const ReportingReport* report) const { | 160 bool IsReportPendingForTesting(const ReportingReport* report) const { |
| 160 return base::ContainsKey(pending_reports_, report); | 161 return base::ContainsKey(pending_reports_, report); |
| 161 } | 162 } |
| 162 | 163 |
| 163 bool IsReportDoomedForTesting(const ReportingReport* report) const { | 164 bool IsReportDoomedForTesting(const ReportingReport* report) const { |
| 164 return base::ContainsKey(doomed_reports_, report); | 165 return base::ContainsKey(doomed_reports_, report); |
| 165 } | 166 } |
| 166 | 167 |
| 167 private: | 168 private: |
| 169 void RemoveReportInternal(const ReportingReport* report); |
| 170 |
| 168 const ReportingReport* FindReportToEvict() const; | 171 const ReportingReport* FindReportToEvict() const; |
| 169 | 172 |
| 170 void AddClient(std::unique_ptr<ReportingClient> client, | 173 void AddClient(std::unique_ptr<ReportingClient> client, |
| 171 base::TimeTicks last_used); | 174 base::TimeTicks last_used); |
| 172 | 175 |
| 173 void RemoveClient(const ReportingClient* client); | 176 void RemoveClient(const ReportingClient* client); |
| 174 | 177 |
| 175 const ReportingClient* GetClientByOriginAndEndpoint( | 178 const ReportingClient* GetClientByOriginAndEndpoint( |
| 176 const url::Origin& origin, | 179 const url::Origin& origin, |
| 177 const GURL& endpoint) const; | 180 const GURL& endpoint) const; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 215 |
| 213 // The time that each client has last been used. | 216 // The time that each client has last been used. |
| 214 std::unordered_map<const ReportingClient*, base::TimeTicks> client_last_used_; | 217 std::unordered_map<const ReportingClient*, base::TimeTicks> client_last_used_; |
| 215 | 218 |
| 216 DISALLOW_COPY_AND_ASSIGN(ReportingCache); | 219 DISALLOW_COPY_AND_ASSIGN(ReportingCache); |
| 217 }; | 220 }; |
| 218 | 221 |
| 219 } // namespace net | 222 } // namespace net |
| 220 | 223 |
| 221 #endif // NET_REPORTING_REPORTING_CACHE_H_ | 224 #endif // NET_REPORTING_REPORTING_CACHE_H_ |
| OLD | NEW |