Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 { | 21 struct AlternativeServiceHash { |
| 22 size_t operator()(const net::AlternativeService& entry) const { | 22 size_t operator()(const net::AlternativeService& entry) const { |
| 23 return entry.protocol ^ std::hash<std::string>()(entry.host) ^ entry.port; | 23 return entry.protocol ^ std::hash<std::string>()(entry.host) ^ entry.port; |
| 24 } | 24 } |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 typedef std::list<std::pair<AlternativeService, base::TimeTicks>> | |
| 28 BrokenAlternativeServiceList; | |
| 29 | |
| 30 typedef std::unordered_map<AlternativeService, | |
| 31 BrokenAlternativeServiceList::iterator, | |
| 32 AlternativeServiceHash> | |
| 33 BrokenAlternativeServiceMap; | |
|
Zhongyi Shi
2017/06/02 18:19:44
Hrm, if I remembered this correctly, the BrokenAlt
wangyix1
2017/06/05 19:16:25
Done.
I don't see it defined in http_server_prope
Zhongyi Shi
2017/06/06 22:17:49
Ah.. I was referring to your previous CL which def
wangyix1
2017/06/09 19:26:41
Hmm, I figured I would keep AlternativeServiceHash
| |
| 34 | |
| 27 // This class tracks HTTP alternative services that have been marked as broken. | 35 // 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 | 36 // 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 | 37 // 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 | 38 // 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 | 39 // delay. This prevents broken alt-svcs from being retried too often by the |
| 32 // network stack. | 40 // network stack. |
| 33 class NET_EXPORT_PRIVATE BrokenAlternativeServices { | 41 class NET_EXPORT_PRIVATE BrokenAlternativeServices { |
| 34 public: | 42 public: |
| 35 // Delegate to be used by owner so it can be notified when the brokenness of | 43 // Delegate to be used by owner so it can be notified when the brokenness of |
| 36 // an AlternativeService expires. | 44 // an AlternativeService expires. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 // Returns true if MarkAlternativeServiceRecentlyBroken(alternative_service) | 86 // Returns true if MarkAlternativeServiceRecentlyBroken(alternative_service) |
| 79 // or MarkAlternativeServiceBroken(alternative_service) has been called and | 87 // or MarkAlternativeServiceBroken(alternative_service) has been called and |
| 80 // ConfirmAlternativeService(alternative_service) has not been called | 88 // ConfirmAlternativeService(alternative_service) has not been called |
| 81 // afterwards (even if brokenness of |alternative_service| has expired). | 89 // afterwards (even if brokenness of |alternative_service| has expired). |
| 82 bool WasAlternativeServiceRecentlyBroken( | 90 bool WasAlternativeServiceRecentlyBroken( |
| 83 const AlternativeService& alternative_service); | 91 const AlternativeService& alternative_service); |
| 84 | 92 |
| 85 // Marks |alternative_service| as not broken and not recently broken. | 93 // Marks |alternative_service| as not broken and not recently broken. |
| 86 void ConfirmAlternativeService(const AlternativeService& alternative_service); | 94 void ConfirmAlternativeService(const AlternativeService& alternative_service); |
| 87 | 95 |
| 96 // Adds broken and recently broken alternative services. | |
| 97 // |broken_alternative_service_list| must be sorted from earliest to latest | |
| 98 // expiration time. | |
| 99 // All AlternativeServices in |broken_alternative_service_list| must exist in | |
| 100 // |recently_broken_alternative_services|. | |
| 101 void AddBrokenAndRecentlyBrokenAlternativeServices( | |
|
Zhongyi Shi
2017/06/02 18:19:44
The return type of this method should be a boolean
wangyix1
2017/06/05 19:16:25
Hmm I didn't think of that. I'm assuming it should
Zhongyi Shi
2017/06/06 22:17:49
If you go a step further, the return type will be
wangyix1
2017/06/09 19:26:41
Acknowledged.
wangyix1
2017/06/10 01:07:17
The current code will only schedule an update to d
wangyix1
2017/06/12 22:28:45
Discussed in person. Will rename this function to
| |
| 102 std::unique_ptr<BrokenAlternativeServiceList> | |
| 103 broken_alternative_service_list, | |
| 104 std::unique_ptr<RecentlyBrokenAlternativeServices> | |
| 105 recently_broken_alternative_services); | |
| 106 | |
| 107 const BrokenAlternativeServiceList& broken_alternative_service_list() const; | |
| 108 | |
| 109 const RecentlyBrokenAlternativeServices& | |
| 110 recently_broken_alternative_services() const; | |
| 111 | |
| 88 private: | 112 private: |
| 89 // TODO (wangyix): modify HttpServerPropertiesImpl unit tests so this | 113 // TODO (wangyix): modify HttpServerPropertiesImpl unit tests so this |
| 90 // friendness is no longer required. | 114 // friendness is no longer required. |
| 91 friend class HttpServerPropertiesImplPeer; | 115 friend class HttpServerPropertiesImplPeer; |
| 92 | 116 |
| 93 // A pair containing a broken AlternativeService and the expiration time of | |
| 94 // its brokenness. | |
| 95 struct BrokenAltSvcExpireInfo { | |
| 96 BrokenAltSvcExpireInfo(const AlternativeService& alt_svc, | |
| 97 base::TimeTicks expire) | |
| 98 : alternative_service(alt_svc), expiration(expire) {} | |
| 99 | |
| 100 AlternativeService alternative_service; | |
| 101 base::TimeTicks expiration; | |
| 102 }; | |
| 103 | |
| 104 typedef std::list<BrokenAltSvcExpireInfo> BrokenAlternativeServiceList; | |
| 105 | |
| 106 typedef std::unordered_map<AlternativeService, | |
| 107 BrokenAlternativeServiceList::iterator, | |
| 108 AlternativeServiceHash> | |
| 109 BrokenAlternativeServiceMap; | |
| 110 | |
| 111 // Inserts |alternative_service| and its |expiration| time into | 117 // Inserts |alternative_service| and its |expiration| time into |
| 112 // |broken_alternative_service_list_| and |broken_alternative_service_map_|. | 118 // |broken_alternative_service_list_| and |broken_alternative_service_map_|. |
| 113 // |it| is the position in |broken_alternative_service_list_| where it was | 119 // |it| is the position in |broken_alternative_service_list_| where it was |
| 114 // inserted. | 120 // inserted. |
| 115 bool AddToBrokenAlternativeServiceListAndMap( | 121 bool AddToBrokenAlternativeServiceListAndMap( |
| 116 const AlternativeService& alternative_service, | 122 const AlternativeService& alternative_service, |
| 117 base::TimeTicks expiration, | 123 base::TimeTicks expiration, |
| 118 BrokenAlternativeServiceList::iterator* it); | 124 BrokenAlternativeServiceList::iterator* it); |
| 119 | 125 |
| 120 void ExpireBrokenAlternateProtocolMappings(); | 126 void ExpireBrokenAlternateProtocolMappings(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 136 // Used for scheduling the task that expires the brokenness of alternative | 142 // Used for scheduling the task that expires the brokenness of alternative |
| 137 // services. | 143 // services. |
| 138 base::OneShotTimer expiration_timer_; | 144 base::OneShotTimer expiration_timer_; |
| 139 | 145 |
| 140 base::WeakPtrFactory<BrokenAlternativeServices> weak_ptr_factory_; | 146 base::WeakPtrFactory<BrokenAlternativeServices> weak_ptr_factory_; |
| 141 }; | 147 }; |
| 142 | 148 |
| 143 } // namespace net | 149 } // namespace net |
| 144 | 150 |
| 145 #endif // NET_HTTP_BROKEN_ALTERNATIVE_SERVICES_H_ | 151 #endif // NET_HTTP_BROKEN_ALTERNATIVE_SERVICES_H_ |
| OLD | NEW |