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

Side by Side Diff: chrome/browser/net/http_server_properties_manager.cc

Issue 377063002: Revert of Add a probability to Alternate-Protocol support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/net/http_server_properties_manager.h" 5 #include "chrome/browser/net/http_server_properties_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 } // namespace 59 } // namespace
60 60
61 //////////////////////////////////////////////////////////////////////////////// 61 ////////////////////////////////////////////////////////////////////////////////
62 // HttpServerPropertiesManager 62 // HttpServerPropertiesManager
63 63
64 HttpServerPropertiesManager::HttpServerPropertiesManager( 64 HttpServerPropertiesManager::HttpServerPropertiesManager(
65 PrefService* pref_service) 65 PrefService* pref_service)
66 : pref_service_(pref_service), 66 : pref_service_(pref_service),
67 setting_prefs_(false) { 67 setting_prefs_(false) {
68 DCHECK_CURRENTLY_ON(BrowserThread::UI); 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
69 DCHECK(pref_service); 69 DCHECK(pref_service);
70 ui_weak_ptr_factory_.reset( 70 ui_weak_ptr_factory_.reset(
71 new base::WeakPtrFactory<HttpServerPropertiesManager>(this)); 71 new base::WeakPtrFactory<HttpServerPropertiesManager>(this));
72 ui_weak_ptr_ = ui_weak_ptr_factory_->GetWeakPtr(); 72 ui_weak_ptr_ = ui_weak_ptr_factory_->GetWeakPtr();
73 ui_cache_update_timer_.reset( 73 ui_cache_update_timer_.reset(
74 new base::OneShotTimer<HttpServerPropertiesManager>); 74 new base::OneShotTimer<HttpServerPropertiesManager>);
75 pref_change_registrar_.Init(pref_service_); 75 pref_change_registrar_.Init(pref_service_);
76 pref_change_registrar_.Add( 76 pref_change_registrar_.Add(
77 prefs::kHttpServerProperties, 77 prefs::kHttpServerProperties,
78 base::Bind(&HttpServerPropertiesManager::OnHttpServerPropertiesChanged, 78 base::Bind(&HttpServerPropertiesManager::OnHttpServerPropertiesChanged,
79 base::Unretained(this))); 79 base::Unretained(this)));
80 } 80 }
81 81
82 HttpServerPropertiesManager::~HttpServerPropertiesManager() { 82 HttpServerPropertiesManager::~HttpServerPropertiesManager() {
83 DCHECK_CURRENTLY_ON(BrowserThread::IO); 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
84 io_weak_ptr_factory_.reset(); 84 io_weak_ptr_factory_.reset();
85 } 85 }
86 86
87 void HttpServerPropertiesManager::InitializeOnIOThread() { 87 void HttpServerPropertiesManager::InitializeOnIOThread() {
88 DCHECK_CURRENTLY_ON(BrowserThread::IO); 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
89 io_weak_ptr_factory_.reset( 89 io_weak_ptr_factory_.reset(
90 new base::WeakPtrFactory<HttpServerPropertiesManager>(this)); 90 new base::WeakPtrFactory<HttpServerPropertiesManager>(this));
91 http_server_properties_impl_.reset(new net::HttpServerPropertiesImpl()); 91 http_server_properties_impl_.reset(new net::HttpServerPropertiesImpl());
92 92
93 io_prefs_update_timer_.reset( 93 io_prefs_update_timer_.reset(
94 new base::OneShotTimer<HttpServerPropertiesManager>); 94 new base::OneShotTimer<HttpServerPropertiesManager>);
95 95
96 BrowserThread::PostTask( 96 BrowserThread::PostTask(
97 BrowserThread::UI, 97 BrowserThread::UI,
98 FROM_HERE, 98 FROM_HERE,
99 base::Bind(&HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI, 99 base::Bind(&HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI,
100 ui_weak_ptr_)); 100 ui_weak_ptr_));
101 } 101 }
102 102
103 void HttpServerPropertiesManager::ShutdownOnUIThread() { 103 void HttpServerPropertiesManager::ShutdownOnUIThread() {
104 DCHECK_CURRENTLY_ON(BrowserThread::UI); 104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
105 // Cancel any pending updates, and stop listening for pref change updates. 105 // Cancel any pending updates, and stop listening for pref change updates.
106 ui_cache_update_timer_->Stop(); 106 ui_cache_update_timer_->Stop();
107 ui_weak_ptr_factory_.reset(); 107 ui_weak_ptr_factory_.reset();
108 pref_change_registrar_.RemoveAll(); 108 pref_change_registrar_.RemoveAll();
109 } 109 }
110 110
111 // static 111 // static
112 void HttpServerPropertiesManager::RegisterProfilePrefs( 112 void HttpServerPropertiesManager::RegisterProfilePrefs(
113 user_prefs::PrefRegistrySyncable* prefs) { 113 user_prefs::PrefRegistrySyncable* prefs) {
114 prefs->RegisterDictionaryPref( 114 prefs->RegisterDictionaryPref(
115 prefs::kHttpServerProperties, 115 prefs::kHttpServerProperties,
116 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 116 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
117 } 117 }
118 118
119 // static 119 // static
120 void HttpServerPropertiesManager::SetVersion( 120 void HttpServerPropertiesManager::SetVersion(
121 base::DictionaryValue* http_server_properties_dict, 121 base::DictionaryValue* http_server_properties_dict,
122 int version_number) { 122 int version_number) {
123 if (version_number < 0) 123 if (version_number < 0)
124 version_number = kVersionNumber; 124 version_number = kVersionNumber;
125 DCHECK_LE(version_number, kVersionNumber); 125 DCHECK_LE(version_number, kVersionNumber);
126 if (version_number <= kVersionNumber) 126 if (version_number <= kVersionNumber)
127 http_server_properties_dict->SetInteger("version", version_number); 127 http_server_properties_dict->SetInteger("version", version_number);
128 } 128 }
129 129
130 // This is required for conformance with the HttpServerProperties interface. 130 // This is required for conformance with the HttpServerProperties interface.
131 base::WeakPtr<net::HttpServerProperties> 131 base::WeakPtr<net::HttpServerProperties>
132 HttpServerPropertiesManager::GetWeakPtr() { 132 HttpServerPropertiesManager::GetWeakPtr() {
133 DCHECK_CURRENTLY_ON(BrowserThread::IO); 133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
134 return io_weak_ptr_factory_->GetWeakPtr(); 134 return io_weak_ptr_factory_->GetWeakPtr();
135 } 135 }
136 136
137 void HttpServerPropertiesManager::Clear() { 137 void HttpServerPropertiesManager::Clear() {
138 Clear(base::Closure()); 138 Clear(base::Closure());
139 } 139 }
140 140
141 void HttpServerPropertiesManager::Clear(const base::Closure& completion) { 141 void HttpServerPropertiesManager::Clear(const base::Closure& completion) {
142 DCHECK_CURRENTLY_ON(BrowserThread::IO); 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
143 143
144 http_server_properties_impl_->Clear(); 144 http_server_properties_impl_->Clear();
145 UpdatePrefsFromCacheOnIO(completion); 145 UpdatePrefsFromCacheOnIO(completion);
146 } 146 }
147 147
148 bool HttpServerPropertiesManager::SupportsSpdy( 148 bool HttpServerPropertiesManager::SupportsSpdy(
149 const net::HostPortPair& server) { 149 const net::HostPortPair& server) {
150 DCHECK_CURRENTLY_ON(BrowserThread::IO); 150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
151 return http_server_properties_impl_->SupportsSpdy(server); 151 return http_server_properties_impl_->SupportsSpdy(server);
152 } 152 }
153 153
154 void HttpServerPropertiesManager::SetSupportsSpdy( 154 void HttpServerPropertiesManager::SetSupportsSpdy(
155 const net::HostPortPair& server, 155 const net::HostPortPair& server,
156 bool support_spdy) { 156 bool support_spdy) {
157 DCHECK_CURRENTLY_ON(BrowserThread::IO); 157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
158 158
159 http_server_properties_impl_->SetSupportsSpdy(server, support_spdy); 159 http_server_properties_impl_->SetSupportsSpdy(server, support_spdy);
160 ScheduleUpdatePrefsOnIO(); 160 ScheduleUpdatePrefsOnIO();
161 } 161 }
162 162
163 bool HttpServerPropertiesManager::HasAlternateProtocol( 163 bool HttpServerPropertiesManager::HasAlternateProtocol(
164 const net::HostPortPair& server) { 164 const net::HostPortPair& server) {
165 DCHECK_CURRENTLY_ON(BrowserThread::IO); 165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
166 return http_server_properties_impl_->HasAlternateProtocol(server); 166 return http_server_properties_impl_->HasAlternateProtocol(server);
167 } 167 }
168 168
169 net::AlternateProtocolInfo 169 net::PortAlternateProtocolPair
170 HttpServerPropertiesManager::GetAlternateProtocol( 170 HttpServerPropertiesManager::GetAlternateProtocol(
171 const net::HostPortPair& server) { 171 const net::HostPortPair& server) {
172 DCHECK_CURRENTLY_ON(BrowserThread::IO); 172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
173 return http_server_properties_impl_->GetAlternateProtocol(server); 173 return http_server_properties_impl_->GetAlternateProtocol(server);
174 } 174 }
175 175
176 void HttpServerPropertiesManager::SetAlternateProtocol( 176 void HttpServerPropertiesManager::SetAlternateProtocol(
177 const net::HostPortPair& server, 177 const net::HostPortPair& server,
178 uint16 alternate_port, 178 uint16 alternate_port,
179 net::AlternateProtocol alternate_protocol, 179 net::AlternateProtocol alternate_protocol) {
180 double alternate_probability) { 180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
181 DCHECK_CURRENTLY_ON(BrowserThread::IO);
182 http_server_properties_impl_->SetAlternateProtocol( 181 http_server_properties_impl_->SetAlternateProtocol(
183 server, alternate_port, alternate_protocol, alternate_probability); 182 server, alternate_port, alternate_protocol);
184 ScheduleUpdatePrefsOnIO(); 183 ScheduleUpdatePrefsOnIO();
185 } 184 }
186 185
187 void HttpServerPropertiesManager::SetBrokenAlternateProtocol( 186 void HttpServerPropertiesManager::SetBrokenAlternateProtocol(
188 const net::HostPortPair& server) { 187 const net::HostPortPair& server) {
189 DCHECK_CURRENTLY_ON(BrowserThread::IO); 188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
190 http_server_properties_impl_->SetBrokenAlternateProtocol(server); 189 http_server_properties_impl_->SetBrokenAlternateProtocol(server);
191 ScheduleUpdatePrefsOnIO(); 190 ScheduleUpdatePrefsOnIO();
192 } 191 }
193 192
194 bool HttpServerPropertiesManager::WasAlternateProtocolRecentlyBroken( 193 bool HttpServerPropertiesManager::WasAlternateProtocolRecentlyBroken(
195 const net::HostPortPair& server) { 194 const net::HostPortPair& server) {
196 DCHECK_CURRENTLY_ON(BrowserThread::IO); 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
197 return http_server_properties_impl_->WasAlternateProtocolRecentlyBroken( 196 return http_server_properties_impl_->WasAlternateProtocolRecentlyBroken(
198 server); 197 server);
199 } 198 }
200 199
201 void HttpServerPropertiesManager::ConfirmAlternateProtocol( 200 void HttpServerPropertiesManager::ConfirmAlternateProtocol(
202 const net::HostPortPair& server) { 201 const net::HostPortPair& server) {
203 DCHECK_CURRENTLY_ON(BrowserThread::IO); 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
204 http_server_properties_impl_->ConfirmAlternateProtocol(server); 203 http_server_properties_impl_->ConfirmAlternateProtocol(server);
205 ScheduleUpdatePrefsOnIO(); 204 ScheduleUpdatePrefsOnIO();
206 } 205 }
207 206
208 void HttpServerPropertiesManager::ClearAlternateProtocol( 207 void HttpServerPropertiesManager::ClearAlternateProtocol(
209 const net::HostPortPair& server) { 208 const net::HostPortPair& server) {
210 DCHECK_CURRENTLY_ON(BrowserThread::IO); 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
211 http_server_properties_impl_->ClearAlternateProtocol(server); 210 http_server_properties_impl_->ClearAlternateProtocol(server);
212 ScheduleUpdatePrefsOnIO(); 211 ScheduleUpdatePrefsOnIO();
213 } 212 }
214 213
215 const net::AlternateProtocolMap& 214 const net::AlternateProtocolMap&
216 HttpServerPropertiesManager::alternate_protocol_map() const { 215 HttpServerPropertiesManager::alternate_protocol_map() const {
217 DCHECK_CURRENTLY_ON(BrowserThread::IO); 216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
218 return http_server_properties_impl_->alternate_protocol_map(); 217 return http_server_properties_impl_->alternate_protocol_map();
219 } 218 }
220 219
221 void HttpServerPropertiesManager::SetAlternateProtocolExperiment( 220 void HttpServerPropertiesManager::SetAlternateProtocolExperiment(
222 net::AlternateProtocolExperiment experiment) { 221 net::AlternateProtocolExperiment experiment) {
223 DCHECK_CURRENTLY_ON(BrowserThread::IO);
224 http_server_properties_impl_->SetAlternateProtocolExperiment(experiment); 222 http_server_properties_impl_->SetAlternateProtocolExperiment(experiment);
225 } 223 }
226 224
227 void HttpServerPropertiesManager::SetAlternateProtocolProbabilityThreshold(
228 double threshold) {
229 DCHECK_CURRENTLY_ON(BrowserThread::IO);
230 http_server_properties_impl_->SetAlternateProtocolProbabilityThreshold(
231 threshold);
232 }
233
234 net::AlternateProtocolExperiment 225 net::AlternateProtocolExperiment
235 HttpServerPropertiesManager::GetAlternateProtocolExperiment() const { 226 HttpServerPropertiesManager::GetAlternateProtocolExperiment() const {
236 DCHECK_CURRENTLY_ON(BrowserThread::IO);
237 return http_server_properties_impl_->GetAlternateProtocolExperiment(); 227 return http_server_properties_impl_->GetAlternateProtocolExperiment();
238 } 228 }
239 229
240 const net::SettingsMap& 230 const net::SettingsMap&
241 HttpServerPropertiesManager::GetSpdySettings( 231 HttpServerPropertiesManager::GetSpdySettings(
242 const net::HostPortPair& host_port_pair) { 232 const net::HostPortPair& host_port_pair) {
243 DCHECK_CURRENTLY_ON(BrowserThread::IO); 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
244 return http_server_properties_impl_->GetSpdySettings(host_port_pair); 234 return http_server_properties_impl_->GetSpdySettings(host_port_pair);
245 } 235 }
246 236
247 bool HttpServerPropertiesManager::SetSpdySetting( 237 bool HttpServerPropertiesManager::SetSpdySetting(
248 const net::HostPortPair& host_port_pair, 238 const net::HostPortPair& host_port_pair,
249 net::SpdySettingsIds id, 239 net::SpdySettingsIds id,
250 net::SpdySettingsFlags flags, 240 net::SpdySettingsFlags flags,
251 uint32 value) { 241 uint32 value) {
252 DCHECK_CURRENTLY_ON(BrowserThread::IO); 242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
253 bool persist = http_server_properties_impl_->SetSpdySetting( 243 bool persist = http_server_properties_impl_->SetSpdySetting(
254 host_port_pair, id, flags, value); 244 host_port_pair, id, flags, value);
255 if (persist) 245 if (persist)
256 ScheduleUpdatePrefsOnIO(); 246 ScheduleUpdatePrefsOnIO();
257 return persist; 247 return persist;
258 } 248 }
259 249
260 void HttpServerPropertiesManager::ClearSpdySettings( 250 void HttpServerPropertiesManager::ClearSpdySettings(
261 const net::HostPortPair& host_port_pair) { 251 const net::HostPortPair& host_port_pair) {
262 DCHECK_CURRENTLY_ON(BrowserThread::IO); 252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
263 http_server_properties_impl_->ClearSpdySettings(host_port_pair); 253 http_server_properties_impl_->ClearSpdySettings(host_port_pair);
264 ScheduleUpdatePrefsOnIO(); 254 ScheduleUpdatePrefsOnIO();
265 } 255 }
266 256
267 void HttpServerPropertiesManager::ClearAllSpdySettings() { 257 void HttpServerPropertiesManager::ClearAllSpdySettings() {
268 DCHECK_CURRENTLY_ON(BrowserThread::IO); 258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
269 http_server_properties_impl_->ClearAllSpdySettings(); 259 http_server_properties_impl_->ClearAllSpdySettings();
270 ScheduleUpdatePrefsOnIO(); 260 ScheduleUpdatePrefsOnIO();
271 } 261 }
272 262
273 const net::SpdySettingsMap& 263 const net::SpdySettingsMap&
274 HttpServerPropertiesManager::spdy_settings_map() const { 264 HttpServerPropertiesManager::spdy_settings_map() const {
275 DCHECK_CURRENTLY_ON(BrowserThread::IO); 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
276 return http_server_properties_impl_->spdy_settings_map(); 266 return http_server_properties_impl_->spdy_settings_map();
277 } 267 }
278 268
279 void HttpServerPropertiesManager::SetServerNetworkStats( 269 void HttpServerPropertiesManager::SetServerNetworkStats(
280 const net::HostPortPair& host_port_pair, 270 const net::HostPortPair& host_port_pair,
281 NetworkStats stats) { 271 NetworkStats stats) {
282 DCHECK_CURRENTLY_ON(BrowserThread::IO); 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
283 http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats); 273 http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats);
284 } 274 }
285 275
286 const HttpServerPropertiesManager::NetworkStats* 276 const HttpServerPropertiesManager::NetworkStats*
287 HttpServerPropertiesManager::GetServerNetworkStats( 277 HttpServerPropertiesManager::GetServerNetworkStats(
288 const net::HostPortPair& host_port_pair) const { 278 const net::HostPortPair& host_port_pair) const {
289 DCHECK_CURRENTLY_ON(BrowserThread::IO); 279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
290 return http_server_properties_impl_->GetServerNetworkStats(host_port_pair); 280 return http_server_properties_impl_->GetServerNetworkStats(host_port_pair);
291 } 281 }
292 282
293 // 283 //
294 // Update the HttpServerPropertiesImpl's cache with data from preferences. 284 // Update the HttpServerPropertiesImpl's cache with data from preferences.
295 // 285 //
296 void HttpServerPropertiesManager::ScheduleUpdateCacheOnUI() { 286 void HttpServerPropertiesManager::ScheduleUpdateCacheOnUI() {
297 DCHECK_CURRENTLY_ON(BrowserThread::UI); 287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
298 // Cancel pending updates, if any. 288 // Cancel pending updates, if any.
299 ui_cache_update_timer_->Stop(); 289 ui_cache_update_timer_->Stop();
300 StartCacheUpdateTimerOnUI( 290 StartCacheUpdateTimerOnUI(
301 base::TimeDelta::FromMilliseconds(kUpdateCacheDelayMs)); 291 base::TimeDelta::FromMilliseconds(kUpdateCacheDelayMs));
302 } 292 }
303 293
304 void HttpServerPropertiesManager::StartCacheUpdateTimerOnUI( 294 void HttpServerPropertiesManager::StartCacheUpdateTimerOnUI(
305 base::TimeDelta delay) { 295 base::TimeDelta delay) {
306 DCHECK_CURRENTLY_ON(BrowserThread::UI); 296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
307 ui_cache_update_timer_->Start( 297 ui_cache_update_timer_->Start(
308 FROM_HERE, delay, this, 298 FROM_HERE, delay, this,
309 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI); 299 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI);
310 } 300 }
311 301
312 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI() { 302 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI() {
313 // The preferences can only be read on the UI thread. 303 // The preferences can only be read on the UI thread.
314 DCHECK_CURRENTLY_ON(BrowserThread::UI); 304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
315 305
316 if (!pref_service_->HasPrefPath(prefs::kHttpServerProperties)) 306 if (!pref_service_->HasPrefPath(prefs::kHttpServerProperties))
317 return; 307 return;
318 308
319 bool detected_corrupted_prefs = false; 309 bool detected_corrupted_prefs = false;
320 const base::DictionaryValue& http_server_properties_dict = 310 const base::DictionaryValue& http_server_properties_dict =
321 *pref_service_->GetDictionary(prefs::kHttpServerProperties); 311 *pref_service_->GetDictionary(prefs::kHttpServerProperties);
322 312
323 int version = kMissingVersion; 313 int version = kMissingVersion;
324 if (!http_server_properties_dict.GetIntegerWithoutPathExpansion( 314 if (!http_server_properties_dict.GetIntegerWithoutPathExpansion(
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 continue; 432 continue;
443 } 433 }
444 net::AlternateProtocol protocol = 434 net::AlternateProtocol protocol =
445 net::AlternateProtocolFromString(protocol_str); 435 net::AlternateProtocolFromString(protocol_str);
446 if (!net::IsAlternateProtocolValid(protocol)) { 436 if (!net::IsAlternateProtocolValid(protocol)) {
447 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; 437 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str;
448 detected_corrupted_prefs = true; 438 detected_corrupted_prefs = true;
449 continue; 439 continue;
450 } 440 }
451 441
452 double probability = 1; 442 net::PortAlternateProtocolPair port_alternate_protocol;
453 if (port_alternate_protocol_dict->HasKey("probability") && 443 port_alternate_protocol.port = port;
454 !port_alternate_protocol_dict->GetDoubleWithoutPathExpansion( 444 port_alternate_protocol.protocol = protocol;
455 "probability", &probability)) {
456 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str;
457 detected_corrupted_prefs = true;
458 continue;
459 }
460 445
461 net::AlternateProtocolInfo port_alternate_protocol(port,
462 protocol,
463 probability);
464 alternate_protocol_map->Put(server, port_alternate_protocol); 446 alternate_protocol_map->Put(server, port_alternate_protocol);
465 ++count; 447 ++count;
466 } while (false); 448 } while (false);
467 } 449 }
468 450
469 BrowserThread::PostTask( 451 BrowserThread::PostTask(
470 BrowserThread::IO, 452 BrowserThread::IO,
471 FROM_HERE, 453 FROM_HERE,
472 base::Bind(&HttpServerPropertiesManager:: 454 base::Bind(&HttpServerPropertiesManager::
473 UpdateCacheFromPrefsOnIO, 455 UpdateCacheFromPrefsOnIO,
474 base::Unretained(this), 456 base::Unretained(this),
475 base::Owned(spdy_servers.release()), 457 base::Owned(spdy_servers.release()),
476 base::Owned(spdy_settings_map.release()), 458 base::Owned(spdy_settings_map.release()),
477 base::Owned(alternate_protocol_map.release()), 459 base::Owned(alternate_protocol_map.release()),
478 alternate_protocol_experiment, 460 alternate_protocol_experiment,
479 detected_corrupted_prefs)); 461 detected_corrupted_prefs));
480 } 462 }
481 463
482 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnIO( 464 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnIO(
483 StringVector* spdy_servers, 465 StringVector* spdy_servers,
484 net::SpdySettingsMap* spdy_settings_map, 466 net::SpdySettingsMap* spdy_settings_map,
485 net::AlternateProtocolMap* alternate_protocol_map, 467 net::AlternateProtocolMap* alternate_protocol_map,
486 net::AlternateProtocolExperiment alternate_protocol_experiment, 468 net::AlternateProtocolExperiment alternate_protocol_experiment,
487 bool detected_corrupted_prefs) { 469 bool detected_corrupted_prefs) {
488 // Preferences have the master data because admins might have pushed new 470 // Preferences have the master data because admins might have pushed new
489 // preferences. Update the cached data with new data from preferences. 471 // preferences. Update the cached data with new data from preferences.
490 DCHECK_CURRENTLY_ON(BrowserThread::IO); 472 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
491 473
492 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); 474 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size());
493 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); 475 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true);
494 476
495 // Update the cached data and use the new spdy_settings from preferences. 477 // Update the cached data and use the new spdy_settings from preferences.
496 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size()); 478 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size());
497 http_server_properties_impl_->InitializeSpdySettingsServers( 479 http_server_properties_impl_->InitializeSpdySettingsServers(
498 spdy_settings_map); 480 spdy_settings_map);
499 481
500 // Update the cached data and use the new Alternate-Protocol server list from 482 // Update the cached data and use the new Alternate-Protocol server list from
501 // preferences. 483 // preferences.
502 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", 484 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers",
503 alternate_protocol_map->size()); 485 alternate_protocol_map->size());
504 http_server_properties_impl_->InitializeAlternateProtocolServers( 486 http_server_properties_impl_->InitializeAlternateProtocolServers(
505 alternate_protocol_map); 487 alternate_protocol_map);
506 http_server_properties_impl_->SetAlternateProtocolExperiment( 488 http_server_properties_impl_->SetAlternateProtocolExperiment(
507 alternate_protocol_experiment); 489 alternate_protocol_experiment);
508 490
509 // Update the prefs with what we have read (delete all corrupted prefs). 491 // Update the prefs with what we have read (delete all corrupted prefs).
510 if (detected_corrupted_prefs) 492 if (detected_corrupted_prefs)
511 ScheduleUpdatePrefsOnIO(); 493 ScheduleUpdatePrefsOnIO();
512 } 494 }
513 495
514 496
515 // 497 //
516 // Update Preferences with data from the cached data. 498 // Update Preferences with data from the cached data.
517 // 499 //
518 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnIO() { 500 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnIO() {
519 DCHECK_CURRENTLY_ON(BrowserThread::IO); 501 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
520 // Cancel pending updates, if any. 502 // Cancel pending updates, if any.
521 io_prefs_update_timer_->Stop(); 503 io_prefs_update_timer_->Stop();
522 StartPrefsUpdateTimerOnIO( 504 StartPrefsUpdateTimerOnIO(
523 base::TimeDelta::FromMilliseconds(kUpdatePrefsDelayMs)); 505 base::TimeDelta::FromMilliseconds(kUpdatePrefsDelayMs));
524 } 506 }
525 507
526 void HttpServerPropertiesManager::StartPrefsUpdateTimerOnIO( 508 void HttpServerPropertiesManager::StartPrefsUpdateTimerOnIO(
527 base::TimeDelta delay) { 509 base::TimeDelta delay) {
528 DCHECK_CURRENTLY_ON(BrowserThread::IO); 510 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
529 // This is overridden in tests to post the task without the delay. 511 // This is overridden in tests to post the task without the delay.
530 io_prefs_update_timer_->Start( 512 io_prefs_update_timer_->Start(
531 FROM_HERE, delay, this, 513 FROM_HERE, delay, this,
532 &HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO); 514 &HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO);
533 } 515 }
534 516
535 // This is required so we can set this as the callback for a timer. 517 // This is required so we can set this as the callback for a timer.
536 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO() { 518 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO() {
537 UpdatePrefsFromCacheOnIO(base::Closure()); 519 UpdatePrefsFromCacheOnIO(base::Closure());
538 } 520 }
539 521
540 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO( 522 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO(
541 const base::Closure& completion) { 523 const base::Closure& completion) {
542 DCHECK_CURRENTLY_ON(BrowserThread::IO); 524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
543 525
544 base::ListValue* spdy_server_list = new base::ListValue; 526 base::ListValue* spdy_server_list = new base::ListValue;
545 http_server_properties_impl_->GetSpdyServerList( 527 http_server_properties_impl_->GetSpdyServerList(
546 spdy_server_list, kMaxSupportsSpdyServerHostsToPersist); 528 spdy_server_list, kMaxSupportsSpdyServerHostsToPersist);
547 529
548 net::SpdySettingsMap* spdy_settings_map = 530 net::SpdySettingsMap* spdy_settings_map =
549 new net::SpdySettingsMap(kMaxSpdySettingsHostsToPersist); 531 new net::SpdySettingsMap(kMaxSpdySettingsHostsToPersist);
550 const net::SpdySettingsMap& main_map = 532 const net::SpdySettingsMap& main_map =
551 http_server_properties_impl_->spdy_settings_map(); 533 http_server_properties_impl_->spdy_settings_map();
552 int count = 0; 534 int count = 0;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 FROM_HERE, 566 FROM_HERE,
585 base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnUI, 567 base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnUI,
586 ui_weak_ptr_, 568 ui_weak_ptr_,
587 base::Owned(spdy_server_list), 569 base::Owned(spdy_server_list),
588 base::Owned(spdy_settings_map), 570 base::Owned(spdy_settings_map),
589 base::Owned(alternate_protocol_map), 571 base::Owned(alternate_protocol_map),
590 completion)); 572 completion));
591 } 573 }
592 574
593 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, 575 // A local or temporary data structure to hold |supports_spdy|, SpdySettings,
594 // and AlternateProtocolInfo preferences for a server. This is used only in 576 // and PortAlternateProtocolPair preferences for a server. This is used only in
595 // UpdatePrefsOnUI. 577 // UpdatePrefsOnUI.
596 struct ServerPref { 578 struct ServerPref {
597 ServerPref() 579 ServerPref()
598 : supports_spdy(false), 580 : supports_spdy(false),
599 settings_map(NULL), 581 settings_map(NULL),
600 alternate_protocol(NULL) { 582 alternate_protocol(NULL) {
601 } 583 }
602 ServerPref(bool supports_spdy, 584 ServerPref(bool supports_spdy,
603 const net::SettingsMap* settings_map, 585 const net::SettingsMap* settings_map,
604 const net::AlternateProtocolInfo* alternate_protocol) 586 const net::PortAlternateProtocolPair* alternate_protocol)
605 : supports_spdy(supports_spdy), 587 : supports_spdy(supports_spdy),
606 settings_map(settings_map), 588 settings_map(settings_map),
607 alternate_protocol(alternate_protocol) { 589 alternate_protocol(alternate_protocol) {
608 } 590 }
609 bool supports_spdy; 591 bool supports_spdy;
610 const net::SettingsMap* settings_map; 592 const net::SettingsMap* settings_map;
611 const net::AlternateProtocolInfo* alternate_protocol; 593 const net::PortAlternateProtocolPair* alternate_protocol;
612 }; 594 };
613 595
614 void HttpServerPropertiesManager::UpdatePrefsOnUI( 596 void HttpServerPropertiesManager::UpdatePrefsOnUI(
615 base::ListValue* spdy_server_list, 597 base::ListValue* spdy_server_list,
616 net::SpdySettingsMap* spdy_settings_map, 598 net::SpdySettingsMap* spdy_settings_map,
617 net::AlternateProtocolMap* alternate_protocol_map, 599 net::AlternateProtocolMap* alternate_protocol_map,
618 const base::Closure& completion) { 600 const base::Closure& completion) {
619 601
620 typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap; 602 typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap;
621 ServerPrefMap server_pref_map; 603 ServerPrefMap server_pref_map;
622 604
623 DCHECK_CURRENTLY_ON(BrowserThread::UI); 605 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
624 606
625 // Add servers that support spdy to server_pref_map. 607 // Add servers that support spdy to server_pref_map.
626 std::string s; 608 std::string s;
627 for (base::ListValue::const_iterator list_it = spdy_server_list->begin(); 609 for (base::ListValue::const_iterator list_it = spdy_server_list->begin();
628 list_it != spdy_server_list->end(); ++list_it) { 610 list_it != spdy_server_list->end(); ++list_it) {
629 if ((*list_it)->GetAsString(&s)) { 611 if ((*list_it)->GetAsString(&s)) {
630 net::HostPortPair server = net::HostPortPair::FromString(s); 612 net::HostPortPair server = net::HostPortPair::FromString(s);
631 613
632 ServerPrefMap::iterator it = server_pref_map.find(server); 614 ServerPrefMap::iterator it = server_pref_map.find(server);
633 if (it == server_pref_map.end()) { 615 if (it == server_pref_map.end()) {
(...skipping 17 matching lines...) Expand all
651 } else { 633 } else {
652 it->second.settings_map = &map_it->second; 634 it->second.settings_map = &map_it->second;
653 } 635 }
654 } 636 }
655 637
656 // Add AlternateProtocol servers to server_pref_map. 638 // Add AlternateProtocol servers to server_pref_map.
657 for (net::AlternateProtocolMap::const_iterator map_it = 639 for (net::AlternateProtocolMap::const_iterator map_it =
658 alternate_protocol_map->begin(); 640 alternate_protocol_map->begin();
659 map_it != alternate_protocol_map->end(); ++map_it) { 641 map_it != alternate_protocol_map->end(); ++map_it) {
660 const net::HostPortPair& server = map_it->first; 642 const net::HostPortPair& server = map_it->first;
661 const net::AlternateProtocolInfo& port_alternate_protocol = 643 const net::PortAlternateProtocolPair& port_alternate_protocol =
662 map_it->second; 644 map_it->second;
663 if (!net::IsAlternateProtocolValid(port_alternate_protocol.protocol)) { 645 if (!net::IsAlternateProtocolValid(port_alternate_protocol.protocol)) {
664 continue; 646 continue;
665 } 647 }
666 648
667 ServerPrefMap::iterator it = server_pref_map.find(server); 649 ServerPrefMap::iterator it = server_pref_map.find(server);
668 if (it == server_pref_map.end()) { 650 if (it == server_pref_map.end()) {
669 ServerPref server_pref(false, NULL, &map_it->second); 651 ServerPref server_pref(false, NULL, &map_it->second);
670 server_pref_map[server] = server_pref; 652 server_pref_map[server] = server_pref;
671 } else { 653 } else {
(...skipping 27 matching lines...) Expand all
699 std::string key = base::StringPrintf("%u", id); 681 std::string key = base::StringPrintf("%u", id);
700 spdy_settings_dict->SetInteger(key, value); 682 spdy_settings_dict->SetInteger(key, value);
701 } 683 }
702 server_pref_dict->SetWithoutPathExpansion("settings", spdy_settings_dict); 684 server_pref_dict->SetWithoutPathExpansion("settings", spdy_settings_dict);
703 } 685 }
704 686
705 // Save alternate_protocol. 687 // Save alternate_protocol.
706 if (server_pref.alternate_protocol) { 688 if (server_pref.alternate_protocol) {
707 base::DictionaryValue* port_alternate_protocol_dict = 689 base::DictionaryValue* port_alternate_protocol_dict =
708 new base::DictionaryValue; 690 new base::DictionaryValue;
709 const net::AlternateProtocolInfo* port_alternate_protocol = 691 const net::PortAlternateProtocolPair* port_alternate_protocol =
710 server_pref.alternate_protocol; 692 server_pref.alternate_protocol;
711 port_alternate_protocol_dict->SetInteger( 693 port_alternate_protocol_dict->SetInteger(
712 "port", port_alternate_protocol->port); 694 "port", port_alternate_protocol->port);
713 const char* protocol_str = 695 const char* protocol_str =
714 net::AlternateProtocolToString(port_alternate_protocol->protocol); 696 net::AlternateProtocolToString(port_alternate_protocol->protocol);
715 port_alternate_protocol_dict->SetString("protocol_str", protocol_str); 697 port_alternate_protocol_dict->SetString("protocol_str", protocol_str);
716 port_alternate_protocol_dict->SetDouble(
717 "probability", port_alternate_protocol->probability);
718 server_pref_dict->SetWithoutPathExpansion( 698 server_pref_dict->SetWithoutPathExpansion(
719 "alternate_protocol", port_alternate_protocol_dict); 699 "alternate_protocol", port_alternate_protocol_dict);
720 } 700 }
721 701
722 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict); 702 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict);
723 } 703 }
724 704
725 http_server_properties_dict.SetWithoutPathExpansion("servers", servers_dict); 705 http_server_properties_dict.SetWithoutPathExpansion("servers", servers_dict);
726 SetVersion(&http_server_properties_dict, kVersionNumber); 706 SetVersion(&http_server_properties_dict, kVersionNumber);
727 setting_prefs_ = true; 707 setting_prefs_ = true;
728 pref_service_->Set(prefs::kHttpServerProperties, 708 pref_service_->Set(prefs::kHttpServerProperties,
729 http_server_properties_dict); 709 http_server_properties_dict);
730 setting_prefs_ = false; 710 setting_prefs_ = false;
731 711
732 // Note that |completion| will be fired after we have written everything to 712 // Note that |completion| will be fired after we have written everything to
733 // the Preferences, but likely before these changes are serialized to disk. 713 // the Preferences, but likely before these changes are serialized to disk.
734 // This is not a problem though, as JSONPrefStore guarantees that this will 714 // This is not a problem though, as JSONPrefStore guarantees that this will
735 // happen, pretty soon, and even in the case we shut down immediately. 715 // happen, pretty soon, and even in the case we shut down immediately.
736 if (!completion.is_null()) 716 if (!completion.is_null())
737 completion.Run(); 717 completion.Run();
738 } 718 }
739 719
740 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { 720 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() {
741 DCHECK_CURRENTLY_ON(BrowserThread::UI); 721 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
742 if (!setting_prefs_) 722 if (!setting_prefs_)
743 ScheduleUpdateCacheOnUI(); 723 ScheduleUpdateCacheOnUI();
744 } 724 }
745 725
746 } // namespace chrome_browser_net 726 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/http_server_properties_manager.h ('k') | chrome/browser/net/http_server_properties_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698