Commit 6a1ea3ac authored by Paul Jensen's avatar Paul Jensen Committed by Commit Bot

[Cronet] Add ability to set network thread priority to native API

Do so by sharing logic from Android and iOS.

Bug: 869406
Cq-Include-Trybots: master.tryserver.chromium.android:android_cronet_tester;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: If51d4acb13103818171bbd9e3f6ddc0e7bb9e294
Reviewed-on: https://chromium-review.googlesource.com/1185210
Commit-Queue: Paul Jensen <pauljensen@chromium.org>
Reviewed-by: default avatarMisha Efimov <mef@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585836}
parent 0f378fd1
...@@ -210,4 +210,15 @@ std::string CreateDefaultUserAgent(const std::string& partial_user_agent) { ...@@ -210,4 +210,15 @@ std::string CreateDefaultUserAgent(const std::string& partial_user_agent) {
return user_agent; return user_agent;
} }
void SetNetworkThreadPriorityOnNetworkThread(double priority) {
int priority_int = priority;
DCHECK_LE(priority_int, 19);
DCHECK_GE(priority_int, -20);
if (priority_int >= -20 && priority_int <= 19) {
JNIEnv* env = base::android::AttachCurrentThread();
cronet::Java_CronetLibraryLoader_setNetworkThreadPriorityOnNetworkThread(
env, priority_int);
}
}
} // namespace cronet } // namespace cronet
...@@ -250,7 +250,8 @@ static jlong JNI_CronetUrlRequestContext_CreateRequestContextConfig( ...@@ -250,7 +250,8 @@ static jlong JNI_CronetUrlRequestContext_CreateRequestContextConfig(
const JavaParamRef<jstring>& jexperimental_quic_connection_options, const JavaParamRef<jstring>& jexperimental_quic_connection_options,
jlong jmock_cert_verifier, jlong jmock_cert_verifier,
jboolean jenable_network_quality_estimator, jboolean jenable_network_quality_estimator,
jboolean jbypass_public_key_pinning_for_local_trust_anchors) { jboolean jbypass_public_key_pinning_for_local_trust_anchors,
jint jnetwork_thread_priority) {
return reinterpret_cast<jlong>(new URLRequestContextConfig( return reinterpret_cast<jlong>(new URLRequestContextConfig(
jquic_enabled, jquic_enabled,
ConvertNullableJavaStringToUTF8(env, jquic_default_user_agent_id), ConvertNullableJavaStringToUTF8(env, jquic_default_user_agent_id),
...@@ -265,7 +266,10 @@ static jlong JNI_CronetUrlRequestContext_CreateRequestContextConfig( ...@@ -265,7 +266,10 @@ static jlong JNI_CronetUrlRequestContext_CreateRequestContextConfig(
base::WrapUnique( base::WrapUnique(
reinterpret_cast<net::CertVerifier*>(jmock_cert_verifier)), reinterpret_cast<net::CertVerifier*>(jmock_cert_verifier)),
jenable_network_quality_estimator, jenable_network_quality_estimator,
jbypass_public_key_pinning_for_local_trust_anchors)); jbypass_public_key_pinning_for_local_trust_anchors,
jnetwork_thread_priority >= -20 && jnetwork_thread_priority <= 19
? base::Optional<double>(jnetwork_thread_priority)
: base::Optional<double>()));
} }
// Add a QUIC hint to a URLRequestContextConfig. // Add a QUIC hint to a URLRequestContextConfig.
......
...@@ -9,6 +9,7 @@ import android.os.ConditionVariable; ...@@ -9,6 +9,7 @@ import android.os.ConditionVariable;
import android.os.Handler; import android.os.Handler;
import android.os.HandlerThread; import android.os.HandlerThread;
import android.os.Looper; import android.os.Looper;
import android.os.Process;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
...@@ -174,6 +175,11 @@ public class CronetLibraryLoader { ...@@ -174,6 +175,11 @@ public class CronetLibraryLoader {
ensureInitialized(applicationContext, null); ensureInitialized(applicationContext, null);
} }
@CalledByNative
private static void setNetworkThreadPriorityOnNetworkThread(int priority) {
Process.setThreadPriority(priority);
}
// Native methods are implemented in cronet_library_loader.cc. // Native methods are implemented in cronet_library_loader.cc.
private static native void nativeCronetInitOnInitThread(); private static native void nativeCronetInitOnInitThread();
private static native String nativeGetCronetVersion(); private static native String nativeGetCronetVersion();
......
...@@ -72,7 +72,6 @@ public class CronetUrlRequestContext extends CronetEngineBase { ...@@ -72,7 +72,6 @@ public class CronetUrlRequestContext extends CronetEngineBase {
private Thread mNetworkThread; private Thread mNetworkThread;
private final boolean mNetworkQualityEstimatorEnabled; private final boolean mNetworkQualityEstimatorEnabled;
private final int mNetworkThreadPriority;
/** /**
* Locks operations on network quality listeners, because listener * Locks operations on network quality listeners, because listener
...@@ -150,7 +149,6 @@ public class CronetUrlRequestContext extends CronetEngineBase { ...@@ -150,7 +149,6 @@ public class CronetUrlRequestContext extends CronetEngineBase {
@UsedByReflection("CronetEngine.java") @UsedByReflection("CronetEngine.java")
public CronetUrlRequestContext(final CronetEngineBuilderImpl builder) { public CronetUrlRequestContext(final CronetEngineBuilderImpl builder) {
mNetworkQualityEstimatorEnabled = builder.networkQualityEstimatorEnabled(); mNetworkQualityEstimatorEnabled = builder.networkQualityEstimatorEnabled();
mNetworkThreadPriority = builder.threadPriority(Process.THREAD_PRIORITY_BACKGROUND);
CronetLibraryLoader.ensureInitialized(builder.getContext(), builder); CronetLibraryLoader.ensureInitialized(builder.getContext(), builder);
if (!IntegratedModeState.INTEGRATED_MODE_ENABLED) { if (!IntegratedModeState.INTEGRATED_MODE_ENABLED) {
nativeSetMinLogLevel(getLoggingLevel()); nativeSetMinLogLevel(getLoggingLevel());
...@@ -196,7 +194,8 @@ public class CronetUrlRequestContext extends CronetEngineBase { ...@@ -196,7 +194,8 @@ public class CronetUrlRequestContext extends CronetEngineBase {
builder.brotliEnabled(), builder.cacheDisabled(), builder.httpCacheMode(), builder.brotliEnabled(), builder.cacheDisabled(), builder.httpCacheMode(),
builder.httpCacheMaxSize(), builder.experimentalOptions(), builder.httpCacheMaxSize(), builder.experimentalOptions(),
builder.mockCertVerifier(), builder.networkQualityEstimatorEnabled(), builder.mockCertVerifier(), builder.networkQualityEstimatorEnabled(),
builder.publicKeyPinningBypassForLocalTrustAnchorsEnabled()); builder.publicKeyPinningBypassForLocalTrustAnchorsEnabled(),
builder.threadPriority(Process.THREAD_PRIORITY_BACKGROUND));
for (CronetEngineBuilderImpl.QuicHint quicHint : builder.quicHints()) { for (CronetEngineBuilderImpl.QuicHint quicHint : builder.quicHints()) {
nativeAddQuicHint(urlRequestContextConfig, quicHint.mHost, quicHint.mPort, nativeAddQuicHint(urlRequestContextConfig, quicHint.mHost, quicHint.mPort,
quicHint.mAlternatePort); quicHint.mAlternatePort);
...@@ -586,7 +585,6 @@ public class CronetUrlRequestContext extends CronetEngineBase { ...@@ -586,7 +585,6 @@ public class CronetUrlRequestContext extends CronetEngineBase {
// In integrated mode, network thread is shared from the host. // In integrated mode, network thread is shared from the host.
// Cronet shouldn't change the property of the thread. // Cronet shouldn't change the property of the thread.
Thread.currentThread().setName("ChromiumNet"); Thread.currentThread().setName("ChromiumNet");
Process.setThreadPriority(mNetworkThreadPriority);
} }
} }
...@@ -679,7 +677,7 @@ public class CronetUrlRequestContext extends CronetEngineBase { ...@@ -679,7 +677,7 @@ public class CronetUrlRequestContext extends CronetEngineBase {
boolean brotliEnabled, boolean disableCache, int httpCacheMode, long httpCacheMaxSize, boolean brotliEnabled, boolean disableCache, int httpCacheMode, long httpCacheMaxSize,
String experimentalOptions, long mockCertVerifier, String experimentalOptions, long mockCertVerifier,
boolean enableNetworkQualityEstimator, boolean enableNetworkQualityEstimator,
boolean bypassPublicKeyPinningForLocalTrustAnchors); boolean bypassPublicKeyPinningForLocalTrustAnchors, int networkThreadPriority);
private static native void nativeAddQuicHint( private static native void nativeAddQuicHint(
long urlRequestContextConfig, String host, int port, int alternatePort); long urlRequestContextConfig, String host, int port, int alternatePort);
......
...@@ -52,6 +52,11 @@ std::unique_ptr<net::ProxyResolutionService> CreateProxyResolutionService( ...@@ -52,6 +52,11 @@ std::unique_ptr<net::ProxyResolutionService> CreateProxyResolutionService(
// itself, if necessary. // itself, if necessary.
std::string CreateDefaultUserAgent(const std::string& partial_user_agent); std::string CreateDefaultUserAgent(const std::string& partial_user_agent);
// Set network thread priority to |priority|. Must be called on the network
// thread. On Android, corresponds to android.os.Process.setThreadPriority()
// values. On iOS, corresponds to NSThread::setThreadPriority values.
void SetNetworkThreadPriorityOnNetworkThread(double priority);
} // namespace cronet } // namespace cronet
#endif // COMPONENTS_CRONET_CRONET_GLOBAL_STATE_H_ #endif // COMPONENTS_CRONET_CRONET_GLOBAL_STATE_H_
...@@ -81,4 +81,8 @@ std::string CreateDefaultUserAgent(const std::string& partial_user_agent) { ...@@ -81,4 +81,8 @@ std::string CreateDefaultUserAgent(const std::string& partial_user_agent) {
return partial_user_agent; return partial_user_agent;
} }
void SetNetworkThreadPriorityOnNetworkThread(double priority) {
NOTIMPLEMENTED();
}
} // namespace cronet } // namespace cronet
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/values.h" #include "base/values.h"
#include "build/build_config.h"
#include "components/cronet/cronet_global_state.h" #include "components/cronet/cronet_global_state.h"
#include "components/cronet/cronet_prefs_manager.h" #include "components/cronet/cronet_prefs_manager.h"
#include "components/cronet/histogram_manager.h" #include "components/cronet/histogram_manager.h"
...@@ -281,6 +282,9 @@ void CronetURLRequestContext::NetworkTasks::Initialize( ...@@ -281,6 +282,9 @@ void CronetURLRequestContext::NetworkTasks::Initialize(
std::unique_ptr<URLRequestContextConfig> config(std::move(context_config_)); std::unique_ptr<URLRequestContextConfig> config(std::move(context_config_));
network_task_runner_ = network_task_runner; network_task_runner_ = network_task_runner;
if (config->network_thread_priority)
SetNetworkThreadPriorityOnNetworkThread(
config->network_thread_priority.value());
base::DisallowBlocking(); base::DisallowBlocking();
net::URLRequestContextBuilder context_builder; net::URLRequestContextBuilder context_builder;
context_builder.set_network_delegate( context_builder.set_network_delegate(
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "components/cronet/cronet_global_state.h"
#include "components/cronet/cronet_prefs_manager.h" #include "components/cronet/cronet_prefs_manager.h"
#include "components/cronet/histogram_manager.h" #include "components/cronet/histogram_manager.h"
#include "components/prefs/pref_filter.h" #include "components/prefs/pref_filter.h"
...@@ -304,10 +305,6 @@ void CronetEnvironment::InitializeOnNetworkThread() { ...@@ -304,10 +305,6 @@ void CronetEnvironment::InitializeOnNetworkThread() {
DCHECK(GetNetworkThreadTaskRunner()->BelongsToCurrentThread()); DCHECK(GetNetworkThreadTaskRunner()->BelongsToCurrentThread());
base::DisallowBlocking(); base::DisallowBlocking();
if (network_thread_priority_ != kKeepDefaultThreadPriority) {
SetNetworkThreadPriorityOnNetworkThread(network_thread_priority_);
}
static bool ssl_key_log_file_set = false; static bool ssl_key_log_file_set = false;
if (!ssl_key_log_file_set && !ssl_key_log_file_name_.empty()) { if (!ssl_key_log_file_set && !ssl_key_log_file_name_.empty()) {
ssl_key_log_file_set = true; ssl_key_log_file_set = true;
...@@ -341,6 +338,8 @@ void CronetEnvironment::InitializeOnNetworkThread() { ...@@ -341,6 +338,8 @@ void CronetEnvironment::InitializeOnNetworkThread() {
experimental_options_; // Set experimental Cronet options. experimental_options_; // Set experimental Cronet options.
context_config_builder.mock_cert_verifier = std::move( context_config_builder.mock_cert_verifier = std::move(
mock_cert_verifier_); // MockCertVerifier to use for testing purposes. mock_cert_verifier_); // MockCertVerifier to use for testing purposes.
if (network_thread_priority_ != kKeepDefaultThreadPriority)
context_config_builder.network_thread_priority = network_thread_priority_;
std::unique_ptr<URLRequestContextConfig> config = std::unique_ptr<URLRequestContextConfig> config =
context_config_builder.Build(); context_config_builder.Build();
...@@ -467,11 +466,7 @@ void CronetEnvironment::SetHostResolverRulesOnNetworkThread( ...@@ -467,11 +466,7 @@ void CronetEnvironment::SetHostResolverRulesOnNetworkThread(
void CronetEnvironment::SetNetworkThreadPriorityOnNetworkThread( void CronetEnvironment::SetNetworkThreadPriorityOnNetworkThread(
double priority) { double priority) {
DCHECK(GetNetworkThreadTaskRunner()->BelongsToCurrentThread()); DCHECK(GetNetworkThreadTaskRunner()->BelongsToCurrentThread());
DCHECK_LE(priority, 1.0); cronet::SetNetworkThreadPriorityOnNetworkThread(priority);
DCHECK_GE(priority, 0.0);
if (priority >= 0.0 && priority <= 1.0) {
[NSThread setThreadPriority:priority];
}
} }
std::string CronetEnvironment::getDefaultQuicUserAgentId() const { std::string CronetEnvironment::getDefaultQuicUserAgentId() const {
......
...@@ -87,4 +87,11 @@ std::string CreateDefaultUserAgent(const std::string& partial_user_agent) { ...@@ -87,4 +87,11 @@ std::string CreateDefaultUserAgent(const std::string& partial_user_agent) {
return web::BuildUserAgentFromProduct(partial_user_agent); return web::BuildUserAgentFromProduct(partial_user_agent);
} }
void SetNetworkThreadPriorityOnNetworkThread(double priority) {
DCHECK_LE(priority, 1.0);
DCHECK_GE(priority, 0.0);
if (priority >= 0.0 && priority <= 1.0)
[NSThread setThreadPriority:priority];
}
} // namespace cronet } // namespace cronet
...@@ -543,6 +543,14 @@ struct EngineParams { ...@@ -543,6 +543,14 @@ struct EngineParams {
*/ */
bool enable_public_key_pinning_bypass_for_local_trust_anchors = true; bool enable_public_key_pinning_bypass_for_local_trust_anchors = true;
/**
* Optional network thread priority. NAN indicates unset, use default.
* On Android, corresponds to android.os.Process.setThreadPriority() values.
* On iOS, corresponds to NSThread::setThreadPriority values.
* Do not specify for other platforms.
*/
double network_thread_priority = double.NAN;
/** /**
* JSON formatted experimental options to be used in Cronet Engine. * JSON formatted experimental options to be used in Cronet Engine.
*/ */
......
...@@ -145,6 +145,10 @@ Cronet_RESULT Cronet_EngineImpl::StartWithParams( ...@@ -145,6 +145,10 @@ Cronet_RESULT Cronet_EngineImpl::StartWithParams(
context_config_builder.experimental_options = params->experimental_options; context_config_builder.experimental_options = params->experimental_options;
context_config_builder.bypass_public_key_pinning_for_local_trust_anchors = context_config_builder.bypass_public_key_pinning_for_local_trust_anchors =
params->enable_public_key_pinning_bypass_for_local_trust_anchors; params->enable_public_key_pinning_bypass_for_local_trust_anchors;
if (!isnan(params->network_thread_priority)) {
context_config_builder.network_thread_priority =
params->network_thread_priority;
}
std::unique_ptr<URLRequestContextConfig> config = std::unique_ptr<URLRequestContextConfig> config =
context_config_builder.Build(); context_config_builder.Build();
......
...@@ -745,6 +745,10 @@ void Cronet_EngineParams_enable_public_key_pinning_bypass_for_local_trust_anchor ...@@ -745,6 +745,10 @@ void Cronet_EngineParams_enable_public_key_pinning_bypass_for_local_trust_anchor
Cronet_EngineParamsPtr self, Cronet_EngineParamsPtr self,
bool enable_public_key_pinning_bypass_for_local_trust_anchors); bool enable_public_key_pinning_bypass_for_local_trust_anchors);
CRONET_EXPORT CRONET_EXPORT
void Cronet_EngineParams_network_thread_priority_set(
Cronet_EngineParamsPtr self,
double network_thread_priority);
CRONET_EXPORT
void Cronet_EngineParams_experimental_options_set( void Cronet_EngineParams_experimental_options_set(
Cronet_EngineParamsPtr self, Cronet_EngineParamsPtr self,
Cronet_String experimental_options); Cronet_String experimental_options);
...@@ -790,6 +794,9 @@ CRONET_EXPORT ...@@ -790,6 +794,9 @@ CRONET_EXPORT
bool Cronet_EngineParams_enable_public_key_pinning_bypass_for_local_trust_anchors_get( bool Cronet_EngineParams_enable_public_key_pinning_bypass_for_local_trust_anchors_get(
Cronet_EngineParamsPtr self); Cronet_EngineParamsPtr self);
CRONET_EXPORT CRONET_EXPORT
double Cronet_EngineParams_network_thread_priority_get(
Cronet_EngineParamsPtr self);
CRONET_EXPORT
Cronet_String Cronet_EngineParams_experimental_options_get( Cronet_String Cronet_EngineParams_experimental_options_get(
Cronet_EngineParamsPtr self); Cronet_EngineParamsPtr self);
......
...@@ -303,6 +303,13 @@ void Cronet_EngineParams_enable_public_key_pinning_bypass_for_local_trust_anchor ...@@ -303,6 +303,13 @@ void Cronet_EngineParams_enable_public_key_pinning_bypass_for_local_trust_anchor
enable_public_key_pinning_bypass_for_local_trust_anchors; enable_public_key_pinning_bypass_for_local_trust_anchors;
} }
void Cronet_EngineParams_network_thread_priority_set(
Cronet_EngineParamsPtr self,
double network_thread_priority) {
DCHECK(self);
self->network_thread_priority = network_thread_priority;
}
void Cronet_EngineParams_experimental_options_set( void Cronet_EngineParams_experimental_options_set(
Cronet_EngineParamsPtr self, Cronet_EngineParamsPtr self,
Cronet_String experimental_options) { Cronet_String experimental_options) {
...@@ -398,6 +405,12 @@ bool Cronet_EngineParams_enable_public_key_pinning_bypass_for_local_trust_anchor ...@@ -398,6 +405,12 @@ bool Cronet_EngineParams_enable_public_key_pinning_bypass_for_local_trust_anchor
return self->enable_public_key_pinning_bypass_for_local_trust_anchors; return self->enable_public_key_pinning_bypass_for_local_trust_anchors;
} }
double Cronet_EngineParams_network_thread_priority_get(
Cronet_EngineParamsPtr self) {
DCHECK(self);
return self->network_thread_priority;
}
Cronet_String Cronet_EngineParams_experimental_options_get( Cronet_String Cronet_EngineParams_experimental_options_get(
Cronet_EngineParamsPtr self) { Cronet_EngineParamsPtr self) {
DCHECK(self); DCHECK(self);
......
...@@ -87,6 +87,7 @@ struct Cronet_EngineParams { ...@@ -87,6 +87,7 @@ struct Cronet_EngineParams {
std::vector<Cronet_QuicHint> quic_hints; std::vector<Cronet_QuicHint> quic_hints;
std::vector<Cronet_PublicKeyPins> public_key_pins; std::vector<Cronet_PublicKeyPins> public_key_pins;
bool enable_public_key_pinning_bypass_for_local_trust_anchors = true; bool enable_public_key_pinning_bypass_for_local_trust_anchors = true;
double network_thread_priority = std::numeric_limits<double>::quiet_NaN();
std::string experimental_options; std::string experimental_options;
private: private:
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "components/cronet/native/generated/cronet.idl_c.h" #include "components/cronet/native/generated/cronet.idl_c.h"
#include <math.h>
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -145,6 +147,13 @@ TEST_F(CronetStructTest, TestCronet_EngineParams) { ...@@ -145,6 +147,13 @@ TEST_F(CronetStructTest, TestCronet_EngineParams) {
first), first),
Cronet_EngineParams_enable_public_key_pinning_bypass_for_local_trust_anchors_get( Cronet_EngineParams_enable_public_key_pinning_bypass_for_local_trust_anchors_get(
second)); second));
Cronet_EngineParams_network_thread_priority_set(
second, Cronet_EngineParams_network_thread_priority_get(first));
EXPECT_TRUE(
Cronet_EngineParams_network_thread_priority_get(first) ==
Cronet_EngineParams_network_thread_priority_get(second) ||
isnan(Cronet_EngineParams_network_thread_priority_get(first)) &&
isnan(Cronet_EngineParams_network_thread_priority_get(second)));
Cronet_EngineParams_experimental_options_set( Cronet_EngineParams_experimental_options_set(
second, Cronet_EngineParams_experimental_options_get(first)); second, Cronet_EngineParams_experimental_options_get(first));
EXPECT_STREQ(Cronet_EngineParams_experimental_options_get(first), EXPECT_STREQ(Cronet_EngineParams_experimental_options_get(first),
......
...@@ -620,7 +620,9 @@ TEST_F(StaleHostResolverTest, CreatedByContext) { ...@@ -620,7 +620,9 @@ TEST_F(StaleHostResolverTest, CreatedByContext) {
// Enable network quality estimator. // Enable network quality estimator.
false, false,
// Enable Public Key Pinning bypass for local trust anchors. // Enable Public Key Pinning bypass for local trust anchors.
true); true,
// Optional network thread priority.
base::Optional<double>());
net::URLRequestContextBuilder builder; net::URLRequestContextBuilder builder;
net::NetLog net_log; net::NetLog net_log;
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include "{{variant_path}}_c.h" #include "{{variant_path}}_c.h"
#include <math.h>
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -34,7 +36,7 @@ class {{test_class_name}}StructTest : public ::testing::Test { ...@@ -34,7 +36,7 @@ class {{test_class_name}}StructTest : public ::testing::Test {
}; };
{%- for struct in structs %} {%- for struct in structs %}
{%- set struct_name = struct|get_name_for_kind %} {%- set struct_name = struct|get_name_for_kind %}
// Test Struct {{struct_name}} setters and getters. // Test Struct {{struct_name}} setters and getters.
TEST_F({{test_class_name}}StructTest, Test{{struct_name}}) { TEST_F({{test_class_name}}StructTest, Test{{struct_name}}) {
...@@ -42,25 +44,33 @@ TEST_F({{test_class_name}}StructTest, Test{{struct_name}}) { ...@@ -42,25 +44,33 @@ TEST_F({{test_class_name}}StructTest, Test{{struct_name}}) {
{{struct_name}}Ptr second = {{struct_name}}_Create(); {{struct_name}}Ptr second = {{struct_name}}_Create();
// Copy values from |first| to |second|. // Copy values from |first| to |second|.
{%- for packed_field in struct.packed.packed_fields_in_ordinal_order %} {%- for packed_field in struct.packed.packed_fields_in_ordinal_order %}
{%- set kind = packed_field.field.kind %} {%- set kind = packed_field.field.kind %}
{%- if kind|is_array_kind %} {%- if kind|is_array_kind %}
// TODO(mef): Test array |{{packed_field.field.name}}|. // TODO(mef): Test array |{{packed_field.field.name}}|.
{%- elif kind|is_struct_kind %} {%- elif kind|is_struct_kind %}
// TODO(mef): Test substruct |{{packed_field.field.name}}|. // TODO(mef): Test substruct |{{packed_field.field.name}}|.
{%- else %} {%- else %}
{{struct_name}}_{{packed_field.field.name}}_set(second, {{struct_name}}_{{packed_field.field.name}}_set(second,
{{struct_name}}_{{packed_field.field.name}}_get(first)); {{struct_name}}_{{packed_field.field.name}}_get(first));
{%- if kind|is_string_kind %} {%- if kind|cpp_wrapper_type == 'double' %}
EXPECT_TRUE(
{{struct_name}}_{{packed_field.field.name}}_get(first) ==
{{struct_name}}_{{packed_field.field.name}}_get(second) ||
isnan({{struct_name}}_{{packed_field.field.name}}_get(first)) &&
isnan({{struct_name}}_{{packed_field.field.name}}_get(second)));
{%- else %}
{%- if kind|is_string_kind %}
EXPECT_STREQ( EXPECT_STREQ(
{%- else %} {%- else %}
EXPECT_EQ( EXPECT_EQ(
{%- endif %} {%- endif %}
{{struct_name}}_{{packed_field.field.name}}_get(first), {{struct_name}}_{{packed_field.field.name}}_get(first),
{{struct_name}}_{{packed_field.field.name}}_get(second)); {{struct_name}}_{{packed_field.field.name}}_get(second));
{%- endif %} {%- endif %}
{%- endfor %} {%- endif %}
{%- endfor %}
{{struct_name}}_Destroy(first); {{struct_name}}_Destroy(first);
{{struct_name}}_Destroy(second); {{struct_name}}_Destroy(second);
} }
......
...@@ -232,7 +232,8 @@ URLRequestContextConfig::URLRequestContextConfig( ...@@ -232,7 +232,8 @@ URLRequestContextConfig::URLRequestContextConfig(
const std::string& experimental_options, const std::string& experimental_options,
std::unique_ptr<net::CertVerifier> mock_cert_verifier, std::unique_ptr<net::CertVerifier> mock_cert_verifier,
bool enable_network_quality_estimator, bool enable_network_quality_estimator,
bool bypass_public_key_pinning_for_local_trust_anchors) bool bypass_public_key_pinning_for_local_trust_anchors,
base::Optional<double> network_thread_priority)
: enable_quic(enable_quic), : enable_quic(enable_quic),
quic_user_agent_id(quic_user_agent_id), quic_user_agent_id(quic_user_agent_id),
enable_spdy(enable_spdy), enable_spdy(enable_spdy),
...@@ -247,6 +248,7 @@ URLRequestContextConfig::URLRequestContextConfig( ...@@ -247,6 +248,7 @@ URLRequestContextConfig::URLRequestContextConfig(
enable_network_quality_estimator(enable_network_quality_estimator), enable_network_quality_estimator(enable_network_quality_estimator),
bypass_public_key_pinning_for_local_trust_anchors( bypass_public_key_pinning_for_local_trust_anchors(
bypass_public_key_pinning_for_local_trust_anchors), bypass_public_key_pinning_for_local_trust_anchors),
network_thread_priority(network_thread_priority),
experimental_options(experimental_options) {} experimental_options(experimental_options) {}
URLRequestContextConfig::~URLRequestContextConfig() {} URLRequestContextConfig::~URLRequestContextConfig() {}
...@@ -689,7 +691,8 @@ URLRequestContextConfigBuilder::Build() { ...@@ -689,7 +691,8 @@ URLRequestContextConfigBuilder::Build() {
http_cache_max_size, load_disable_cache, storage_path, accept_language, http_cache_max_size, load_disable_cache, storage_path, accept_language,
user_agent, experimental_options, std::move(mock_cert_verifier), user_agent, experimental_options, std::move(mock_cert_verifier),
enable_network_quality_estimator, enable_network_quality_estimator,
bypass_public_key_pinning_for_local_trust_anchors); bypass_public_key_pinning_for_local_trust_anchors,
network_thread_priority);
} }
} // namespace cronet } // namespace cronet
...@@ -123,7 +123,12 @@ struct URLRequestContextConfig { ...@@ -123,7 +123,12 @@ struct URLRequestContextConfig {
// Enable network quality estimator. // Enable network quality estimator.
bool enable_network_quality_estimator, bool enable_network_quality_estimator,
// Enable bypassing of public key pinning for local trust anchors // Enable bypassing of public key pinning for local trust anchors
bool bypass_public_key_pinning_for_local_trust_anchors); bool bypass_public_key_pinning_for_local_trust_anchors,
// Optional network thread priority.
// On Android, corresponds to android.os.Process.setThreadPriority()
// values. On iOS, corresponds to NSThread::setThreadPriority values. Do
// not specify for other targets.
base::Optional<double> network_thread_priority);
~URLRequestContextConfig(); ~URLRequestContextConfig();
// Configures |context_builder| based on |this|. // Configures |context_builder| based on |this|.
...@@ -190,6 +195,11 @@ struct URLRequestContextConfig { ...@@ -190,6 +195,11 @@ struct URLRequestContextConfig {
// Preloaded NEL headers, to preconfigure Network Error Logging. // Preloaded NEL headers, to preconfigure Network Error Logging.
std::vector<PreloadedNelAndReportingHeader> preloaded_nel_headers; std::vector<PreloadedNelAndReportingHeader> preloaded_nel_headers;
// Optional network thread priority.
// On Android, corresponds to android.os.Process.setThreadPriority() values.
// On iOS, corresponds to NSThread::setThreadPriority values.
const base::Optional<double> network_thread_priority;
private: private:
// Parses experimental options and makes appropriate changes to settings in // Parses experimental options and makes appropriate changes to settings in
// the URLRequestContextConfig and URLRequestContextBuilder. // the URLRequestContextConfig and URLRequestContextBuilder.
...@@ -261,6 +271,12 @@ struct URLRequestContextConfigBuilder { ...@@ -261,6 +271,12 @@ struct URLRequestContextConfigBuilder {
// Enable public key pinning bypass for local trust anchors. // Enable public key pinning bypass for local trust anchors.
bool bypass_public_key_pinning_for_local_trust_anchors = true; bool bypass_public_key_pinning_for_local_trust_anchors = true;
// Optional network thread priority.
// On Android, corresponds to android.os.Process.setThreadPriority() values.
// On iOS, corresponds to NSThread::setThreadPriority values.
// Do not specify for other targets.
base::Optional<double> network_thread_priority;
private: private:
DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfigBuilder); DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfigBuilder);
}; };
......
...@@ -167,7 +167,9 @@ TEST(URLRequestContextConfigTest, TestExperimentalOptionParsing) { ...@@ -167,7 +167,9 @@ TEST(URLRequestContextConfigTest, TestExperimentalOptionParsing) {
// Enable network quality estimator. // Enable network quality estimator.
false, false,
// Enable Public Key Pinning bypass for local trust anchors. // Enable Public Key Pinning bypass for local trust anchors.
true); true,
// Optional network thread priority.
base::Optional<double>(42.0));
net::URLRequestContextBuilder builder; net::URLRequestContextBuilder builder;
net::NetLog net_log; net::NetLog net_log;
...@@ -272,6 +274,9 @@ TEST(URLRequestContextConfigTest, TestExperimentalOptionParsing) { ...@@ -272,6 +274,9 @@ TEST(URLRequestContextConfigTest, TestExperimentalOptionParsing) {
net::AddressList addresses; net::AddressList addresses;
EXPECT_EQ(net::OK, context->host_resolver()->ResolveFromCache( EXPECT_EQ(net::OK, context->host_resolver()->ResolveFromCache(
info, &addresses, net::NetLogWithSource())); info, &addresses, net::NetLogWithSource()));
EXPECT_TRUE(config.network_thread_priority);
EXPECT_EQ(42.0, config.network_thread_priority.value());
} }
TEST(URLRequestContextConfigTest, SetQuicServerMigrationOptions) { TEST(URLRequestContextConfigTest, SetQuicServerMigrationOptions) {
...@@ -307,7 +312,9 @@ TEST(URLRequestContextConfigTest, SetQuicServerMigrationOptions) { ...@@ -307,7 +312,9 @@ TEST(URLRequestContextConfigTest, SetQuicServerMigrationOptions) {
// Enable network quality estimator. // Enable network quality estimator.
false, false,
// Enable Public Key Pinning bypass for local trust anchors. // Enable Public Key Pinning bypass for local trust anchors.
true); true,
// Optional network thread priority.
base::Optional<double>());
net::URLRequestContextBuilder builder; net::URLRequestContextBuilder builder;
net::NetLog net_log; net::NetLog net_log;
...@@ -366,7 +373,9 @@ TEST(URLRequestContextConfigTest, ...@@ -366,7 +373,9 @@ TEST(URLRequestContextConfigTest,
// Enable network quality estimator. // Enable network quality estimator.
false, false,
// Enable Public Key Pinning bypass for local trust anchors. // Enable Public Key Pinning bypass for local trust anchors.
true); true,
// Optional network thread priority.
base::Optional<double>());
net::URLRequestContextBuilder builder; net::URLRequestContextBuilder builder;
net::NetLog net_log; net::NetLog net_log;
...@@ -426,7 +435,9 @@ TEST(URLRequestContextConfigTest, ...@@ -426,7 +435,9 @@ TEST(URLRequestContextConfigTest,
// Enable network quality estimator. // Enable network quality estimator.
false, false,
// Enable Public Key Pinning bypass for local trust anchors. // Enable Public Key Pinning bypass for local trust anchors.
true); true,
// Optional network thread priority.
base::Optional<double>());
net::URLRequestContextBuilder builder; net::URLRequestContextBuilder builder;
net::NetLog net_log; net::NetLog net_log;
...@@ -486,7 +497,9 @@ TEST(URLRequestContextConfigTest, ...@@ -486,7 +497,9 @@ TEST(URLRequestContextConfigTest,
// Enable network quality estimator. // Enable network quality estimator.
false, false,
// Enable Public Key Pinning bypass for local trust anchors. // Enable Public Key Pinning bypass for local trust anchors.
true); true,
// Optional network thread priority.
base::Optional<double>());
net::URLRequestContextBuilder builder; net::URLRequestContextBuilder builder;
net::NetLog net_log; net::NetLog net_log;
...@@ -540,7 +553,9 @@ TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationV2Options) { ...@@ -540,7 +553,9 @@ TEST(URLRequestContextConfigTest, SetQuicConnectionMigrationV2Options) {
// Enable network quality estimator. // Enable network quality estimator.
false, false,
// Enable Public Key Pinning bypass for local trust anchors. // Enable Public Key Pinning bypass for local trust anchors.
true); true,
// Optional network thread priority.
base::Optional<double>());
net::URLRequestContextBuilder builder; net::URLRequestContextBuilder builder;
net::NetLog net_log; net::NetLog net_log;
...@@ -596,7 +611,9 @@ TEST(URLRequestContextConfigTest, SetQuicHostWhitelist) { ...@@ -596,7 +611,9 @@ TEST(URLRequestContextConfigTest, SetQuicHostWhitelist) {
// Enable network quality estimator. // Enable network quality estimator.
false, false,
// Enable Public Key Pinning bypass for local trust anchors. // Enable Public Key Pinning bypass for local trust anchors.
true); true,
// Optional network thread priority.
base::Optional<double>());
net::URLRequestContextBuilder builder; net::URLRequestContextBuilder builder;
net::NetLog net_log; net::NetLog net_log;
...@@ -649,7 +666,9 @@ TEST(URLRequestContextConfigTest, SetQuicMaxTimeBeforeCryptoHandshake) { ...@@ -649,7 +666,9 @@ TEST(URLRequestContextConfigTest, SetQuicMaxTimeBeforeCryptoHandshake) {
// Enable network quality estimator. // Enable network quality estimator.
false, false,
// Enable Public Key Pinning bypass for local trust anchors. // Enable Public Key Pinning bypass for local trust anchors.
true); true,
// Optional network thread priority.
base::Optional<double>());
net::URLRequestContextBuilder builder; net::URLRequestContextBuilder builder;
net::NetLog net_log; net::NetLog net_log;
...@@ -700,7 +719,9 @@ TEST(URLURLRequestContextConfigTest, SetQuicConnectionOptions) { ...@@ -700,7 +719,9 @@ TEST(URLURLRequestContextConfigTest, SetQuicConnectionOptions) {
// Enable network quality estimator. // Enable network quality estimator.
false, false,
// Enable Public Key Pinning bypass for local trust anchors. // Enable Public Key Pinning bypass for local trust anchors.
true); true,
// Optional network thread priority.
base::Optional<double>());
net::URLRequestContextBuilder builder; net::URLRequestContextBuilder builder;
net::NetLog net_log; net::NetLog net_log;
...@@ -758,7 +779,9 @@ TEST(URLURLRequestContextConfigTest, SetAcceptLanguageAndUserAgent) { ...@@ -758,7 +779,9 @@ TEST(URLURLRequestContextConfigTest, SetAcceptLanguageAndUserAgent) {
// Enable network quality estimator. // Enable network quality estimator.
false, false,
// Enable Public Key Pinning bypass for local trust anchors. // Enable Public Key Pinning bypass for local trust anchors.
true); true,
// Optional network thread priority.
base::Optional<double>());
net::URLRequestContextBuilder builder; net::URLRequestContextBuilder builder;
net::NetLog net_log; net::NetLog net_log;
......
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