Commit d07dc85e authored by Julia Tuttle's avatar Julia Tuttle Committed by Commit Bot

Reporting API / Network Error Logging: Make available to Cronet.

Bug: 799616
Cq-Include-Trybots: master.tryserver.chromium.android:android_cronet_tester;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ic05966416c1f82dd593d061cccc9ac0a2728b588
Reviewed-on: https://chromium-review.googlesource.com/853172
Commit-Queue: Julia Tuttle <juliatuttle@chromium.org>
Reviewed-by: default avatarMiriam Gershenson <mgersh@chromium.org>
Reviewed-by: default avatarMisha Efimov <mef@chromium.org>
Cr-Commit-Position: refs/heads/master@{#530650}
parent 442eb325
......@@ -29,9 +29,14 @@
#include "net/nqe/network_quality_estimator_params.h"
#include "net/quic/chromium/quic_utils_chromium.h"
#include "net/quic/core/quic_packets.h"
#include "net/reporting/reporting_policy.h"
#include "net/socket/ssl_client_socket.h"
#include "net/url_request/url_request_context_builder.h"
#if BUILDFLAG(ENABLE_REPORTING)
#include "net/reporting/reporting_policy.h"
#endif // BUILDFLAG(ENABLE_REPORTING)
namespace cronet {
namespace {
......@@ -105,6 +110,11 @@ const char kHostResolverRules[] = "host_resolver_rules";
// NetworkQualityEstimator (NQE) experiment dictionary name.
const char kNetworkQualityEstimatorFieldTrialName[] = "NetworkQualityEstimator";
// Network Error Logging experiment dictionary name.
const char kNetworkErrorLoggingFieldTrialName[] = "NetworkErrorLogging";
// Name of boolean to enable Reporting API.
const char kNetworkErrorLoggingEnable[] = "enable";
// Disable IPv6 when on WiFi. This is a workaround for a known issue on certain
// Android phones, and should not be necessary when not on one of those devices.
// See https://crbug.com/696569 for details.
......@@ -209,6 +219,7 @@ void URLRequestContextConfig::ParseAndSetExperimentalOptions(
bool stale_dns_enable = false;
bool host_resolver_rules_enable = false;
bool disable_ipv6_on_wifi = false;
bool nel_enable = false;
effective_experimental_options = dict->CreateDeepCopy();
StaleHostResolver::StaleOptions stale_dns_options;
......@@ -412,6 +423,15 @@ void URLRequestContextConfig::ParseAndSetExperimentalOptions(
}
host_resolver_rules_enable = host_resolver_rules_args->GetString(
kHostResolverRules, &host_resolver_rules_string);
} else if (it.key() == kNetworkErrorLoggingFieldTrialName) {
const base::DictionaryValue* nel_args = nullptr;
if (!it.value().GetAsDictionary(&nel_args)) {
LOG(ERROR) << "\"" << it.key() << "\" config params \"" << it.value()
<< "\" is not a dictionary value";
effective_experimental_options->Remove(it.key(), nullptr);
continue;
}
nel_args->GetBoolean(kNetworkErrorLoggingEnable, &nel_enable);
} else if (it.key() == kDisableIPv6OnWifi) {
if (!it.value().GetAsBoolean(&disable_ipv6_on_wifi)) {
LOG(ERROR) << "\"" << it.key() << "\" config params \"" << it.value()
......@@ -483,6 +503,23 @@ void URLRequestContextConfig::ParseAndSetExperimentalOptions(
}
context_builder->set_host_resolver(std::move(host_resolver));
}
#if BUILDFLAG(ENABLE_REPORTING)
if (nel_enable) {
auto policy = std::make_unique<net::ReportingPolicy>();
// Apps (like Cronet embedders) are generally allowed to run in the
// background, even across network changes, so use more relaxed privacy
// settings than when Reporting is running in the browser.
policy->persist_reports_across_restarts = true;
policy->persist_clients_across_restarts = true;
policy->clear_reports_on_network_changes = false;
policy->clear_clients_on_network_changes = false;
context_builder->set_reporting_policy(std::move(policy));
context_builder->set_network_error_logging_enabled(true);
}
#endif // BUILDFLAG(ENABLE_REPORTING)
}
void URLRequestContextConfig::ConfigureURLRequestContextBuilder(
......
......@@ -52,6 +52,7 @@ TEST(URLRequestContextConfigTest, TestExperimentalOptionParsing) {
"\"race_cert_verification\":true,"
"\"connection_options\":\"TIME,TBBR,REJ\"},"
"\"AsyncDNS\":{\"enable\":true},"
"\"NetworkErrorLogging\":{\"enable\":true},"
"\"UnknownOption\":{\"foo\":true},"
"\"HostResolverRules\":{\"host_resolver_rules\":"
"\"MAP * 127.0.0.1\"},"
......@@ -106,6 +107,13 @@ TEST(URLRequestContextConfigTest, TestExperimentalOptionParsing) {
EXPECT_TRUE(context->host_resolver()->GetDnsConfigAsValue());
#endif // defined(ENABLE_BUILT_IN_DNS)
#if BUILDFLAG(ENABLE_REPORTING)
// Check Reporting and Network Error Logging are enabled (can be disabled at
// build time).
EXPECT_TRUE(context->reporting_service());
EXPECT_TRUE(context->network_error_logging_delegate());
#endif // BUILDFLAG(ENABLE_REPORTING)
// Check IPv6 is disabled when on wifi.
EXPECT_TRUE(context->host_resolver()->GetNoIPv6OnWifi());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment