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

Side by Side Diff: net/http/broken_alternative_services.h

Issue 2932953002: Persist broken and recently-broken alt-svcs to prefs in HttpServerPropertiesManager (Closed)
Patch Set: Added a DCHECK Created 3 years, 6 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 (c) 2017 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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_HTTP_BROKEN_ALTERNATIVE_SERVICES_H_ 5 #ifndef NET_HTTP_BROKEN_ALTERNATIVE_SERVICES_H_
6 #define NET_HTTP_BROKEN_ALTERNATIVE_SERVICES_H_ 6 #define NET_HTTP_BROKEN_ALTERNATIVE_SERVICES_H_
7 7
8 #include <list> 8 #include <list>
9 #include <unordered_map> 9 #include <unordered_map>
10 10
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/time/default_tick_clock.h"
12 #include "base/timer/timer.h" 13 #include "base/timer/timer.h"
13 #include "net/http/http_server_properties.h" 14 #include "net/http/http_server_properties.h"
14 15
15 namespace base {
16 class TickClock;
17 }
18
19 namespace net { 16 namespace net {
20 17
21 // This class tracks HTTP alternative services that have been marked as broken. 18 // This class tracks HTTP alternative services that have been marked as broken.
22 // The brokenness of an alt-svc will expire after some time according to an 19 // The brokenness of an alt-svc will expire after some time according to an
23 // exponential back-off formula: each time an alt-svc is marked broken, the 20 // exponential back-off formula: each time an alt-svc is marked broken, the
24 // expiration delay will be some constant multiple of its previous expiration 21 // expiration delay will be some constant multiple of its previous expiration
25 // delay. This prevents broken alt-svcs from being retried too often by the 22 // delay. This prevents broken alt-svcs from being retried too often by the
26 // network stack. 23 // network stack.
27 class NET_EXPORT_PRIVATE BrokenAlternativeServices { 24 class NET_EXPORT_PRIVATE BrokenAlternativeServices {
28 public: 25 public:
29 // Delegate to be used by owner so it can be notified when the brokenness of 26 // Delegate to be used by owner so it can be notified when the brokenness of
30 // an AlternativeService expires. 27 // an AlternativeService expires.
31 class NET_EXPORT Delegate { 28 class NET_EXPORT Delegate {
32 public: 29 public:
33 // Called when a broken alternative service's expiration time is reached. 30 // Called when a broken alternative service's expiration time is reached.
34 virtual void OnExpireBrokenAlternativeService( 31 virtual void OnExpireBrokenAlternativeService(
35 const AlternativeService& expired_alternative_service) = 0; 32 const AlternativeService& expired_alternative_service) = 0;
36 virtual ~Delegate() {} 33 virtual ~Delegate() {}
37 }; 34 };
38 35
39 // |delegate| will be notified when a broken alternative service expires. It 36 // |delegate| will be notified when a broken alternative service expires. It
40 // must not be null. 37 // must not be null.
41 // |clock| is used for setting expiration times and scheduling the 38 // |clock| is used for setting expiration times and scheduling the
42 // expiration of broken alternative services. It must not be null. 39 // expiration of broken alternative services. It must not be null.
43 // |delegate| and |clock| are both unowned and must outlive this. 40 // |delegate| and |clock| are both unowned and must outlive this.
44 BrokenAlternativeServices(Delegate* delegate, base::TickClock* clock); 41 BrokenAlternativeServices(Delegate* delegate);
45 42
46 BrokenAlternativeServices(const BrokenAlternativeServices&) = delete; 43 BrokenAlternativeServices(const BrokenAlternativeServices&) = delete;
47 void operator=(const BrokenAlternativeServices&) = delete; 44 void operator=(const BrokenAlternativeServices&) = delete;
48 45
49 ~BrokenAlternativeServices(); 46 ~BrokenAlternativeServices();
50 47
48 void Clear();
Ryan Hamilton 2017/06/12 18:57:32 nit: Comment (though it's probably fairly obvious)
wangyix1 2017/06/14 00:01:25 Done.
49
51 // Marks |alternative_service| as broken until after some expiration delay 50 // Marks |alternative_service| as broken until after some expiration delay
52 // (determined by how many times it's been marked broken before). Being broken 51 // (determined by how many times it's been marked broken before). Being broken
53 // will cause IsAlternativeServiceBroken(alternative_service) to return true 52 // will cause IsAlternativeServiceBroken(alternative_service) to return true
54 // until the expiration time is reached, or until 53 // until the expiration time is reached, or until
55 // ConfirmAlternativeService(alternative_service) is called. 54 // ConfirmAlternativeService(alternative_service) is called.
56 void MarkAlternativeServiceBroken( 55 void MarkAlternativeServiceBroken(
57 const AlternativeService& alternative_service); 56 const AlternativeService& alternative_service);
58 57
59 // Marks |alternative_service| as recently broken. Being recently broken will 58 // Marks |alternative_service| as recently broken. Being recently broken will
60 // cause WasAlternativeServiceRecentlyBroken(alternative_service) to return 59 // cause WasAlternativeServiceRecentlyBroken(alternative_service) to return
(...skipping 16 matching lines...) Expand all
77 const AlternativeService& alternative_service); 76 const AlternativeService& alternative_service);
78 77
79 // Marks |alternative_service| as not broken and not recently broken. 78 // Marks |alternative_service| as not broken and not recently broken.
80 void ConfirmAlternativeService(const AlternativeService& alternative_service); 79 void ConfirmAlternativeService(const AlternativeService& alternative_service);
81 80
82 // Adds broken and recently broken alternative services. 81 // Adds broken and recently broken alternative services.
83 // |broken_alternative_service_list| must be sorted from earliest to latest 82 // |broken_alternative_service_list| must be sorted from earliest to latest
84 // expiration time. 83 // expiration time.
85 // All AlternativeServices in |broken_alternative_service_list| must exist in 84 // All AlternativeServices in |broken_alternative_service_list| must exist in
86 // |recently_broken_alternative_services|. 85 // |recently_broken_alternative_services|.
87 // Returns whether or not any alternative services were actually added. 86 //
88 bool AddBrokenAndRecentlyBrokenAlternativeServices( 87 // If a broken/recently-broken alt svc that's being added is already stored,
88 // the stored expiration/broken-count for that alt svc will be overwritten
89 // with the new value.
90 // However, |recently_broken_alternative_services_| will still have the
91 // already-stored alt svcs at the front of the recency list, followed by the
92 // newly added ones.
93 void AddBrokenAndRecentlyBrokenAlternativeServices(
89 std::unique_ptr<BrokenAlternativeServiceList> 94 std::unique_ptr<BrokenAlternativeServiceList>
90 broken_alternative_service_list, 95 broken_alternative_service_list,
91 std::unique_ptr<RecentlyBrokenAlternativeServices> 96 std::unique_ptr<RecentlyBrokenAlternativeServices>
92 recently_broken_alternative_services); 97 recently_broken_alternative_services);
93 98
94 const BrokenAlternativeServiceList& broken_alternative_service_list() const; 99 const BrokenAlternativeServiceList& broken_alternative_service_list() const;
95 100
96 const RecentlyBrokenAlternativeServices& 101 const RecentlyBrokenAlternativeServices&
97 recently_broken_alternative_services() const; 102 recently_broken_alternative_services() const;
98 103
104 // |clock| is unowned.
Ryan Hamilton 2017/06/12 18:57:32 I think you mean to say that |clock| must outlive
wangyix1 2017/06/14 00:01:25 Function has been removed
105 void SetTickClockForTesting(base::TickClock* clock);
106
99 private: 107 private:
100 // TODO (wangyix): modify HttpServerPropertiesImpl unit tests so this 108 // TODO (wangyix): modify HttpServerPropertiesImpl unit tests so this
101 // friendness is no longer required. 109 // friendness is no longer required.
102 friend class HttpServerPropertiesImplPeer; 110 friend class HttpServerPropertiesImplPeer;
103 111
104 struct AlternativeServiceHash { 112 struct AlternativeServiceHash {
105 size_t operator()(const net::AlternativeService& entry) const { 113 size_t operator()(const net::AlternativeService& entry) const {
106 return entry.protocol ^ std::hash<std::string>()(entry.host) ^ entry.port; 114 return entry.protocol ^ std::hash<std::string>()(entry.host) ^ entry.port;
107 } 115 }
108 }; 116 };
109 117
110 typedef std::unordered_map<AlternativeService, 118 typedef std::unordered_map<AlternativeService,
111 BrokenAlternativeServiceList::iterator, 119 BrokenAlternativeServiceList::iterator,
112 AlternativeServiceHash> 120 AlternativeServiceHash>
113 BrokenAlternativeServiceMap; 121 BrokenAlternativeServiceMap;
114 122
115 // Inserts |alternative_service| and its |expiration| time into 123 // Inserts |alternative_service| and its |expiration| time into
116 // |broken_alternative_service_list_| and |broken_alternative_service_map_|. 124 // |broken_alternative_service_list_| and |broken_alternative_service_map_|.
117 // |it| is the position in |broken_alternative_service_list_| where it was 125 // |it| is the position in |broken_alternative_service_list_| where it was
118 // inserted. 126 // inserted.
119 bool AddToBrokenAlternativeServiceListAndMap( 127 bool AddToBrokenAlternativeServiceListAndMap(
120 const AlternativeService& alternative_service, 128 const AlternativeService& alternative_service,
121 base::TimeTicks expiration, 129 base::TimeTicks expiration,
122 BrokenAlternativeServiceList::iterator* it); 130 BrokenAlternativeServiceList::iterator* it);
123 131
124 void ExpireBrokenAlternateProtocolMappings(); 132 void ExpireBrokenAlternateProtocolMappings();
125 void ScheduleBrokenAlternateProtocolMappingsExpiration(); 133 void ScheduleBrokenAlternateProtocolMappingsExpiration(base::TimeTicks when);
126 134
127 Delegate* delegate_; // Unowned 135 Delegate* delegate_; // Unowned
128 base::TickClock* clock_; // Unowned 136 base::TickClock* clock_; // Unowned if not pointing to |default_clock_|.
Ryan Hamilton 2017/06/12 18:57:32 I'd just say "Unowned". Because you'll never say "
wangyix1 2017/06/14 00:01:25 Done.
137
138 base::DefaultTickClock default_clock_;
129 139
130 // List of <broken alt svc, expiration time> pairs sorted by expiration time. 140 // List of <broken alt svc, expiration time> pairs sorted by expiration time.
131 BrokenAlternativeServiceList broken_alternative_service_list_; 141 BrokenAlternativeServiceList broken_alternative_service_list_;
132 // A map from broken alt-svcs to their iterator pointing to that alt-svc's 142 // A map from broken alt-svcs to their iterator pointing to that alt-svc's
133 // position in |broken_alternative_service_list_|. 143 // position in |broken_alternative_service_list_|.
134 BrokenAlternativeServiceMap broken_alternative_service_map_; 144 BrokenAlternativeServiceMap broken_alternative_service_map_;
135 145
136 // Maps broken alternative services to how many times they've been marked 146 // Maps broken alternative services to how many times they've been marked
137 // broken. 147 // broken.
138 RecentlyBrokenAlternativeServices recently_broken_alternative_services_; 148 RecentlyBrokenAlternativeServices recently_broken_alternative_services_;
139 149
140 // Used for scheduling the task that expires the brokenness of alternative 150 // Used for scheduling the task that expires the brokenness of alternative
141 // services. 151 // services.
142 base::OneShotTimer expiration_timer_; 152 base::OneShotTimer expiration_timer_;
143 153
144 base::WeakPtrFactory<BrokenAlternativeServices> weak_ptr_factory_; 154 base::WeakPtrFactory<BrokenAlternativeServices> weak_ptr_factory_;
145 }; 155 };
146 156
147 } // namespace net 157 } // namespace net
148 158
149 #endif // NET_HTTP_BROKEN_ALTERNATIVE_SERVICES_H_ 159 #endif // NET_HTTP_BROKEN_ALTERNATIVE_SERVICES_H_
OLDNEW
« no previous file with comments | « no previous file | net/http/broken_alternative_services.cc » ('j') | net/http/broken_alternative_services.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698