Commit 115d431f authored by Wez's avatar Wez Committed by Commit Bot

[cronet] Add support for building Cronet for Linux, Mac & Fuchsia.

This adds supports for building Cronet as a native shared library which can
be used through the C API generated from cronet.idl.

This is based on jamesr@'s work-in-progress to bring up the Cronet
library for Fuchsia:
https://chromium-review.googlesource.com/c/chromium/src/+/896389

Bug: 808075
Cq-Include-Trybots: master.tryserver.chromium.android:android_cronet_tester;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I598a8d1ca049e8c166e57546b7bdbf53e4659831
Reviewed-on: https://chromium-review.googlesource.com/914805
Commit-Queue: Wez <wez@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Reviewed-by: default avatarAndrei Kapishnikov <kapishnikov@chromium.org>
Reviewed-by: default avatarScott Graham <scottmg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537527}
parent 1f56bbed
...@@ -182,6 +182,14 @@ group("gn_all") { ...@@ -182,6 +182,14 @@ group("gn_all") {
] ]
} }
# TODO(https://crbug.com/812268): Fix Windows build, and enable it.
if (!is_ios && !is_android && !is_win) {
deps += [
"//components/cronet:cronet_tests",
"//components/cronet:cronet_unittests",
]
}
if (!is_ios && !is_fuchsia) { if (!is_ios && !is_fuchsia) {
deps += [ deps += [
"//chrome/test:telemetry_perf_unittests", "//chrome/test:telemetry_perf_unittests",
......
...@@ -65,3 +65,52 @@ source_set("cronet_common_unittests") { ...@@ -65,3 +65,52 @@ source_set("cronet_common_unittests") {
"url_request_context_config_unittest.cc", "url_request_context_config_unittest.cc",
] ]
} }
# For platforms on which the native Cronet library is used, build the library,
# a cronet_tests binary that exercises it, and a unit-tests binary.
# Android and iOS have their own platform-specific rules to build Cronet.
# TODO(https://crbug.com/812268): Fix Windows build, and enable it.
if (!is_ios && !is_android && !is_win) {
shared_library("cronet") {
deps = [
"//base",
# Explicitly add the exe_and_shlib_deps, otherwise the library will fail
# to link in component builds, due to missing libc++ symbols.
"//build/config:exe_and_shlib_deps",
"//components/cronet:cronet_common",
"//components/cronet/native:cronet_native_impl",
"//net",
]
sources = [
"cronet_global_state_stubs.cc",
]
}
test("cronet_tests") {
testonly = true
deps = [
":cronet",
"//components/cronet/native/test:cronet_native_tests",
"//testing/gtest:gtest_main",
]
}
test("cronet_unittests") {
testonly = true
deps = [
":cronet_common",
":cronet_common_unittests",
"//base",
"//components/cronet/native:cronet_native_unittests",
"//net",
]
sources = [
"cronet_global_state_stubs.cc",
]
}
}
...@@ -18,8 +18,8 @@ class ProxyResolutionService; ...@@ -18,8 +18,8 @@ class ProxyResolutionService;
namespace cronet { namespace cronet {
// Returns true when running on initialization thread. // Returns true when called on the initialization thread.
// Only callable after initialization thread is started. // May only be called after EnsureInitialized() has returned.
bool OnInitThread(); bool OnInitThread();
// Posts a task to run on initialization thread. Blocks until initialization // Posts a task to run on initialization thread. Blocks until initialization
...@@ -27,24 +27,29 @@ bool OnInitThread(); ...@@ -27,24 +27,29 @@ bool OnInitThread();
void PostTaskToInitThread(const base::Location& posted_from, void PostTaskToInitThread(const base::Location& posted_from,
base::OnceClosure task); base::OnceClosure task);
// Ensure that one time initialization of Cronet global state is done. Can be // Performs one-off initialization of Cronet global state, including creating,
// called from any thread. The initialization is performed on initialization // or binding to an existing thread, to run initialization and process
// thread. // network notifications on. The implementation must be thread-safe and
// idempotent, and must complete initialization before returning.
void EnsureInitialized(); void EnsureInitialized();
// 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. // system proxy settings. Cronet will call this API only after a prior call
// to EnsureInitialized() has returned.
std::unique_ptr<net::ProxyConfigService> CreateProxyConfigService( std::unique_ptr<net::ProxyConfigService> CreateProxyConfigService(
const scoped_refptr<base::SequencedTaskRunner>& io_task_runner); const scoped_refptr<base::SequencedTaskRunner>& io_task_runner);
// Creates a proxy service appropriate for this platform that fetches the // Creates a proxy service appropriate for this platform that fetches the
// system proxy settings. // system proxy settings. Cronet will call this API only after a prior call
// to EnsureInitialized() has returned.
std::unique_ptr<net::ProxyResolutionService> CreateProxyService( std::unique_ptr<net::ProxyResolutionService> CreateProxyService(
std::unique_ptr<net::ProxyConfigService> proxy_config_service, std::unique_ptr<net::ProxyConfigService> proxy_config_service,
net::NetLog* net_log); net::NetLog* net_log);
// Creates default User-Agent request value, combining optional // Creates default User-Agent request value, combining optional
// |partial_user_agent| with system-dependent values. // |partial_user_agent| with system-dependent values. This API may be invoked
// before EnsureInitialized(), in which case it may trigger initialization
// itself, if necessary.
std::string CreateDefaultUserAgent(const std::string& partial_user_agent); std::string CreateDefaultUserAgent(const std::string& partial_user_agent);
} // namespace cronet } // namespace cronet
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/cronet/cronet_global_state.h"
#include "base/at_exit.h"
#include "base/task_scheduler/post_task.h"
#include "base/task_scheduler/task_scheduler.h"
#include "net/proxy_resolution/proxy_config_service.h"
#include "net/proxy_resolution/proxy_service.h"
#include "url/url_util.h"
// This file provides minimal "stub" implementations of the Cronet global-state
// functions for the native library build, sufficient to have cronet_tests and
// cronet_unittests build.
namespace cronet {
namespace {
scoped_refptr<base::SingleThreadTaskRunner> InitializeAndCreateTaskRunner() {
// TODO(wez): Remove this once AtExitManager dependencies are gone.
ignore_result(new base::AtExitManager);
url::Initialize();
// Note that in component builds this TaskScheduler will be shared with the
// calling process, if it also depends on //base. In particular this means
// that the Cronet test binaries must avoid initializing or shutting-down the
// TaskScheduler themselves.
base::TaskScheduler::CreateAndStartWithDefaultParams("cronet");
return base::CreateSingleThreadTaskRunnerWithTraits({});
}
base::SingleThreadTaskRunner* InitTaskRunner() {
static scoped_refptr<base::SingleThreadTaskRunner> init_task_runner =
InitializeAndCreateTaskRunner();
return init_task_runner.get();
}
} // namespace
void EnsureInitialized() {
ignore_result(InitTaskRunner());
}
bool OnInitThread() {
return InitTaskRunner()->BelongsToCurrentThread();
}
void PostTaskToInitThread(const base::Location& posted_from,
base::OnceClosure task) {
InitTaskRunner()->PostTask(posted_from, std::move(task));
}
std::unique_ptr<net::ProxyConfigService> CreateProxyConfigService(
const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) {
// TODO(https://crbug.com/813226): Add ProxyConfigService support.
NOTIMPLEMENTED();
return nullptr;
}
std::unique_ptr<net::ProxyResolutionService> CreateProxyService(
std::unique_ptr<net::ProxyConfigService> proxy_config_service,
net::NetLog* net_log) {
// TODO(https://crbug.com/813226): Add ProxyResolutionService support.
NOTIMPLEMENTED();
return nullptr;
}
std::string CreateDefaultUserAgent(const std::string& partial_user_agent) {
return partial_user_agent;
}
} // namespace cronet
...@@ -31,7 +31,7 @@ source_set("cronet_native_headers") { ...@@ -31,7 +31,7 @@ source_set("cronet_native_headers") {
] ]
} }
# Cronet native API implementation. # Cross-platform portion of Cronet native API implementation.
source_set("cronet_native_impl") { source_set("cronet_native_impl") {
deps = [ deps = [
":cronet_native_headers", ":cronet_native_headers",
...@@ -73,6 +73,7 @@ source_set("cronet_native_unittests") { ...@@ -73,6 +73,7 @@ source_set("cronet_native_unittests") {
":cronet_native_impl", ":cronet_native_impl",
"//components/cronet/native/test:cronet_native_testutil", "//components/cronet/native/test:cronet_native_testutil",
"//net:test_support", "//net:test_support",
"//testing/gtest",
] ]
configs += [ ":cronet_native_include_config" ] configs += [ ":cronet_native_include_config" ]
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/test/scoped_task_environment.h" #include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "components/cronet/native/generated/cronet.idl_impl_interface.h" #include "components/cronet/native/generated/cronet.idl_impl_interface.h"
#include "components/cronet/native/include/cronet_c.h" #include "components/cronet/native/include/cronet_c.h"
#include "components/cronet/native/test/test_util.h" #include "components/cronet/native/test/test_util.h"
...@@ -41,7 +42,8 @@ class RunnablesTest : public ::testing::Test { ...@@ -41,7 +42,8 @@ class RunnablesTest : public ::testing::Test {
bool callback_called() const { return callback_called_; } bool callback_called() const { return callback_called_; }
base::test::ScopedTaskEnvironment scoped_task_environment_; // Provide a message loop for use by TestExecutor instances.
base::MessageLoop message_loop_;
private: private:
bool callback_called_ = false; bool callback_called_ = false;
...@@ -139,7 +141,7 @@ TEST_F(RunnablesTest, TestRunCallbackOnExecutor) { ...@@ -139,7 +141,7 @@ TEST_F(RunnablesTest, TestRunCallbackOnExecutor) {
new_location_url = "bad"; new_location_url = "bad";
Cronet_UrlRequestCallback_SetClientContext(callback, this); Cronet_UrlRequestCallback_SetClientContext(callback, this);
Cronet_Executor_Execute(executor, runnable); Cronet_Executor_Execute(executor, runnable);
scoped_task_environment_.RunUntilIdle(); base::RunLoop().RunUntilIdle();
ASSERT_TRUE(callback_called()); ASSERT_TRUE(callback_called());
Cronet_Executor_Destroy(executor); Cronet_Executor_Destroy(executor);
} }
...@@ -162,7 +164,7 @@ TEST_F(RunnablesTest, TestRunOnceClosureOnExecutor) { ...@@ -162,7 +164,7 @@ TEST_F(RunnablesTest, TestRunOnceClosureOnExecutor) {
/* request = */ nullptr, /* response_info = */ nullptr)); /* request = */ nullptr, /* response_info = */ nullptr));
Cronet_UrlRequestCallback_SetClientContext(callback, this); Cronet_UrlRequestCallback_SetClientContext(callback, this);
Cronet_Executor_Execute(executor, runnable); Cronet_Executor_Execute(executor, runnable);
scoped_task_environment_.RunUntilIdle(); base::RunLoop().RunUntilIdle();
ASSERT_TRUE(callback_called()); ASSERT_TRUE(callback_called());
Cronet_Executor_Destroy(executor); Cronet_Executor_Destroy(executor);
} }
...@@ -190,7 +192,7 @@ TEST_F(RunnablesTest, TestCronetBuffer) { ...@@ -190,7 +192,7 @@ TEST_F(RunnablesTest, TestCronetBuffer) {
/* response_info = */ nullptr, buffer, /* bytes_read = */ 0)); /* response_info = */ nullptr, buffer, /* bytes_read = */ 0));
Cronet_UrlRequestCallback_SetClientContext(callback, this); Cronet_UrlRequestCallback_SetClientContext(callback, this);
Cronet_Executor_Execute(executor, runnable); Cronet_Executor_Execute(executor, runnable);
scoped_task_environment_.RunUntilIdle(); base::RunLoop().RunUntilIdle();
ASSERT_TRUE(callback_called()); ASSERT_TRUE(callback_called());
Cronet_Executor_Destroy(executor); Cronet_Executor_Destroy(executor);
} }
......
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/test/scoped_task_environment.h" #include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "components/cronet/native/test/test_util.h" #include "components/cronet/native/test/test_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -22,7 +23,8 @@ class BufferTest : public ::testing::Test { ...@@ -22,7 +23,8 @@ class BufferTest : public ::testing::Test {
Cronet_BufferPtr buffer); Cronet_BufferPtr buffer);
bool on_destroy_called() const { return on_destroy_called_; } bool on_destroy_called() const { return on_destroy_called_; }
base::test::ScopedTaskEnvironment scoped_task_environment_; // Provide a message loop for use by TestExecutor instances.
base::MessageLoop message_loop_;
private: private:
void set_on_destroy_called(bool value) { on_destroy_called_ = value; } void set_on_destroy_called(bool value) { on_destroy_called_ = value; }
...@@ -116,7 +118,7 @@ TEST_F(BufferTest, TestCronetBufferAsync) { ...@@ -116,7 +118,7 @@ TEST_F(BufferTest, TestCronetBufferAsync) {
Cronet_Runnable_CreateWith(TestRunnable_DestroyBuffer); Cronet_Runnable_CreateWith(TestRunnable_DestroyBuffer);
Cronet_Runnable_SetClientContext(runnable, buffer); Cronet_Runnable_SetClientContext(runnable, buffer);
Cronet_Executor_Execute(executor, runnable); Cronet_Executor_Execute(executor, runnable);
scoped_task_environment_.RunUntilIdle(); base::RunLoop().RunUntilIdle();
ASSERT_TRUE(on_destroy_called()); ASSERT_TRUE(on_destroy_called());
Cronet_Executor_Destroy(executor); Cronet_Executor_Destroy(executor);
} }
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/test/scoped_task_environment.h" #include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "components/cronet/native/test/test_util.h" #include "components/cronet/native/test/test_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
......
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/test/scoped_task_environment.h" #include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "components/cronet/native/test/test_util.h" #include "components/cronet/native/test/test_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -21,7 +22,8 @@ class ExecutorsTest : public ::testing::Test { ...@@ -21,7 +22,8 @@ class ExecutorsTest : public ::testing::Test {
static void TestRunnable_Run(Cronet_RunnablePtr self); static void TestRunnable_Run(Cronet_RunnablePtr self);
bool runnable_called() const { return runnable_called_; } bool runnable_called() const { return runnable_called_; }
base::test::ScopedTaskEnvironment scoped_task_environment_; // Provide a message loop for use by TestExecutor instances.
base::MessageLoop message_loop_;
private: private:
void set_runnable_called(bool value) { runnable_called_ = value; } void set_runnable_called(bool value) { runnable_called_ = value; }
...@@ -57,7 +59,7 @@ TEST_F(ExecutorsTest, TestCustom) { ...@@ -57,7 +59,7 @@ TEST_F(ExecutorsTest, TestCustom) {
Cronet_Executor_CreateWith(TestExecutor_Execute); Cronet_Executor_CreateWith(TestExecutor_Execute);
Cronet_Executor_Execute(executor, runnable); Cronet_Executor_Execute(executor, runnable);
Cronet_Executor_Destroy(executor); Cronet_Executor_Destroy(executor);
scoped_task_environment_.RunUntilIdle(); base::RunLoop().RunUntilIdle();
ASSERT_TRUE(runnable_called()); ASSERT_TRUE(runnable_called());
} }
...@@ -69,7 +71,7 @@ TEST_F(ExecutorsTest, TestTestExecutor) { ...@@ -69,7 +71,7 @@ TEST_F(ExecutorsTest, TestTestExecutor) {
Cronet_ExecutorPtr executor = cronet::test::CreateTestExecutor(); Cronet_ExecutorPtr executor = cronet::test::CreateTestExecutor();
Cronet_Executor_Execute(executor, runnable); Cronet_Executor_Execute(executor, runnable);
Cronet_Executor_Destroy(executor); Cronet_Executor_Destroy(executor);
scoped_task_environment_.RunUntilIdle(); base::RunLoop().RunUntilIdle();
ASSERT_TRUE(runnable_called()); ASSERT_TRUE(runnable_called());
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/task_scheduler/post_task.h" #include "base/threading/sequenced_task_runner_handle.h"
#include "components/cronet/native/generated/cronet.idl_c.h" #include "components/cronet/native/generated/cronet.idl_c.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/cert/mock_cert_verifier.h" #include "net/cert/mock_cert_verifier.h"
...@@ -20,7 +20,8 @@ void TestExecutor_Execute(Cronet_ExecutorPtr self, ...@@ -20,7 +20,8 @@ void TestExecutor_Execute(Cronet_ExecutorPtr self,
Cronet_RunnablePtr runnable) { Cronet_RunnablePtr runnable) {
CHECK(self); CHECK(self);
DVLOG(1) << "Post Task"; DVLOG(1) << "Post Task";
base::PostTask(FROM_HERE, base::BindOnce(Cronet_Runnable_Run, runnable)); base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(Cronet_Runnable_Run, runnable));
} }
} // namespace } // namespace
......
...@@ -8,8 +8,9 @@ ...@@ -8,8 +8,9 @@
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/test/scoped_task_environment.h"
#include "components/cronet/native/test/test_url_request_callback.h" #include "components/cronet/native/test/test_url_request_callback.h"
#include "components/cronet/native/test/test_util.h" #include "components/cronet/native/test/test_util.h"
#include "components/cronet/test/test_server.h" #include "components/cronet/test/test_server.h"
...@@ -104,7 +105,8 @@ class UrlRequestTest : public ::testing::Test { ...@@ -104,7 +105,8 @@ class UrlRequestTest : public ::testing::Test {
} }
protected: protected:
base::test::ScopedTaskEnvironment scoped_task_environment_; // Provide a message loop for use by TestExecutor instances.
base::MessageLoop message_loop_;
private: private:
DISALLOW_COPY_AND_ASSIGN(UrlRequestTest); DISALLOW_COPY_AND_ASSIGN(UrlRequestTest);
......
...@@ -71,6 +71,7 @@ enum AddressListDeltaType { ...@@ -71,6 +71,7 @@ enum AddressListDeltaType {
// Compares two AddressLists to see how similar or different their addresses // Compares two AddressLists to see how similar or different their addresses
// are. (See |AddressListDeltaType| for details of exactly what's checked.) // are. (See |AddressListDeltaType| for details of exactly what's checked.)
NET_EXPORT
AddressListDeltaType FindAddressListDeltaType(const AddressList& a, AddressListDeltaType FindAddressListDeltaType(const AddressList& a,
const AddressList& b); const AddressList& b);
......
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