OLD | NEW |
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/io_thread.h" | 5 #include "chrome/browser/io_thread.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "base/time/time.h" | 33 #include "base/time/time.h" |
34 #include "base/trace_event/trace_event.h" | 34 #include "base/trace_event/trace_event.h" |
35 #include "build/build_config.h" | 35 #include "build/build_config.h" |
36 #include "chrome/browser/browser_process.h" | 36 #include "chrome/browser/browser_process.h" |
37 #include "chrome/browser/data_usage/tab_id_annotator.h" | 37 #include "chrome/browser/data_usage/tab_id_annotator.h" |
38 #include "chrome/browser/net/async_dns_field_trial.h" | 38 #include "chrome/browser/net/async_dns_field_trial.h" |
39 #include "chrome/browser/net/chrome_network_delegate.h" | 39 #include "chrome/browser/net/chrome_network_delegate.h" |
40 #include "chrome/browser/net/connect_interceptor.h" | 40 #include "chrome/browser/net/connect_interceptor.h" |
41 #include "chrome/browser/net/dns_probe_service.h" | 41 #include "chrome/browser/net/dns_probe_service.h" |
42 #include "chrome/browser/net/proxy_service_factory.h" | 42 #include "chrome/browser/net/proxy_service_factory.h" |
| 43 #include "chrome/browser/net/sth_distributor_provider.h" |
43 #include "chrome/common/channel_info.h" | 44 #include "chrome/common/channel_info.h" |
44 #include "chrome/common/chrome_content_client.h" | 45 #include "chrome/common/chrome_content_client.h" |
45 #include "chrome/common/chrome_switches.h" | 46 #include "chrome/common/chrome_switches.h" |
46 #include "chrome/common/pref_names.h" | 47 #include "chrome/common/pref_names.h" |
| 48 #include "components/certificate_transparency/tree_state_tracker.h" |
47 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_pref
s.h" | 49 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_pref
s.h" |
48 #include "components/data_usage/core/data_use_aggregator.h" | 50 #include "components/data_usage/core/data_use_aggregator.h" |
49 #include "components/data_usage/core/data_use_amortizer.h" | 51 #include "components/data_usage/core/data_use_amortizer.h" |
50 #include "components/data_usage/core/data_use_annotator.h" | 52 #include "components/data_usage/core/data_use_annotator.h" |
51 #include "components/metrics/metrics_service.h" | 53 #include "components/metrics/metrics_service.h" |
52 #include "components/net_log/chrome_net_log.h" | 54 #include "components/net_log/chrome_net_log.h" |
53 #include "components/network_session_configurator/network_session_configurator.h
" | 55 #include "components/network_session_configurator/network_session_configurator.h
" |
54 #include "components/policy/core/common/policy_service.h" | 56 #include "components/policy/core/common/policy_service.h" |
55 #include "components/prefs/pref_registry_simple.h" | 57 #include "components/prefs/pref_registry_simple.h" |
56 #include "components/prefs/pref_service.h" | 58 #include "components/prefs/pref_service.h" |
57 #include "components/proxy_config/pref_proxy_config_tracker.h" | 59 #include "components/proxy_config/pref_proxy_config_tracker.h" |
58 #include "components/variations/variations_associated_data.h" | 60 #include "components/variations/variations_associated_data.h" |
59 #include "components/version_info/version_info.h" | 61 #include "components/version_info/version_info.h" |
60 #include "content/public/browser/browser_thread.h" | 62 #include "content/public/browser/browser_thread.h" |
61 #include "content/public/browser/cookie_store_factory.h" | 63 #include "content/public/browser/cookie_store_factory.h" |
62 #include "content/public/common/content_features.h" | 64 #include "content/public/common/content_features.h" |
63 #include "content/public/common/content_switches.h" | 65 #include "content/public/common/content_switches.h" |
64 #include "content/public/common/user_agent.h" | 66 #include "content/public/common/user_agent.h" |
65 #include "net/base/host_mapping_rules.h" | 67 #include "net/base/host_mapping_rules.h" |
66 #include "net/base/logging_network_change_observer.h" | 68 #include "net/base/logging_network_change_observer.h" |
67 #include "net/base/sdch_manager.h" | 69 #include "net/base/sdch_manager.h" |
68 #include "net/cert/cert_verifier.h" | 70 #include "net/cert/cert_verifier.h" |
69 #include "net/cert/cert_verify_proc.h" | 71 #include "net/cert/cert_verify_proc.h" |
70 #include "net/cert/ct_known_logs.h" | 72 #include "net/cert/ct_known_logs.h" |
71 #include "net/cert/ct_log_verifier.h" | 73 #include "net/cert/ct_log_verifier.h" |
72 #include "net/cert/ct_policy_enforcer.h" | 74 #include "net/cert/ct_policy_enforcer.h" |
73 #include "net/cert/ct_verifier.h" | 75 #include "net/cert/ct_verifier.h" |
74 #include "net/cert/multi_log_ct_verifier.h" | 76 #include "net/cert/multi_log_ct_verifier.h" |
75 #include "net/cert/multi_threaded_cert_verifier.h" | 77 #include "net/cert/multi_threaded_cert_verifier.h" |
| 78 #include "net/cert/sth_distributor.h" |
| 79 #include "net/cert/sth_observer.h" |
76 #include "net/cookies/cookie_store.h" | 80 #include "net/cookies/cookie_store.h" |
77 #include "net/dns/host_cache.h" | 81 #include "net/dns/host_cache.h" |
78 #include "net/dns/host_resolver.h" | 82 #include "net/dns/host_resolver.h" |
79 #include "net/dns/mapped_host_resolver.h" | 83 #include "net/dns/mapped_host_resolver.h" |
80 #include "net/ftp/ftp_network_layer.h" | 84 #include "net/ftp/ftp_network_layer.h" |
81 #include "net/http/http_auth_filter.h" | 85 #include "net/http/http_auth_filter.h" |
82 #include "net/http/http_auth_handler_factory.h" | 86 #include "net/http/http_auth_handler_factory.h" |
83 #include "net/http/http_auth_preferences.h" | 87 #include "net/http/http_auth_preferences.h" |
84 #include "net/http/http_network_layer.h" | 88 #include "net/http/http_network_layer.h" |
85 #include "net/http/http_server_properties_impl.h" | 89 #include "net/http/http_server_properties_impl.h" |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 value->GetAsBoolean(&is_quic_allowed_by_policy_); | 391 value->GetAsBoolean(&is_quic_allowed_by_policy_); |
388 | 392 |
389 // Some unit tests use IOThread but do not initialize MetricsService. In that | 393 // Some unit tests use IOThread but do not initialize MetricsService. In that |
390 // case it is fine not to have |metrics_data_use_forwarder_|. | 394 // case it is fine not to have |metrics_data_use_forwarder_|. |
391 if (g_browser_process->metrics_service()) { | 395 if (g_browser_process->metrics_service()) { |
392 // Callback for updating data use prefs should be obtained on UI thread. | 396 // Callback for updating data use prefs should be obtained on UI thread. |
393 metrics_data_use_forwarder_ = | 397 metrics_data_use_forwarder_ = |
394 g_browser_process->metrics_service()->GetDataUseForwardingCallback(); | 398 g_browser_process->metrics_service()->GetDataUseForwardingCallback(); |
395 } | 399 } |
396 | 400 |
| 401 chrome_browser_net::SetGlobalSTHDistributor( |
| 402 std::unique_ptr<net::ct::STHDistributor>(new net::ct::STHDistributor())); |
| 403 |
397 BrowserThread::SetDelegate(BrowserThread::IO, this); | 404 BrowserThread::SetDelegate(BrowserThread::IO, this); |
398 } | 405 } |
399 | 406 |
400 IOThread::~IOThread() { | 407 IOThread::~IOThread() { |
401 // This isn't needed for production code, but in tests, IOThread may | 408 // This isn't needed for production code, but in tests, IOThread may |
402 // be multiply constructed. | 409 // be multiply constructed. |
403 BrowserThread::SetDelegate(BrowserThread::IO, NULL); | 410 BrowserThread::SetDelegate(BrowserThread::IO, NULL); |
404 | 411 |
405 pref_proxy_config_tracker_->DetachFromPrefService(); | 412 pref_proxy_config_tracker_->DetachFromPrefService(); |
406 DCHECK(!globals_); | 413 DCHECK(!globals_); |
| 414 |
| 415 // Destroy the old distributor to check that the observers list it holds is |
| 416 // empty. |
| 417 chrome_browser_net::SetGlobalSTHDistributor(nullptr); |
407 } | 418 } |
408 | 419 |
409 IOThread::Globals* IOThread::globals() { | 420 IOThread::Globals* IOThread::globals() { |
410 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 421 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
411 return globals_; | 422 return globals_; |
412 } | 423 } |
413 | 424 |
414 void IOThread::SetGlobalsForTesting(Globals* globals) { | 425 void IOThread::SetGlobalsForTesting(Globals* globals) { |
415 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 426 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
416 DCHECK(!globals || !globals_); | 427 DCHECK(!globals || !globals_); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 | 612 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
602 // is fixed. | 613 // is fixed. |
603 tracked_objects::ScopedTracker tracking_profile7( | 614 tracked_objects::ScopedTracker tracking_profile7( |
604 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 615 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
605 "466432 IOThread::InitAsync::CreateMultiLogVerifier")); | 616 "466432 IOThread::InitAsync::CreateMultiLogVerifier")); |
606 net::MultiLogCTVerifier* ct_verifier = new net::MultiLogCTVerifier(); | 617 net::MultiLogCTVerifier* ct_verifier = new net::MultiLogCTVerifier(); |
607 globals_->cert_transparency_verifier.reset(ct_verifier); | 618 globals_->cert_transparency_verifier.reset(ct_verifier); |
608 // Add built-in logs | 619 // Add built-in logs |
609 ct_verifier->AddLogs(globals_->ct_logs); | 620 ct_verifier->AddLogs(globals_->ct_logs); |
610 | 621 |
| 622 ct_tree_tracker_.reset( |
| 623 new certificate_transparency::TreeStateTracker(globals_->ct_logs)); |
| 624 // Register the ct_tree_tracker_ as observer for new STHs. |
| 625 RegisterSTHObserver(ct_tree_tracker_.get()); |
| 626 // Register the ct_tree_tracker_ as observer for verified SCTs. |
| 627 globals_->cert_transparency_verifier->SetObserver(ct_tree_tracker_.get()); |
| 628 |
611 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 | 629 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
612 // is fixed. | 630 // is fixed. |
613 tracked_objects::ScopedTracker tracking_profile10( | 631 tracked_objects::ScopedTracker tracking_profile10( |
614 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 632 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
615 "466432 IOThread::InitAsync::CTPolicyEnforcer")); | 633 "466432 IOThread::InitAsync::CTPolicyEnforcer")); |
616 globals_->ct_policy_enforcer.reset(new net::CTPolicyEnforcer()); | 634 globals_->ct_policy_enforcer.reset(new net::CTPolicyEnforcer()); |
617 params_.ct_policy_enforcer = globals_->ct_policy_enforcer.get(); | 635 params_.ct_policy_enforcer = globals_->ct_policy_enforcer.get(); |
618 | 636 |
619 globals_->ssl_config_service = GetSSLConfigService(); | 637 globals_->ssl_config_service = GetSSLConfigService(); |
620 | 638 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 | 778 |
761 void IOThread::CleanUp() { | 779 void IOThread::CleanUp() { |
762 base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks(); | 780 base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks(); |
763 | 781 |
764 #if defined(USE_NSS_CERTS) | 782 #if defined(USE_NSS_CERTS) |
765 net::ShutdownNSSHttpIO(); | 783 net::ShutdownNSSHttpIO(); |
766 #endif | 784 #endif |
767 | 785 |
768 system_url_request_context_getter_ = NULL; | 786 system_url_request_context_getter_ = NULL; |
769 | 787 |
| 788 // Unlink the ct_tree_tracker_ from the global cert_transparency_verifier |
| 789 // and unregister it from new STH notifications so it will take no actions |
| 790 // on anything observed during CleanUp process. |
| 791 globals()->cert_transparency_verifier->SetObserver(nullptr); |
| 792 UnregisterSTHObserver(ct_tree_tracker_.get()); |
| 793 |
| 794 ct_tree_tracker_.reset(); |
| 795 |
770 // Release objects that the net::URLRequestContext could have been pointing | 796 // Release objects that the net::URLRequestContext could have been pointing |
771 // to. | 797 // to. |
772 | 798 |
773 // Shutdown the HistogramWatcher on the IO thread. | 799 // Shutdown the HistogramWatcher on the IO thread. |
774 net::NetworkChangeNotifier::ShutdownHistogramWatcher(); | 800 net::NetworkChangeNotifier::ShutdownHistogramWatcher(); |
775 | 801 |
776 // This must be reset before the ChromeNetLog is destroyed. | 802 // This must be reset before the ChromeNetLog is destroyed. |
777 network_change_observer_.reset(); | 803 network_change_observer_.reset(); |
778 | 804 |
779 system_proxy_config_service_.reset(); | 805 system_proxy_config_service_.reset(); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 quick_check_enabled_.GetValue()); | 937 quick_check_enabled_.GetValue()); |
912 | 938 |
913 globals_->system_request_context.reset( | 939 globals_->system_request_context.reset( |
914 ConstructSystemRequestContext(globals_, params_, net_log_)); | 940 ConstructSystemRequestContext(globals_, params_, net_log_)); |
915 } | 941 } |
916 | 942 |
917 void IOThread::UpdateDnsClientEnabled() { | 943 void IOThread::UpdateDnsClientEnabled() { |
918 globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_); | 944 globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_); |
919 } | 945 } |
920 | 946 |
| 947 void IOThread::RegisterSTHObserver(net::ct::STHObserver* observer) { |
| 948 chrome_browser_net::GetGlobalSTHDistributor()->RegisterObserver(observer); |
| 949 } |
| 950 |
| 951 void IOThread::UnregisterSTHObserver(net::ct::STHObserver* observer) { |
| 952 chrome_browser_net::GetGlobalSTHDistributor()->UnregisterObserver(observer); |
| 953 } |
| 954 |
921 // static | 955 // static |
922 net::URLRequestContext* IOThread::ConstructSystemRequestContext( | 956 net::URLRequestContext* IOThread::ConstructSystemRequestContext( |
923 IOThread::Globals* globals, | 957 IOThread::Globals* globals, |
924 const net::HttpNetworkSession::Params& params, | 958 const net::HttpNetworkSession::Params& params, |
925 net::NetLog* net_log) { | 959 net::NetLog* net_log) { |
926 net::URLRequestContext* context = new SystemURLRequestContext; | 960 net::URLRequestContext* context = new SystemURLRequestContext; |
927 context->set_net_log(net_log); | 961 context->set_net_log(net_log); |
928 context->set_host_resolver(globals->host_resolver.get()); | 962 context->set_host_resolver(globals->host_resolver.get()); |
929 context->set_cert_verifier(globals->cert_verifier.get()); | 963 context->set_cert_verifier(globals->cert_verifier.get()); |
930 context->set_transport_security_state( | 964 context->set_transport_security_state( |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the | 1090 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the |
1057 // system URLRequestContext too. There's no reason this should be tied to a | 1091 // system URLRequestContext too. There's no reason this should be tied to a |
1058 // profile. | 1092 // profile. |
1059 return context; | 1093 return context; |
1060 } | 1094 } |
1061 | 1095 |
1062 const metrics::UpdateUsagePrefCallbackType& | 1096 const metrics::UpdateUsagePrefCallbackType& |
1063 IOThread::GetMetricsDataUseForwarder() { | 1097 IOThread::GetMetricsDataUseForwarder() { |
1064 return metrics_data_use_forwarder_; | 1098 return metrics_data_use_forwarder_; |
1065 } | 1099 } |
OLD | NEW |