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/time/default_tick_clock.h" | |
|
Ryan Hamilton
2017/07/06 16:48:22
It looks like a fwd-declare of base::TickClock sho
wangyix1
2017/07/06 18:04:29
Done.
| |
| 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: |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 const AlternativeService& alternative_service); | 74 const AlternativeService& alternative_service); |
| 78 | 75 |
| 79 // Marks |alternative_service| as not broken and not recently broken. | 76 // Marks |alternative_service| as not broken and not recently broken. |
| 80 void ConfirmAlternativeService(const AlternativeService& alternative_service); | 77 void ConfirmAlternativeService(const AlternativeService& alternative_service); |
| 81 | 78 |
| 82 // Sets broken and recently broken alternative services. | 79 // Sets broken and recently broken alternative services. |
| 83 // |broken_alternative_service_list| must be sorted from earliest to latest | 80 // |broken_alternative_service_list| must be sorted from earliest to latest |
| 84 // expiration time. | 81 // expiration time. |
| 85 // All AlternativeServices in |broken_alternative_service_list| must exist in | 82 // All AlternativeServices in |broken_alternative_service_list| must exist in |
| 86 // |recently_broken_alternative_services|. | 83 // |recently_broken_alternative_services|. |
| 84 // | |
| 85 // If a broken/recently-broken alt svc that's being added is already stored, | |
| 86 // the stored expiration/broken-count for that alt svc will be overwritten | |
| 87 // with the new value. | |
| 87 void SetBrokenAndRecentlyBrokenAlternativeServices( | 88 void SetBrokenAndRecentlyBrokenAlternativeServices( |
| 88 std::unique_ptr<BrokenAlternativeServiceList> | 89 std::unique_ptr<BrokenAlternativeServiceList> |
| 89 broken_alternative_service_list, | 90 broken_alternative_service_list, |
| 90 std::unique_ptr<RecentlyBrokenAlternativeServices> | 91 std::unique_ptr<RecentlyBrokenAlternativeServices> |
| 91 recently_broken_alternative_services); | 92 recently_broken_alternative_services); |
| 92 | 93 |
| 93 const BrokenAlternativeServiceList& broken_alternative_service_list() const; | 94 const BrokenAlternativeServiceList& broken_alternative_service_list() const; |
| 94 | 95 |
| 95 const RecentlyBrokenAlternativeServices& | 96 const RecentlyBrokenAlternativeServices& |
| 96 recently_broken_alternative_services() const; | 97 recently_broken_alternative_services() const; |
| 97 | 98 |
| 98 private: | 99 private: |
| 99 // TODO (wangyix): modify HttpServerPropertiesImpl unit tests so this | 100 // TODO (wangyix): modify HttpServerPropertiesImpl unit tests so this |
| 100 // friendness is no longer required. | 101 // friendness is no longer required. |
| 101 friend class HttpServerPropertiesImplPeer; | 102 friend class HttpServerPropertiesImplPeer; |
| 102 | 103 |
| 103 struct AlternativeServiceHash { | |
| 104 size_t operator()(const net::AlternativeService& entry) const { | |
| 105 return entry.protocol ^ std::hash<std::string>()(entry.host) ^ entry.port; | |
| 106 } | |
| 107 }; | |
| 108 | |
| 109 typedef std::unordered_map<AlternativeService, | 104 typedef std::unordered_map<AlternativeService, |
| 110 BrokenAlternativeServiceList::iterator, | 105 BrokenAlternativeServiceList::iterator, |
| 111 AlternativeServiceHash> | 106 AlternativeServiceHash> |
| 112 BrokenAlternativeServiceMap; | 107 BrokenAlternativeServiceMap; |
| 113 | 108 |
| 114 // Inserts |alternative_service| and its |expiration| time into | 109 // Inserts |alternative_service| and its |expiration| time into |
| 115 // |broken_alternative_service_list_| and |broken_alternative_service_map_|. | 110 // |broken_alternative_service_list_| and |broken_alternative_service_map_|. |
| 116 // |it| is the position in |broken_alternative_service_list_| where it was | 111 // |it| is the position in |broken_alternative_service_list_| where it was |
| 117 // inserted. | 112 // inserted. |
| 118 bool AddToBrokenAlternativeServiceListAndMap( | 113 bool AddToBrokenAlternativeServiceListAndMap( |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 139 // Used for scheduling the task that expires the brokenness of alternative | 134 // Used for scheduling the task that expires the brokenness of alternative |
| 140 // services. | 135 // services. |
| 141 base::OneShotTimer expiration_timer_; | 136 base::OneShotTimer expiration_timer_; |
| 142 | 137 |
| 143 base::WeakPtrFactory<BrokenAlternativeServices> weak_ptr_factory_; | 138 base::WeakPtrFactory<BrokenAlternativeServices> weak_ptr_factory_; |
| 144 }; | 139 }; |
| 145 | 140 |
| 146 } // namespace net | 141 } // namespace net |
| 147 | 142 |
| 148 #endif // NET_HTTP_BROKEN_ALTERNATIVE_SERVICES_H_ | 143 #endif // NET_HTTP_BROKEN_ALTERNATIVE_SERVICES_H_ |
| OLD | NEW |