mirror of
https://github.com/klzgrad/naiveproxy.git
synced 2024-11-24 06:16:30 +03:00
cronet: Support setting feature list from experimental option
This commit is contained in:
parent
8edf04ca34
commit
f23eaeae21
@ -146,7 +146,8 @@ void PostTaskToInitThread(const base::Location& posted_from,
|
|||||||
g_init_task_executor->task_runner()->PostTask(posted_from, std::move(task));
|
g_init_task_executor->task_runner()->PostTask(posted_from, std::move(task));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnsureInitialized() {
|
void EnsureInitialized(const char* /*enable_features*/,
|
||||||
|
const char* /*disable_features*/) {
|
||||||
if (g_init_task_executor) {
|
if (g_init_task_executor) {
|
||||||
// Ensure that init is done on the init thread.
|
// Ensure that init is done on the init thread.
|
||||||
g_init_thread_init_done.Wait();
|
g_init_thread_init_done.Wait();
|
||||||
|
@ -31,7 +31,8 @@ void PostTaskToInitThread(const base::Location& posted_from,
|
|||||||
// or binding to an existing thread, to run initialization and process
|
// or binding to an existing thread, to run initialization and process
|
||||||
// network notifications on. The implementation must be thread-safe and
|
// network notifications on. The implementation must be thread-safe and
|
||||||
// idempotent, and must complete initialization before returning.
|
// idempotent, and must complete initialization before returning.
|
||||||
void EnsureInitialized();
|
void EnsureInitialized(const char* enable_features = nullptr,
|
||||||
|
const char* disable_features = nullptr);
|
||||||
|
|
||||||
// Creates a proxy config service appropriate for this platform that fetches the
|
// Creates a proxy config service appropriate for this platform that fetches the
|
||||||
// system proxy settings. Cronet will call this API only after a prior call
|
// system proxy settings. Cronet will call this API only after a prior call
|
||||||
|
@ -21,14 +21,18 @@ namespace cronet {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
scoped_refptr<base::SingleThreadTaskRunner> InitializeAndCreateTaskRunner() {
|
scoped_refptr<base::SingleThreadTaskRunner> InitializeAndCreateTaskRunner(
|
||||||
|
const char* enable_features,
|
||||||
|
const char* disable_features) {
|
||||||
// Cronet tests sets AtExitManager as part of TestSuite, so statically linked
|
// Cronet tests sets AtExitManager as part of TestSuite, so statically linked
|
||||||
// library is not allowed to set its own.
|
// library is not allowed to set its own.
|
||||||
#if !defined(CRONET_TESTS_IMPLEMENTATION)
|
#if !defined(CRONET_TESTS_IMPLEMENTATION)
|
||||||
std::ignore = new base::AtExitManager;
|
std::ignore = new base::AtExitManager;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
base::FeatureList::InitializeInstance(std::string(), std::string());
|
base::FeatureList::InitializeInstance(
|
||||||
|
enable_features ? enable_features : "",
|
||||||
|
disable_features ? disable_features : "");
|
||||||
|
|
||||||
// Note that in component builds this ThreadPoolInstance will be shared with
|
// Note that in component builds this ThreadPoolInstance will be shared with
|
||||||
// the calling process, if it also depends on //base. In particular this means
|
// the calling process, if it also depends on //base. In particular this means
|
||||||
@ -39,16 +43,19 @@ scoped_refptr<base::SingleThreadTaskRunner> InitializeAndCreateTaskRunner() {
|
|||||||
return base::ThreadPool::CreateSingleThreadTaskRunner({});
|
return base::ThreadPool::CreateSingleThreadTaskRunner({});
|
||||||
}
|
}
|
||||||
|
|
||||||
base::SingleThreadTaskRunner* InitTaskRunner() {
|
base::SingleThreadTaskRunner* InitTaskRunner(
|
||||||
|
const char* enable_features = nullptr,
|
||||||
|
const char* disable_features = nullptr) {
|
||||||
static scoped_refptr<base::SingleThreadTaskRunner> init_task_runner =
|
static scoped_refptr<base::SingleThreadTaskRunner> init_task_runner =
|
||||||
InitializeAndCreateTaskRunner();
|
InitializeAndCreateTaskRunner(enable_features, disable_features);
|
||||||
return init_task_runner.get();
|
return init_task_runner.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void EnsureInitialized() {
|
void EnsureInitialized(const char* enable_features,
|
||||||
std::ignore = InitTaskRunner();
|
const char* disable_features) {
|
||||||
|
std::ignore = InitTaskRunner(enable_features, disable_features);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OnInitThread() {
|
bool OnInitThread() {
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "base/base_switches.h"
|
||||||
#include "base/bind.h"
|
#include "base/bind.h"
|
||||||
#include "base/callback_helpers.h"
|
#include "base/callback_helpers.h"
|
||||||
#include "base/files/file_path.h"
|
#include "base/files/file_path.h"
|
||||||
@ -102,6 +103,25 @@ Cronet_EngineImpl::~Cronet_EngineImpl() {
|
|||||||
|
|
||||||
Cronet_RESULT Cronet_EngineImpl::StartWithParams(
|
Cronet_RESULT Cronet_EngineImpl::StartWithParams(
|
||||||
Cronet_EngineParamsPtr params) {
|
Cronet_EngineParamsPtr params) {
|
||||||
|
absl::optional<base::Value::DictStorage> experimental_options =
|
||||||
|
URLRequestContextConfig::ParseExperimentalOptions(
|
||||||
|
params->experimental_options);
|
||||||
|
if (experimental_options) {
|
||||||
|
const auto& iter = experimental_options->find("feature_list");
|
||||||
|
if (iter != experimental_options->end()) {
|
||||||
|
const base::Value& feature_list = iter->second;
|
||||||
|
if (feature_list.is_dict()) {
|
||||||
|
const std::string* enable_features =
|
||||||
|
feature_list.GetDict().FindString(switches::kEnableFeatures);
|
||||||
|
const std::string* disable_features =
|
||||||
|
feature_list.GetDict().FindString(switches::kDisableFeatures);
|
||||||
|
cronet::EnsureInitialized(
|
||||||
|
enable_features ? enable_features->c_str() : nullptr,
|
||||||
|
disable_features ? disable_features->c_str() : nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cronet::EnsureInitialized();
|
cronet::EnsureInitialized();
|
||||||
base::AutoLock lock(lock_);
|
base::AutoLock lock(lock_);
|
||||||
|
|
||||||
|
@ -761,6 +761,15 @@ void URLRequestContextConfig::SetContextBuilderExperimentalOptions(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Handled in CronetContext::NetworkTasks::BuildDefaultURLRequestContext.
|
// Handled in CronetContext::NetworkTasks::BuildDefaultURLRequestContext.
|
||||||
|
} else if (iter.first == "feature_list") {
|
||||||
|
if (!iter.second.is_dict()) {
|
||||||
|
LOG(ERROR) << "\"" << iter.first << "\" config params \"" << iter.second
|
||||||
|
<< "\" is not a dictionary value";
|
||||||
|
effective_experimental_options.erase(iter.first);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Already handled in Cronet_EngineImpl::StartWithParams.
|
||||||
|
// Only checks and reports errors here.
|
||||||
} else {
|
} else {
|
||||||
LOG(WARNING) << "Unrecognized Cronet experimental option \"" << iter.first
|
LOG(WARNING) << "Unrecognized Cronet experimental option \"" << iter.first
|
||||||
<< "\" with params \"" << iter.second;
|
<< "\" with params \"" << iter.second;
|
||||||
|
@ -216,6 +216,12 @@ struct URLRequestContextConfig {
|
|||||||
// not specify for other targets.
|
// not specify for other targets.
|
||||||
absl::optional<double> network_thread_priority);
|
absl::optional<double> network_thread_priority);
|
||||||
|
|
||||||
|
// Parses experimental options from their JSON format to the format used
|
||||||
|
// internally.
|
||||||
|
// Returns an empty optional if the operation was unsuccessful.
|
||||||
|
static absl::optional<base::Value::DictStorage> ParseExperimentalOptions(
|
||||||
|
std::string unparsed_experimental_options);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
URLRequestContextConfig(
|
URLRequestContextConfig(
|
||||||
// Enable QUIC.
|
// Enable QUIC.
|
||||||
@ -253,12 +259,6 @@ struct URLRequestContextConfig {
|
|||||||
// not specify for other targets.
|
// not specify for other targets.
|
||||||
absl::optional<double> network_thread_priority);
|
absl::optional<double> network_thread_priority);
|
||||||
|
|
||||||
// Parses experimental options from their JSON format to the format used
|
|
||||||
// internally.
|
|
||||||
// Returns an empty optional if the operation was unsuccessful.
|
|
||||||
static absl::optional<base::Value::DictStorage> ParseExperimentalOptions(
|
|
||||||
std::string unparsed_experimental_options);
|
|
||||||
|
|
||||||
// Makes appropriate changes to settings in |this|.
|
// Makes appropriate changes to settings in |this|.
|
||||||
void SetContextConfigExperimentalOptions();
|
void SetContextConfigExperimentalOptions();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user