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

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

Issue 2917913002: Add getters and setters for BrokenAlternativeService's list of broken and recently-broken alt svcs (Closed)
Patch Set: Fixed entry override logic in SetBrokenAndRecentlyBrokenAlternativeServices() 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/timer/timer.h" 12 #include "base/timer/timer.h"
13 #include "net/http/http_server_properties.h" 13 #include "net/http/http_server_properties.h"
14 14
15 namespace base { 15 namespace base {
16 class TickClock; 16 class TickClock;
17 } 17 }
18 18
19 namespace net { 19 namespace net {
20 20
21 struct AlternativeServiceHash {
22 size_t operator()(const net::AlternativeService& entry) const {
23 return entry.protocol ^ std::hash<std::string>()(entry.host) ^ entry.port;
24 }
25 };
26
27 // This class tracks HTTP alternative services that have been marked as broken. 21 // This class tracks HTTP alternative services that have been marked as broken.
28 // The brokenness of an alt-svc will expire after some time according to an 22 // The brokenness of an alt-svc will expire after some time according to an
29 // exponential back-off formula: each time an alt-svc is marked broken, the 23 // exponential back-off formula: each time an alt-svc is marked broken, the
30 // expiration delay will be some constant multiple of its previous expiration 24 // expiration delay will be some constant multiple of its previous expiration
31 // delay. This prevents broken alt-svcs from being retried too often by the 25 // delay. This prevents broken alt-svcs from being retried too often by the
32 // network stack. 26 // network stack.
33 class NET_EXPORT_PRIVATE BrokenAlternativeServices { 27 class NET_EXPORT_PRIVATE BrokenAlternativeServices {
34 public: 28 public:
35 // Delegate to be used by owner so it can be notified when the brokenness of 29 // Delegate to be used by owner so it can be notified when the brokenness of
36 // an AlternativeService expires. 30 // an AlternativeService expires.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // Returns true if MarkAlternativeServiceRecentlyBroken(alternative_service) 72 // Returns true if MarkAlternativeServiceRecentlyBroken(alternative_service)
79 // or MarkAlternativeServiceBroken(alternative_service) has been called and 73 // or MarkAlternativeServiceBroken(alternative_service) has been called and
80 // ConfirmAlternativeService(alternative_service) has not been called 74 // ConfirmAlternativeService(alternative_service) has not been called
81 // afterwards (even if brokenness of |alternative_service| has expired). 75 // afterwards (even if brokenness of |alternative_service| has expired).
82 bool WasAlternativeServiceRecentlyBroken( 76 bool WasAlternativeServiceRecentlyBroken(
83 const AlternativeService& alternative_service); 77 const AlternativeService& alternative_service);
84 78
85 // Marks |alternative_service| as not broken and not recently broken. 79 // Marks |alternative_service| as not broken and not recently broken.
86 void ConfirmAlternativeService(const AlternativeService& alternative_service); 80 void ConfirmAlternativeService(const AlternativeService& alternative_service);
87 81
82 // Sets broken and recently broken alternative services.
83 // |broken_alternative_service_list| must be sorted from earliest to latest
84 // expiration time.
85 // All AlternativeServices in |broken_alternative_service_list| must exist in
86 // |recently_broken_alternative_services|.
87 void SetBrokenAndRecentlyBrokenAlternativeServices(
88 std::unique_ptr<BrokenAlternativeServiceList>
89 broken_alternative_service_list,
90 std::unique_ptr<RecentlyBrokenAlternativeServices>
91 recently_broken_alternative_services);
92
93 const BrokenAlternativeServiceList& broken_alternative_service_list() const;
94
95 const RecentlyBrokenAlternativeServices&
96 recently_broken_alternative_services() const;
97
88 private: 98 private:
89 // TODO (wangyix): modify HttpServerPropertiesImpl unit tests so this 99 // TODO (wangyix): modify HttpServerPropertiesImpl unit tests so this
90 // friendness is no longer required. 100 // friendness is no longer required.
91 friend class HttpServerPropertiesImplPeer; 101 friend class HttpServerPropertiesImplPeer;
92 102
93 // A pair containing a broken AlternativeService and the expiration time of 103 struct AlternativeServiceHash {
94 // its brokenness. 104 size_t operator()(const net::AlternativeService& entry) const {
95 struct BrokenAltSvcExpireInfo { 105 return entry.protocol ^ std::hash<std::string>()(entry.host) ^ entry.port;
96 BrokenAltSvcExpireInfo(const AlternativeService& alt_svc, 106 }
97 base::TimeTicks expire)
98 : alternative_service(alt_svc), expiration(expire) {}
99
100 AlternativeService alternative_service;
101 base::TimeTicks expiration;
102 }; 107 };
103 108
104 typedef std::list<BrokenAltSvcExpireInfo> BrokenAlternativeServiceList;
105
106 typedef std::unordered_map<AlternativeService, 109 typedef std::unordered_map<AlternativeService,
107 BrokenAlternativeServiceList::iterator, 110 BrokenAlternativeServiceList::iterator,
108 AlternativeServiceHash> 111 AlternativeServiceHash>
109 BrokenAlternativeServiceMap; 112 BrokenAlternativeServiceMap;
110 113
111 // Inserts |alternative_service| and its |expiration| time into 114 // Inserts |alternative_service| and its |expiration| time into
112 // |broken_alternative_service_list_| and |broken_alternative_service_map_|. 115 // |broken_alternative_service_list_| and |broken_alternative_service_map_|.
113 // |it| is the position in |broken_alternative_service_list_| where it was 116 // |it| is the position in |broken_alternative_service_list_| where it was
114 // inserted. 117 // inserted.
115 bool AddToBrokenAlternativeServiceListAndMap( 118 bool AddToBrokenAlternativeServiceListAndMap(
(...skipping 20 matching lines...) Expand all
136 // Used for scheduling the task that expires the brokenness of alternative 139 // Used for scheduling the task that expires the brokenness of alternative
137 // services. 140 // services.
138 base::OneShotTimer expiration_timer_; 141 base::OneShotTimer expiration_timer_;
139 142
140 base::WeakPtrFactory<BrokenAlternativeServices> weak_ptr_factory_; 143 base::WeakPtrFactory<BrokenAlternativeServices> weak_ptr_factory_;
141 }; 144 };
142 145
143 } // namespace net 146 } // namespace net
144 147
145 #endif // NET_HTTP_BROKEN_ALTERNATIVE_SERVICES_H_ 148 #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