diff options
author | Peter Varga <pvarga@inf.u-szeged.hu> | 2022-02-02 11:06:24 +0100 |
---|---|---|
committer | Peter Varga <pvarga@inf.u-szeged.hu> | 2022-02-02 16:23:58 +0000 |
commit | ee7acb3042a64a8f4b1b3a15ebac2adeb864b229 (patch) | |
tree | 01be4b9f631aeaabe686a4f49dc668acb707bac8 | |
parent | d5ae47fe7afb7b3349a166b60fa299a5fadc2f9e (diff) | |
download | qtwebengine-chromium-ee7acb3042a64a8f4b1b3a15ebac2adeb864b229.tar.gz |
[Backport] Remove NOTREACHED assertions from NetworkContext's reporting methods
These functions are not supposed to be called if reporting is disabled
(enable_reporting=false). The usages was supposed to be guarded on the
caller side by BUILDFLAG(ENABLE_REPORTING). Nonetheless, some of the
usages are not guarded and they are still called and cause assert on
certain web pages.
As a fix, remove the guards where it is possible from the caller site and
guard the callee site to do nothing if reporting is disabled.
Also enable ReportingServiceProxy for disabled reporting to avoid
crash/assert when reporting API is accessed via mojo.
Bug: none
Change-Id: I404b005606653ed55eec28171f799f9c3d99133a
Test: load https://www.usnews.com/
Review-URL: https://chromium-review.googlesource.com/c/chromium/src/+/3412481
Cr-Commit-Position: refs/heads/main@{#965655}
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
8 files changed, 24 insertions, 86 deletions
diff --git a/chromium/content/browser/BUILD.gn b/chromium/content/browser/BUILD.gn index f1f8ec2104a..00ba6f9edaf 100644 --- a/chromium/content/browser/BUILD.gn +++ b/chromium/content/browser/BUILD.gn @@ -1272,6 +1272,8 @@ jumbo_source_set("browser") { "net/network_errors_listing_ui.h", "net/network_quality_observer_impl.cc", "net/network_quality_observer_impl.h", + "net/reporting_service_proxy.cc", + "net/reporting_service_proxy.h", "network_context_client_base_impl.cc", "network_context_client_base_impl.h", "network_service_client.cc", @@ -3053,13 +3055,6 @@ jumbo_source_set("browser") { ] } - if (enable_reporting) { - sources += [ - "net/reporting_service_proxy.cc", - "net/reporting_service_proxy.h", - ] - } - if (enable_vr) { if (!is_android) { sources += [ diff --git a/chromium/content/browser/browser_interface_binders.cc b/chromium/content/browser/browser_interface_binders.cc index 4cd1d0f50f2..c26f8a3d255 100644 --- a/chromium/content/browser/browser_interface_binders.cc +++ b/chromium/content/browser/browser_interface_binders.cc @@ -30,6 +30,7 @@ #include "content/browser/loader/content_security_notifier.h" #include "content/browser/media/midi_host.h" #include "content/browser/media/session/media_session_service_impl.h" +#include "content/browser/net/reporting_service_proxy.h" #include "content/browser/picture_in_picture/picture_in_picture_service_impl.h" #include "content/browser/process_internals/process_internals.mojom.h" #include "content/browser/process_internals/process_internals_ui.h" @@ -168,10 +169,6 @@ #include "media/mojo/mojom/remoting.mojom-forward.h" #endif -#if BUILDFLAG(ENABLE_REPORTING) -#include "content/browser/net/reporting_service_proxy.h" -#endif - #if BUILDFLAG(GOOGLE_CHROME_BRANDING) && BUILDFLAG(IS_CHROMEOS_ASH) #include "content/browser/service_sandbox_type.h" #include "content/public/browser/service_process_host.h" @@ -711,10 +708,8 @@ void PopulateFrameBinders(RenderFrameHostImpl* host, mojo::BinderMap* map) { map->Add<blink::mojom::QuotaManagerHost>( base::BindRepeating(&BindQuotaManagerHost, base::Unretained(host))); -#if BUILDFLAG(ENABLE_REPORTING) map->Add<blink::mojom::ReportingServiceProxy>(base::BindRepeating( &CreateReportingServiceProxyForFrame, base::Unretained(host))); -#endif map->Add<blink::mojom::SharedWorkerConnector>( base::BindRepeating(&BindSharedWorkerConnector, base::Unretained(host))); @@ -1091,10 +1086,8 @@ void PopulateDedicatedWorkerBinders(DedicatedWorkerHost* host, &DedicatedWorkerHost::BindCacheStorage, base::Unretained(host))); map->Add<blink::mojom::CodeCacheHost>(base::BindRepeating( &DedicatedWorkerHost::CreateCodeCacheHost, base::Unretained(host))); -#if BUILDFLAG(ENABLE_REPORTING) map->Add<blink::mojom::ReportingServiceProxy>(base::BindRepeating( &CreateReportingServiceProxyForDedicatedWorker, base::Unretained(host))); -#endif #if !defined(OS_ANDROID) map->Add<blink::mojom::SerialService>(base::BindRepeating( &DedicatedWorkerHost::BindSerialService, base::Unretained(host))); @@ -1186,10 +1179,8 @@ void PopulateSharedWorkerBinders(SharedWorkerHost* host, mojo::BinderMap* map) { &SharedWorkerHost::BindCacheStorage, base::Unretained(host))); map->Add<blink::mojom::CodeCacheHost>(base::BindRepeating( &SharedWorkerHost::CreateCodeCacheHost, base::Unretained(host))); -#if BUILDFLAG(ENABLE_REPORTING) map->Add<blink::mojom::ReportingServiceProxy>(base::BindRepeating( &CreateReportingServiceProxyForSharedWorker, base::Unretained(host))); -#endif // render process host binders map->Add<media::mojom::VideoDecodePerfHistory>(BindWorkerReceiver( @@ -1271,10 +1262,8 @@ void PopulateServiceWorkerBinders(ServiceWorkerHost* host, &ServiceWorkerHost::BindCacheStorage, base::Unretained(host))); map->Add<blink::mojom::CodeCacheHost>(base::BindRepeating( &ServiceWorkerHost::CreateCodeCacheHost, base::Unretained(host))); -#if BUILDFLAG(ENABLE_REPORTING) map->Add<blink::mojom::ReportingServiceProxy>(base::BindRepeating( &CreateReportingServiceProxyForServiceWorker, base::Unretained(host))); -#endif // render process host binders map->Add<media::mojom::VideoDecodePerfHistory>(BindServiceWorkerReceiver( diff --git a/chromium/content/browser/browsing_data/browsing_data_remover_impl.cc b/chromium/content/browser/browsing_data/browsing_data_remover_impl.cc index 495b79065ac..8e7d82fabe3 100644 --- a/chromium/content/browser/browsing_data/browsing_data_remover_impl.cc +++ b/chromium/content/browser/browsing_data/browsing_data_remover_impl.cc @@ -524,9 +524,9 @@ void BrowsingDataRemoverImpl::RemoveImpl( CreateTaskCompletionClosureForMojo(TracingDataType::kTrustTokens)); } -#if BUILDFLAG(ENABLE_REPORTING) ////////////////////////////////////////////////////////////////////////////// // Reporting cache. + // TODO(https://crbug.com/1291489): Add unit test to cover this. if (remove_mask & DATA_TYPE_COOKIES) { network::mojom::NetworkContext* network_context = browser_context_->GetDefaultStoragePartition()->GetNetworkContext(); @@ -538,7 +538,6 @@ void BrowsingDataRemoverImpl::RemoveImpl( CreateTaskCompletionClosureForMojo( TracingDataType::kNetworkErrorLogging)); } -#endif // BUILDFLAG(ENABLE_REPORTING) ////////////////////////////////////////////////////////////////////////////// // Auth cache. diff --git a/chromium/content/browser/browsing_data/browsing_data_remover_impl_unittest.cc b/chromium/content/browser/browsing_data/browsing_data_remover_impl_unittest.cc index ba50ab44b2a..80278960d1b 100644 --- a/chromium/content/browser/browsing_data/browsing_data_remover_impl_unittest.cc +++ b/chromium/content/browser/browsing_data/browsing_data_remover_impl_unittest.cc @@ -62,17 +62,6 @@ #include "testing/gtest/include/gtest/gtest.h" #include "url/origin.h" -#if BUILDFLAG(ENABLE_REPORTING) -#include "net/network_error_logging/mock_persistent_nel_store.h" -#include "net/network_error_logging/network_error_logging_service.h" -#include "net/reporting/mock_persistent_reporting_store.h" -#include "net/reporting/reporting_cache.h" -#include "net/reporting/reporting_endpoint.h" -#include "net/reporting/reporting_report.h" -#include "net/reporting/reporting_service.h" -#include "net/reporting/reporting_test_util.h" -#endif // BUILDFLAG(ENABLE_REPORTING) - using base::test::RunOnceClosure; using testing::_; using testing::ByRef; diff --git a/chromium/content/browser/net/reporting_service_proxy.cc b/chromium/content/browser/net/reporting_service_proxy.cc index 74dd3068ca6..9808efae13f 100644 --- a/chromium/content/browser/net/reporting_service_proxy.cc +++ b/chromium/content/browser/net/reporting_service_proxy.cc @@ -13,16 +13,12 @@ #include "content/browser/service_worker/service_worker_host.h" #include "content/browser/worker_host/dedicated_worker_host.h" #include "content/browser/worker_host/shared_worker_host.h" -#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_process_host.h" -#include "content/public/browser/site_instance.h" #include "content/public/browser/storage_partition.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h" #include "net/base/network_isolation_key.h" -#include "net/reporting/reporting_report.h" -#include "net/reporting/reporting_service.h" #include "services/network/public/mojom/network_context.mojom.h" #include "third_party/blink/public/mojom/reporting/reporting.mojom.h" #include "url/gurl.h" diff --git a/chromium/content/web_test/browser/web_test_content_browser_client.cc b/chromium/content/web_test/browser/web_test_content_browser_client.cc index c6872573086..888263f08bf 100644 --- a/chromium/content/web_test/browser/web_test_content_browser_client.cc +++ b/chromium/content/web_test/browser/web_test_content_browser_client.cc @@ -555,7 +555,6 @@ void WebTestContentBrowserClient::ConfigureNetworkContextParamsForShell( ShellContentBrowserClient::ConfigureNetworkContextParamsForShell( context, context_params, cert_verifier_creation_params); -#if BUILDFLAG(ENABLE_REPORTING) // Configure the Reporting service in a manner expected by certain Web // Platform Tests (network-error-logging and reporting-api). // @@ -564,7 +563,6 @@ void WebTestContentBrowserClient::ConfigureNetworkContextParamsForShell( context_params->reporting_delivery_interval = kReportingDeliveryIntervalTimeForWebTests; context_params->skip_reporting_send_permission_check = true; -#endif } void WebTestContentBrowserClient::CreateFakeBluetoothChooserFactory( diff --git a/chromium/services/network/network_context.cc b/chromium/services/network/network_context.cc index 15a97e39282..1721a34ef6e 100644 --- a/chromium/services/network/network_context.cc +++ b/chromium/services/network/network_context.cc @@ -779,7 +779,11 @@ size_t NetworkContext::GetNumOutstandingResolveHostRequestsForTesting() const { } bool NetworkContext::SkipReportingPermissionCheck() const { +#if BUILDFLAG(ENABLE_REPORTING) return params_ && params_->skip_reporting_send_permission_check; +#else + return false; +#endif } void NetworkContext::ClearTrustTokenData(mojom::ClearDataFilterPtr filter, @@ -865,10 +869,10 @@ void NetworkContext::ClearHttpAuthCache(base::Time start_time, std::move(callback).Run(); } -#if BUILDFLAG(ENABLE_REPORTING) void NetworkContext::ClearReportingCacheReports( mojom::ClearDataFilterPtr filter, ClearReportingCacheReportsCallback callback) { +#if BUILDFLAG(ENABLE_REPORTING) net::ReportingService* reporting_service = url_request_context_->reporting_service(); if (reporting_service) { @@ -881,6 +885,7 @@ void NetworkContext::ClearReportingCacheReports( net::ReportingBrowsingDataRemover::DATA_TYPE_REPORTS); } } +#endif // BUILDFLAG(ENABLE_REPORTING) std::move(callback).Run(); } @@ -888,6 +893,7 @@ void NetworkContext::ClearReportingCacheReports( void NetworkContext::ClearReportingCacheClients( mojom::ClearDataFilterPtr filter, ClearReportingCacheClientsCallback callback) { +#if BUILDFLAG(ENABLE_REPORTING) net::ReportingService* reporting_service = url_request_context_->reporting_service(); if (reporting_service) { @@ -900,6 +906,7 @@ void NetworkContext::ClearReportingCacheClients( net::ReportingBrowsingDataRemover::DATA_TYPE_CLIENTS); } } +#endif // BUILDFLAG(ENABLE_REPORTING) std::move(callback).Run(); } @@ -907,6 +914,7 @@ void NetworkContext::ClearReportingCacheClients( void NetworkContext::ClearNetworkErrorLogging( mojom::ClearDataFilterPtr filter, ClearNetworkErrorLoggingCallback callback) { +#if BUILDFLAG(ENABLE_REPORTING) net::NetworkErrorLoggingService* logging_service = url_request_context_->network_error_logging_service(); if (logging_service) { @@ -916,6 +924,7 @@ void NetworkContext::ClearNetworkErrorLogging( logging_service->RemoveAllBrowsingData(); } } +#endif // BUILDFLAG(ENABLE_REPORTING) std::move(callback).Run(); } @@ -924,12 +933,14 @@ void NetworkContext::SetDocumentReportingEndpoints( const url::Origin& origin, const net::NetworkIsolationKey& network_isolation_key, const base::flat_map<std::string, std::string>& endpoints) { +#if BUILDFLAG(ENABLE_REPORTING) net::ReportingService* reporting_service = url_request_context()->reporting_service(); if (reporting_service) { reporting_service->SetDocumentReportingEndpoints( origin, network_isolation_key, endpoints); } +#endif // BUILDFLAG(ENABLE_REPORTING) } void NetworkContext::QueueReport( @@ -939,6 +950,7 @@ void NetworkContext::QueueReport( const net::NetworkIsolationKey& network_isolation_key, const absl::optional<std::string>& user_agent, base::Value body) { +#if BUILDFLAG(ENABLE_REPORTING) if (require_network_isolation_key_) DCHECK(!network_isolation_key.IsEmpty()); @@ -965,11 +977,13 @@ void NetworkContext::QueueReport( reporting_service->QueueReport( url, network_isolation_key, reported_user_agent, group, type, base::Value::ToUniquePtrValue(std::move(body)), 0 /* depth */); +#endif // BUILDFLAG(ENABLE_REPORTING) } void NetworkContext::QueueSignedExchangeReport( mojom::SignedExchangeReportPtr report, const net::NetworkIsolationKey& network_isolation_key) { +#if BUILDFLAG(ENABLE_REPORTING) if (require_network_isolation_key_) DCHECK(!network_isolation_key.IsEmpty()); @@ -997,50 +1011,8 @@ void NetworkContext::QueueSignedExchangeReport( details.elapsed_time = report->elapsed_time; details.user_agent = std::move(user_agent); logging_service->QueueSignedExchangeReport(std::move(details)); -} - -#else // BUILDFLAG(ENABLE_REPORTING) -void NetworkContext::ClearReportingCacheReports( - mojom::ClearDataFilterPtr filter, - ClearReportingCacheReportsCallback callback) { - NOTREACHED(); -} - -void NetworkContext::ClearReportingCacheClients( - mojom::ClearDataFilterPtr filter, - ClearReportingCacheClientsCallback callback) { - NOTREACHED(); -} - -void NetworkContext::ClearNetworkErrorLogging( - mojom::ClearDataFilterPtr filter, - ClearNetworkErrorLoggingCallback callback) { - NOTREACHED(); -} - -void NetworkContext::SetDocumentReportingEndpoints( - const url::Origin& origin, - const net::NetworkIsolationKey& network_isolation_key, - const base::flat_map<std::string, std::string>& endpoints) { - NOTREACHED(); -} - -void NetworkContext::QueueReport( - const std::string& type, - const std::string& group, - const GURL& url, - const net::NetworkIsolationKey& network_isolation_key, - const absl::optional<std::string>& user_agent, - base::Value body) { - NOTREACHED(); -} - -void NetworkContext::QueueSignedExchangeReport( - mojom::SignedExchangeReportPtr report, - const net::NetworkIsolationKey& network_isolation_key) { - NOTREACHED(); -} #endif // BUILDFLAG(ENABLE_REPORTING) +} void NetworkContext::ClearDomainReliability( mojom::ClearDataFilterPtr filter, diff --git a/chromium/services/network/public/mojom/network_context.mojom b/chromium/services/network/public/mojom/network_context.mojom index db640c80db5..8545aea5f10 100644 --- a/chromium/services/network/public/mojom/network_context.mojom +++ b/chromium/services/network/public/mojom/network_context.mojom @@ -855,22 +855,22 @@ interface NetworkContext { ClearHttpAuthCache(mojo_base.mojom.Time start_time, mojo_base.mojom.Time end_time) => (); - // Clears all report entries from the reporting cache. Should not be called if + // Clears all report entries from the reporting cache. This has no effect if // the ENABLE_REPORTING build flag is false. // // If a non-null |filter| is specified, will clear only entries matching the // filter. ClearReportingCacheReports(ClearDataFilter? filter) => (); - // Clears all client entries from the reporting cache. Should not be called if + // Clears all client entries from the reporting cache. This has no effect if // the ENABLE_REPORTING build flag is false. // // If a non-null |filter| is specified, will clear only entries matching the // filter. ClearReportingCacheClients(ClearDataFilter? filter) => (); - // Clears policy entries from the NetworkErrorLoggingService. Should not be - // called if the ENABLE_REPORTING build flag is false. + // Clears policy entries from the NetworkErrorLoggingService. This has no + // effect if the ENABLE_REPORTING build flag is false. // // If a non-null |filter| is specified, will clear only entries matching the // filter. |