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

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

Issue 681713002: Update from chromium https://crrev.com/301315 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 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
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
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
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; 351 int count = 0;
384 for (base::DictionaryValue::Iterator it(*servers_dict); !it.IsAtEnd(); 352 for (base::DictionaryValue::Iterator it(*servers_dict); !it.IsAtEnd();
385 it.Advance()) { 353 it.Advance()) {
386 // Get server's host/pair. 354 // Get server's host/pair.
387 const std::string& server_str = it.key(); 355 const std::string& server_str = it.key();
388 net::HostPortPair server = net::HostPortPair::FromString(server_str); 356 net::HostPortPair server = net::HostPortPair::FromString(server_str);
389 if (server.host().empty()) { 357 if (server.host().empty()) {
390 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; 358 DVLOG(1) << "Malformed http_server_properties for server: " << server_str;
391 detected_corrupted_prefs = true; 359 detected_corrupted_prefs = true;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 406
439 // Get alternate_protocol server. 407 // Get alternate_protocol server.
440 DCHECK(alternate_protocol_map->Peek(server) == 408 DCHECK(alternate_protocol_map->Peek(server) ==
441 alternate_protocol_map->end()); 409 alternate_protocol_map->end());
442 const base::DictionaryValue* port_alternate_protocol_dict = NULL; 410 const base::DictionaryValue* port_alternate_protocol_dict = NULL;
443 if (!server_pref_dict->GetDictionaryWithoutPathExpansion( 411 if (!server_pref_dict->GetDictionaryWithoutPathExpansion(
444 "alternate_protocol", &port_alternate_protocol_dict)) { 412 "alternate_protocol", &port_alternate_protocol_dict)) {
445 continue; 413 continue;
446 } 414 }
447 415
448 if (count >= alternate_protocols_to_load) 416 if (count >= kMaxAlternateProtocolHostsToPersist)
449 continue; 417 continue;
450 do { 418 do {
451 int port = 0; 419 int port = 0;
452 if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion( 420 if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion(
453 "port", &port) || 421 "port", &port) ||
454 (port > (1 << 16))) { 422 (port > (1 << 16))) {
455 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; 423 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str;
456 detected_corrupted_prefs = true; 424 detected_corrupted_prefs = true;
457 continue; 425 continue;
458 } 426 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 } 483 }
516 484
517 network_task_runner_->PostTask( 485 network_task_runner_->PostTask(
518 FROM_HERE, 486 FROM_HERE,
519 base::Bind( 487 base::Bind(
520 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread, 488 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread,
521 base::Unretained(this), 489 base::Unretained(this),
522 base::Owned(spdy_servers.release()), 490 base::Owned(spdy_servers.release()),
523 base::Owned(spdy_settings_map.release()), 491 base::Owned(spdy_settings_map.release()),
524 base::Owned(alternate_protocol_map.release()), 492 base::Owned(alternate_protocol_map.release()),
525 alternate_protocol_experiment,
526 base::Owned(supports_quic_map.release()), 493 base::Owned(supports_quic_map.release()),
527 detected_corrupted_prefs)); 494 detected_corrupted_prefs));
528 } 495 }
529 496
530 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread( 497 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread(
531 StringVector* spdy_servers, 498 StringVector* spdy_servers,
532 net::SpdySettingsMap* spdy_settings_map, 499 net::SpdySettingsMap* spdy_settings_map,
533 net::AlternateProtocolMap* alternate_protocol_map, 500 net::AlternateProtocolMap* alternate_protocol_map,
534 net::AlternateProtocolExperiment alternate_protocol_experiment,
535 net::SupportsQuicMap* supports_quic_map, 501 net::SupportsQuicMap* supports_quic_map,
536 bool detected_corrupted_prefs) { 502 bool detected_corrupted_prefs) {
537 // Preferences have the master data because admins might have pushed new 503 // Preferences have the master data because admins might have pushed new
538 // preferences. Update the cached data with new data from preferences. 504 // preferences. Update the cached data with new data from preferences.
539 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 505 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
540 506
541 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); 507 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size());
542 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); 508 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true);
543 509
544 // Update the cached data and use the new spdy_settings from preferences. 510 // Update the cached data and use the new spdy_settings from preferences.
545 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size()); 511 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size());
546 http_server_properties_impl_->InitializeSpdySettingsServers( 512 http_server_properties_impl_->InitializeSpdySettingsServers(
547 spdy_settings_map); 513 spdy_settings_map);
548 514
549 // Update the cached data and use the new Alternate-Protocol server list from 515 // Update the cached data and use the new Alternate-Protocol server list from
550 // preferences. 516 // preferences.
551 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", 517 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers",
552 alternate_protocol_map->size()); 518 alternate_protocol_map->size());
553 http_server_properties_impl_->InitializeAlternateProtocolServers( 519 http_server_properties_impl_->InitializeAlternateProtocolServers(
554 alternate_protocol_map); 520 alternate_protocol_map);
555 http_server_properties_impl_->SetAlternateProtocolExperiment(
556 alternate_protocol_experiment);
557 521
558 http_server_properties_impl_->InitializeSupportsQuic(supports_quic_map); 522 http_server_properties_impl_->InitializeSupportsQuic(supports_quic_map);
559 523
560 // Update the prefs with what we have read (delete all corrupted prefs). 524 // Update the prefs with what we have read (delete all corrupted prefs).
561 if (detected_corrupted_prefs) 525 if (detected_corrupted_prefs)
562 ScheduleUpdatePrefsOnNetworkThread(); 526 ScheduleUpdatePrefsOnNetworkThread();
563 } 527 }
564 528
565 // 529 //
566 // Update Preferences with data from the cached data. 530 // Update Preferences with data from the cached data.
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 completion.Run(); 789 completion.Run();
826 } 790 }
827 791
828 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { 792 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() {
829 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 793 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread());
830 if (!setting_prefs_) 794 if (!setting_prefs_)
831 ScheduleUpdateCacheOnPrefThread(); 795 ScheduleUpdateCacheOnPrefThread();
832 } 796 }
833 797
834 } // namespace net 798 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_manager.h ('k') | net/http/http_server_properties_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698