| 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_ENDPOINT_MANAGER_H_ |
| 6 #define NET_REPORTING_REPORTING_ENDPOINT_MANAGER_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <memory> |
| 10 #include <set> |
| 11 #include <string> |
| 12 |
| 13 #include "base/macros.h" |
| 14 #include "net/base/backoff_entry.h" |
| 15 #include "net/base/net_export.h" |
| 16 |
| 17 class GURL; |
| 18 |
| 19 namespace base { |
| 20 class TickClock; |
| 21 } // namespace base |
| 22 |
| 23 namespace url { |
| 24 class Origin; |
| 25 } // namespace url |
| 26 |
| 27 namespace net { |
| 28 |
| 29 class ReportingCache; |
| 30 |
| 31 // Keeps track of which endpoints are pending (have active delivery attempts to |
| 32 // them) or in exponential backoff after one or more failures, and chooses an |
| 33 // endpoint from an endpoint group to receive reports for an origin. |
| 34 class NET_EXPORT ReportingEndpointManager { |
| 35 public: |
| 36 // Note: All three parameters must outlive the endpoint manager. |
| 37 ReportingEndpointManager(base::TickClock* clock, |
| 38 const ReportingCache* cache, |
| 39 const BackoffEntry::Policy* backoff_policy); |
| 40 ~ReportingEndpointManager(); |
| 41 |
| 42 // Finds an endpoint configured by |origin| in group |group| that is not |
| 43 // pending, in exponential backoff from failed requests, or expired. |
| 44 // |
| 45 // Deliberately chooses an endpoint randomly to ensure sites aren't relying on |
| 46 // any sort of fallback ordering. |
| 47 // |
| 48 // Returns true and sets |*endpoint_url_out| to the endpoint URL if an |
| 49 // endpoint was chosen; returns false (and leaves |*endpoint_url_out| invalid) |
| 50 // if no endpoint was found. |
| 51 bool FindEndpointForOriginAndGroup(const url::Origin& origin, |
| 52 const std::string& group, |
| 53 GURL* endpoint_url_out); |
| 54 |
| 55 // Adds |endpoint| to the set of pending endpoints, preventing it from being |
| 56 // chosen for a second parallel delivery attempt. |
| 57 void SetEndpointPending(const GURL& endpoint); |
| 58 |
| 59 // Removes |endpoint| from the set of pending endpoints. |
| 60 void ClearEndpointPending(const GURL& endpoint); |
| 61 |
| 62 // Informs the EndpointManager of a successful or unsuccessful request made to |
| 63 // |endpoint| so it can manage exponential backoff of failing endpoints. |
| 64 void InformOfEndpointRequest(const GURL& endpoint, bool succeeded); |
| 65 |
| 66 private: |
| 67 base::TickClock* clock_; |
| 68 const ReportingCache* cache_; |
| 69 const BackoffEntry::Policy* backoff_policy_; |
| 70 |
| 71 std::set<GURL> pending_endpoints_; |
| 72 std::map<GURL, std::unique_ptr<net::BackoffEntry>> endpoint_backoff_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(ReportingEndpointManager); |
| 75 }; |
| 76 |
| 77 } // namespace net |
| 78 |
| 79 #endif // NET_REPORTING_REPORTING_ENDPOINT_MANAGER_H_ |
| OLD | NEW |