OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/http_server_properties_manager.h" | 5 #include "net/http/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" | |
11 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
12 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
13 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
15 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
16 #include "base/values.h" | 15 #include "base/values.h" |
17 | 16 |
18 namespace net { | 17 namespace net { |
19 | 18 |
20 namespace { | 19 namespace { |
(...skipping 16 matching lines...) Expand all Loading... | |
37 | 36 |
38 // "version" 0 indicates, http_server_properties doesn't have "version" | 37 // "version" 0 indicates, http_server_properties doesn't have "version" |
39 // property. | 38 // property. |
40 const int kMissingVersion = 0; | 39 const int kMissingVersion = 0; |
41 | 40 |
42 // The version number of persisted http_server_properties. | 41 // The version number of persisted http_server_properties. |
43 const int kVersionNumber = 3; | 42 const int kVersionNumber = 3; |
44 | 43 |
45 typedef std::vector<std::string> StringVector; | 44 typedef std::vector<std::string> StringVector; |
46 | 45 |
47 // Load either 200 or 1000 servers based on a coin flip. | 46 // Persist 200 MRU AlternateProtocolHostPortPairs. |
48 const int k200AlternateProtocolHostsToLoad = 200; | 47 const int kMaxAlternateProtocolHostsToPersist = 200; |
49 const int k1000AlternateProtocolHostsToLoad = 1000; | |
50 // Persist 1000 MRU AlternateProtocolHostPortPairs. | |
51 const int kMaxAlternateProtocolHostsToPersist = 1000; | |
52 | 48 |
53 // Persist 200 MRU SpdySettingsHostPortPairs. | 49 // Persist 200 MRU SpdySettingsHostPortPairs. |
54 const int kMaxSpdySettingsHostsToPersist = 200; | 50 const int kMaxSpdySettingsHostsToPersist = 200; |
55 | 51 |
56 // Persist 300 MRU SupportsSpdyServerHostPortPairs. | 52 // Persist 300 MRU SupportsSpdyServerHostPortPairs. |
57 const int kMaxSupportsSpdyServerHostsToPersist = 300; | 53 const int kMaxSupportsSpdyServerHostsToPersist = 300; |
58 | 54 |
59 } // namespace | 55 } // namespace |
60 | 56 |
61 //////////////////////////////////////////////////////////////////////////////// | 57 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 http_server_properties_impl_->ClearAlternateProtocol(server); | 202 http_server_properties_impl_->ClearAlternateProtocol(server); |
207 ScheduleUpdatePrefsOnNetworkThread(); | 203 ScheduleUpdatePrefsOnNetworkThread(); |
208 } | 204 } |
209 | 205 |
210 const net::AlternateProtocolMap& | 206 const net::AlternateProtocolMap& |
211 HttpServerPropertiesManager::alternate_protocol_map() const { | 207 HttpServerPropertiesManager::alternate_protocol_map() const { |
212 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 208 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
213 return http_server_properties_impl_->alternate_protocol_map(); | 209 return http_server_properties_impl_->alternate_protocol_map(); |
214 } | 210 } |
215 | 211 |
216 void HttpServerPropertiesManager::SetAlternateProtocolExperiment( | |
217 AlternateProtocolExperiment experiment) { | |
218 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | |
219 http_server_properties_impl_->SetAlternateProtocolExperiment(experiment); | |
220 } | |
221 | |
222 void HttpServerPropertiesManager::SetAlternateProtocolProbabilityThreshold( | 212 void HttpServerPropertiesManager::SetAlternateProtocolProbabilityThreshold( |
223 double threshold) { | 213 double threshold) { |
224 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 214 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
225 http_server_properties_impl_->SetAlternateProtocolProbabilityThreshold( | 215 http_server_properties_impl_->SetAlternateProtocolProbabilityThreshold( |
226 threshold); | 216 threshold); |
227 } | 217 } |
228 | 218 |
229 AlternateProtocolExperiment | |
230 HttpServerPropertiesManager::GetAlternateProtocolExperiment() const { | |
231 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | |
232 return http_server_properties_impl_->GetAlternateProtocolExperiment(); | |
233 } | |
234 | |
235 const SettingsMap& HttpServerPropertiesManager::GetSpdySettings( | 219 const SettingsMap& HttpServerPropertiesManager::GetSpdySettings( |
236 const HostPortPair& host_port_pair) { | 220 const HostPortPair& host_port_pair) { |
237 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 221 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
238 return http_server_properties_impl_->GetSpdySettings(host_port_pair); | 222 return http_server_properties_impl_->GetSpdySettings(host_port_pair); |
239 } | 223 } |
240 | 224 |
241 bool HttpServerPropertiesManager::SetSpdySetting( | 225 bool HttpServerPropertiesManager::SetSpdySetting( |
242 const HostPortPair& host_port_pair, | 226 const HostPortPair& host_port_pair, |
243 SpdySettingsIds id, | 227 SpdySettingsIds id, |
244 SpdySettingsFlags flags, | 228 SpdySettingsFlags flags, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 } | 340 } |
357 | 341 |
358 // String is host/port pair of spdy server. | 342 // String is host/port pair of spdy server. |
359 scoped_ptr<StringVector> spdy_servers(new StringVector); | 343 scoped_ptr<StringVector> spdy_servers(new StringVector); |
360 scoped_ptr<net::SpdySettingsMap> spdy_settings_map( | 344 scoped_ptr<net::SpdySettingsMap> spdy_settings_map( |
361 new net::SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); | 345 new net::SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); |
362 scoped_ptr<net::AlternateProtocolMap> alternate_protocol_map( | 346 scoped_ptr<net::AlternateProtocolMap> alternate_protocol_map( |
363 new net::AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist)); | 347 new net::AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist)); |
364 scoped_ptr<net::SupportsQuicMap> supports_quic_map( | 348 scoped_ptr<net::SupportsQuicMap> supports_quic_map( |
365 new net::SupportsQuicMap()); | 349 new net::SupportsQuicMap()); |
366 // TODO(rtenneti): Delete the following code after the experiment. | |
367 int alternate_protocols_to_load = k200AlternateProtocolHostsToLoad; | |
368 net::AlternateProtocolExperiment alternate_protocol_experiment = | |
369 net::ALTERNATE_PROTOCOL_NOT_PART_OF_EXPERIMENT; | |
370 if (version == kVersionNumber) { | |
371 if (base::RandInt(0, 99) == 0) { | |
372 alternate_protocol_experiment = | |
373 net::ALTERNATE_PROTOCOL_TRUNCATED_200_SERVERS; | |
374 } else { | |
375 alternate_protocols_to_load = k1000AlternateProtocolHostsToLoad; | |
376 alternate_protocol_experiment = | |
377 net::ALTERNATE_PROTOCOL_TRUNCATED_1000_SERVERS; | |
378 } | |
379 DVLOG(1) << "# of servers that support alternate_protocol: " | |
380 << alternate_protocols_to_load; | |
381 } | |
382 | 350 |
383 int count = 0; | |
384 for (base::DictionaryValue::Iterator it(*servers_dict); !it.IsAtEnd(); | 351 for (base::DictionaryValue::Iterator it(*servers_dict); !it.IsAtEnd(); |
385 it.Advance()) { | 352 it.Advance()) { |
386 // Get server's host/pair. | 353 // Get server's host/pair. |
387 const std::string& server_str = it.key(); | 354 const std::string& server_str = it.key(); |
388 net::HostPortPair server = net::HostPortPair::FromString(server_str); | 355 net::HostPortPair server = net::HostPortPair::FromString(server_str); |
389 if (server.host().empty()) { | 356 if (server.host().empty()) { |
390 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; | 357 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; |
391 detected_corrupted_prefs = true; | 358 detected_corrupted_prefs = true; |
392 continue; | 359 continue; |
393 } | 360 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
438 | 405 |
439 // Get alternate_protocol server. | 406 // Get alternate_protocol server. |
440 DCHECK(alternate_protocol_map->Peek(server) == | 407 DCHECK(alternate_protocol_map->Peek(server) == |
441 alternate_protocol_map->end()); | 408 alternate_protocol_map->end()); |
442 const base::DictionaryValue* port_alternate_protocol_dict = NULL; | 409 const base::DictionaryValue* port_alternate_protocol_dict = NULL; |
443 if (!server_pref_dict->GetDictionaryWithoutPathExpansion( | 410 if (!server_pref_dict->GetDictionaryWithoutPathExpansion( |
444 "alternate_protocol", &port_alternate_protocol_dict)) { | 411 "alternate_protocol", &port_alternate_protocol_dict)) { |
445 continue; | 412 continue; |
446 } | 413 } |
447 | 414 |
448 if (count >= alternate_protocols_to_load) | |
jar (doing other things)
2014/10/23 23:11:51
I think this is OK. Just to confirm.... we will "
ramant (doing other things)
2014/10/23 23:27:19
Made this code similar to other MRU items we are p
| |
449 continue; | |
450 do { | 415 do { |
451 int port = 0; | 416 int port = 0; |
452 if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion( | 417 if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion( |
453 "port", &port) || | 418 "port", &port) || |
454 (port > (1 << 16))) { | 419 (port > (1 << 16))) { |
455 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; | 420 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; |
456 detected_corrupted_prefs = true; | 421 detected_corrupted_prefs = true; |
457 continue; | 422 continue; |
458 } | 423 } |
459 std::string protocol_str; | 424 std::string protocol_str; |
(...skipping 17 matching lines...) Expand all Loading... | |
477 "probability", &probability)) { | 442 "probability", &probability)) { |
478 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; | 443 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; |
479 detected_corrupted_prefs = true; | 444 detected_corrupted_prefs = true; |
480 continue; | 445 continue; |
481 } | 446 } |
482 | 447 |
483 net::AlternateProtocolInfo port_alternate_protocol(port, | 448 net::AlternateProtocolInfo port_alternate_protocol(port, |
484 protocol, | 449 protocol, |
485 probability); | 450 probability); |
486 alternate_protocol_map->Put(server, port_alternate_protocol); | 451 alternate_protocol_map->Put(server, port_alternate_protocol); |
487 ++count; | |
488 } while (false); | 452 } while (false); |
489 | 453 |
490 // Get SupportsQuic. | 454 // Get SupportsQuic. |
491 DCHECK(supports_quic_map->find(server) == supports_quic_map->end()); | 455 DCHECK(supports_quic_map->find(server) == supports_quic_map->end()); |
492 const base::DictionaryValue* supports_quic_dict = NULL; | 456 const base::DictionaryValue* supports_quic_dict = NULL; |
493 if (!server_pref_dict->GetDictionaryWithoutPathExpansion( | 457 if (!server_pref_dict->GetDictionaryWithoutPathExpansion( |
494 "supports_quic", &supports_quic_dict)) { | 458 "supports_quic", &supports_quic_dict)) { |
495 continue; | 459 continue; |
496 } | 460 } |
497 do { | 461 do { |
(...skipping 17 matching lines...) Expand all Loading... | |
515 } | 479 } |
516 | 480 |
517 network_task_runner_->PostTask( | 481 network_task_runner_->PostTask( |
518 FROM_HERE, | 482 FROM_HERE, |
519 base::Bind( | 483 base::Bind( |
520 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread, | 484 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread, |
521 base::Unretained(this), | 485 base::Unretained(this), |
522 base::Owned(spdy_servers.release()), | 486 base::Owned(spdy_servers.release()), |
523 base::Owned(spdy_settings_map.release()), | 487 base::Owned(spdy_settings_map.release()), |
524 base::Owned(alternate_protocol_map.release()), | 488 base::Owned(alternate_protocol_map.release()), |
525 alternate_protocol_experiment, | |
526 base::Owned(supports_quic_map.release()), | 489 base::Owned(supports_quic_map.release()), |
527 detected_corrupted_prefs)); | 490 detected_corrupted_prefs)); |
528 } | 491 } |
529 | 492 |
530 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread( | 493 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread( |
531 StringVector* spdy_servers, | 494 StringVector* spdy_servers, |
532 net::SpdySettingsMap* spdy_settings_map, | 495 net::SpdySettingsMap* spdy_settings_map, |
533 net::AlternateProtocolMap* alternate_protocol_map, | 496 net::AlternateProtocolMap* alternate_protocol_map, |
534 net::AlternateProtocolExperiment alternate_protocol_experiment, | |
535 net::SupportsQuicMap* supports_quic_map, | 497 net::SupportsQuicMap* supports_quic_map, |
536 bool detected_corrupted_prefs) { | 498 bool detected_corrupted_prefs) { |
537 // Preferences have the master data because admins might have pushed new | 499 // Preferences have the master data because admins might have pushed new |
538 // preferences. Update the cached data with new data from preferences. | 500 // preferences. Update the cached data with new data from preferences. |
539 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 501 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
540 | 502 |
541 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); | 503 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); |
542 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); | 504 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); |
543 | 505 |
544 // Update the cached data and use the new spdy_settings from preferences. | 506 // Update the cached data and use the new spdy_settings from preferences. |
545 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size()); | 507 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size()); |
546 http_server_properties_impl_->InitializeSpdySettingsServers( | 508 http_server_properties_impl_->InitializeSpdySettingsServers( |
547 spdy_settings_map); | 509 spdy_settings_map); |
548 | 510 |
549 // Update the cached data and use the new Alternate-Protocol server list from | 511 // Update the cached data and use the new Alternate-Protocol server list from |
550 // preferences. | 512 // preferences. |
551 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", | 513 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", |
552 alternate_protocol_map->size()); | 514 alternate_protocol_map->size()); |
553 http_server_properties_impl_->InitializeAlternateProtocolServers( | 515 http_server_properties_impl_->InitializeAlternateProtocolServers( |
554 alternate_protocol_map); | 516 alternate_protocol_map); |
555 http_server_properties_impl_->SetAlternateProtocolExperiment( | |
556 alternate_protocol_experiment); | |
557 | 517 |
558 http_server_properties_impl_->InitializeSupportsQuic(supports_quic_map); | 518 http_server_properties_impl_->InitializeSupportsQuic(supports_quic_map); |
559 | 519 |
560 // Update the prefs with what we have read (delete all corrupted prefs). | 520 // Update the prefs with what we have read (delete all corrupted prefs). |
561 if (detected_corrupted_prefs) | 521 if (detected_corrupted_prefs) |
562 ScheduleUpdatePrefsOnNetworkThread(); | 522 ScheduleUpdatePrefsOnNetworkThread(); |
563 } | 523 } |
564 | 524 |
565 // | 525 // |
566 // Update Preferences with data from the cached data. | 526 // Update Preferences with data from the cached data. |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
825 completion.Run(); | 785 completion.Run(); |
826 } | 786 } |
827 | 787 |
828 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { | 788 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { |
829 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 789 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
830 if (!setting_prefs_) | 790 if (!setting_prefs_) |
831 ScheduleUpdateCacheOnPrefThread(); | 791 ScheduleUpdateCacheOnPrefThread(); |
832 } | 792 } |
833 | 793 |
834 } // namespace net | 794 } // namespace net |
OLD | NEW |