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

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

Issue 2932953002: Persist broken and recently-broken alt-svcs to prefs in HttpServerPropertiesManager (Closed)
Patch Set: Fixed rch's comments from PS14 Created 3 years, 5 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 #include "net/http/broken_alternative_services.h" 5 #include "net/http/broken_alternative_services.h"
6 6
7 #include "base/memory/singleton.h" 7 #include "base/memory/singleton.h"
8 #include "base/time/tick_clock.h" 8 #include "base/time/tick_clock.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "net/http/http_server_properties_impl.h" 10 #include "net/http/http_server_properties_impl.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 broken_alternative_service_list_.erase(map_it->second); 107 broken_alternative_service_list_.erase(map_it->second);
108 broken_alternative_service_map_.erase(map_it); 108 broken_alternative_service_map_.erase(map_it);
109 } 109 }
110 110
111 auto it = recently_broken_alternative_services_.Get(alternative_service); 111 auto it = recently_broken_alternative_services_.Get(alternative_service);
112 if (it != recently_broken_alternative_services_.end()) { 112 if (it != recently_broken_alternative_services_.end()) {
113 recently_broken_alternative_services_.Erase(it); 113 recently_broken_alternative_services_.Erase(it);
114 } 114 }
115 } 115 }
116 116
117 const BrokenAlternativeServiceList&
118 BrokenAlternativeServices::broken_alternative_service_list() const {
119 return broken_alternative_service_list_;
120 }
121
122 const RecentlyBrokenAlternativeServices&
123 BrokenAlternativeServices::recently_broken_alternative_services() const {
124 return recently_broken_alternative_services_;
125 }
126
127 void BrokenAlternativeServices::SetBrokenAndRecentlyBrokenAlternativeServices( 117 void BrokenAlternativeServices::SetBrokenAndRecentlyBrokenAlternativeServices(
128 std::unique_ptr<BrokenAlternativeServiceList> 118 std::unique_ptr<BrokenAlternativeServiceList>
129 broken_alternative_service_list, 119 broken_alternative_service_list,
130 std::unique_ptr<RecentlyBrokenAlternativeServices> 120 std::unique_ptr<RecentlyBrokenAlternativeServices>
131 recently_broken_alternative_services) { 121 recently_broken_alternative_services) {
132 DCHECK(broken_alternative_service_list); 122 DCHECK(broken_alternative_service_list);
133 DCHECK(recently_broken_alternative_services); 123 DCHECK(recently_broken_alternative_services);
134 124
135 // Make sure all alt svcs in |broken_alternative_service_list| has an entry 125 // Make sure all alt svcs in |broken_alternative_service_list| has an entry
136 // in |recently_broken_alternative_services| 126 // in |recently_broken_alternative_services|
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 auto map_it = broken_alternative_service_map_.find(alternative_service); 160 auto map_it = broken_alternative_service_map_.find(alternative_service);
171 if (map_it != broken_alternative_service_map_.end()) { 161 if (map_it != broken_alternative_service_map_.end()) {
172 broken_alternative_service_list_.erase(map_it->second); 162 broken_alternative_service_list_.erase(map_it->second);
173 map_it->second = it; 163 map_it->second = it;
174 } else { 164 } else {
175 broken_alternative_service_map_.insert( 165 broken_alternative_service_map_.insert(
176 std::make_pair(alternative_service, it)); 166 std::make_pair(alternative_service, it));
177 } 167 }
178 } 168 }
179 169
180 // Merge |broken_alternative_service_list| with 170 // Append |broken_alternative_service_list| to
181 // |broken_alternative_service_list_|. Both should already be sorted by 171 // |broken_alternative_service_list_|, then sort the resulting list.
182 // expiration time. std::list::merge() will not invalidate any iterators 172 // Neither operations will invalidate any iterators of either list,
183 // of either list, so all iterators in |broken_alternative_service_map_| 173 // so all iterators in |broken_alternative_service_map_| remain valid.
184 // remain valid. 174 broken_alternative_service_list_.splice(
185 broken_alternative_service_list_.merge( 175 broken_alternative_service_list_.end(), *broken_alternative_service_list);
186 *broken_alternative_service_list, 176
177 broken_alternative_service_list_.sort(
187 [](const std::pair<AlternativeService, base::TimeTicks>& lhs, 178 [](const std::pair<AlternativeService, base::TimeTicks>& lhs,
188 const std::pair<AlternativeService, base::TimeTicks>& rhs) -> bool { 179 const std::pair<AlternativeService, base::TimeTicks>& rhs) -> bool {
189 return lhs.second < rhs.second; 180 return lhs.second < rhs.second;
190 }); 181 });
191 182
192 base::TimeTicks new_next_expiration = 183 base::TimeTicks new_next_expiration =
193 broken_alternative_service_list_.empty() 184 broken_alternative_service_list_.empty()
194 ? base::TimeTicks::Max() 185 ? base::TimeTicks::Max()
195 : broken_alternative_service_list_.front().second; 186 : broken_alternative_service_list_.front().second;
196 187
197 if (new_next_expiration != next_expiration) 188 if (new_next_expiration != next_expiration)
198 ScheduleBrokenAlternateProtocolMappingsExpiration(); 189 ScheduleBrokenAlternateProtocolMappingsExpiration();
199 } 190 }
200 191
192 const BrokenAlternativeServiceList&
193 BrokenAlternativeServices::broken_alternative_service_list() const {
194 return broken_alternative_service_list_;
195 }
196
197 const RecentlyBrokenAlternativeServices&
198 BrokenAlternativeServices::recently_broken_alternative_services() const {
199 return recently_broken_alternative_services_;
200 }
201
201 bool BrokenAlternativeServices::AddToBrokenAlternativeServiceListAndMap( 202 bool BrokenAlternativeServices::AddToBrokenAlternativeServiceListAndMap(
202 const AlternativeService& alternative_service, 203 const AlternativeService& alternative_service,
203 base::TimeTicks expiration, 204 base::TimeTicks expiration,
204 BrokenAlternativeServiceList::iterator* it) { 205 BrokenAlternativeServiceList::iterator* it) {
205 DCHECK(it); 206 DCHECK(it);
206 207
207 auto map_it = broken_alternative_service_map_.find(alternative_service); 208 auto map_it = broken_alternative_service_map_.find(alternative_service);
208 if (map_it != broken_alternative_service_map_.end()) 209 if (map_it != broken_alternative_service_map_.end())
209 return false; 210 return false;
210 211
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); 257 base::TimeDelta delay = when > now ? when - now : base::TimeDelta();
257 expiration_timer_.Stop(); 258 expiration_timer_.Stop();
258 expiration_timer_.Start( 259 expiration_timer_.Start(
259 FROM_HERE, delay, 260 FROM_HERE, delay,
260 base::Bind( 261 base::Bind(
261 &BrokenAlternativeServices ::ExpireBrokenAlternateProtocolMappings, 262 &BrokenAlternativeServices ::ExpireBrokenAlternateProtocolMappings,
262 weak_ptr_factory_.GetWeakPtr())); 263 weak_ptr_factory_.GetWeakPtr()));
263 } 264 }
264 265
265 } // namespace net 266 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698