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