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

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

Powered by Google App Engine
This is Rietveld 408576698