From e5da6098907e92bbd463040061834ca8cd17a7df Mon Sep 17 00:00:00 2001 From: Victor Vasiliev Date: Thu, 15 Aug 2019 23:14:46 +0000 Subject: [PATCH] Remove url::Initialize() and rename url::Shutdown() to url::ResetForTests() This is a follow-up cleanup to https://chromium-review.googlesource.com/c/chromium/src/+/1600497 Change-Id: I27c3719322e96a5c1fca9aad761bb22536fed610 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1754232 Commit-Queue: Victor Vasiliev Reviewed-by: Daniel Cheng Reviewed-by: Nico Weber Reviewed-by: Scott Violet Cr-Commit-Position: refs/heads/master@{#687473} --- android_webview/lib/webview_jni_onload.cc | 6 ------ components/cronet/android/cronet_library_loader.cc | 2 -- components/cronet/cronet_global_state_stubs.cc | 3 --- components/cronet/ios/cronet_global_state_ios.mm | 3 --- components/test/components_test_suite.cc | 2 +- content/public/test/blink_test_environment.cc | 5 ----- content/public/test/test_utils.cc | 3 +-- google_apis/drive/drive_api_url_generator_unittest.cc | 2 +- .../renderer/platform/weborigin/security_origin_test.cc | 2 +- url/origin_unittest.cc | 4 ++-- url/scheme_host_port_unittest.cc | 2 +- url/url_util.cc | 6 +----- url/url_util.h | 5 +---- url/url_util_unittest.cc | 4 ++-- 14 files changed, 11 insertions(+), 38 deletions(-) diff --git a/android_webview/lib/webview_jni_onload.cc b/android_webview/lib/webview_jni_onload.cc index 139f35ec40dcdf..1a59dbb45fc81c 100644 --- a/android_webview/lib/webview_jni_onload.cc +++ b/android_webview/lib/webview_jni_onload.cc @@ -9,7 +9,6 @@ #include "components/version_info/version_info_values.h" #include "content/public/app/content_jni_onload.h" #include "content/public/app/content_main.h" -#include "url/url_util.h" namespace android_webview { @@ -19,11 +18,6 @@ bool OnJNIOnLoadInit() { base::android::SetVersionNumber(PRODUCT_VERSION); content::SetContentMainDelegate(new android_webview::AwMainDelegate()); - - // Initialize url lib here while we are still single-threaded, in case we use - // CookieManager before initializing Chromium (which would normally have done - // this). It's safe to call this multiple times. - url::Initialize(); return true; } diff --git a/components/cronet/android/cronet_library_loader.cc b/components/cronet/android/cronet_library_loader.cc index 10a009ce099971..519d0c3ebd6ad9 100644 --- a/components/cronet/android/cronet_library_loader.cc +++ b/components/cronet/android/cronet_library_loader.cc @@ -34,7 +34,6 @@ #include "net/proxy_resolution/proxy_resolution_service.h" #include "third_party/zlib/zlib.h" #include "url/buildflags.h" -#include "url/url_util.h" #if !BUILDFLAG(USE_PLATFORM_ICU_ALTERNATIVES) #include "base/i18n/icu_util.h" // nogncheck @@ -74,7 +73,6 @@ void NativeInit() { if (!base::ThreadPoolInstance::Get()) base::ThreadPoolInstance::CreateAndStartWithDefaultParams("Cronet"); - url::Initialize(); } } // namespace diff --git a/components/cronet/cronet_global_state_stubs.cc b/components/cronet/cronet_global_state_stubs.cc index b0cedb382b201e..61b7f815c5c35e 100644 --- a/components/cronet/cronet_global_state_stubs.cc +++ b/components/cronet/cronet_global_state_stubs.cc @@ -10,7 +10,6 @@ #include "base/task/thread_pool/thread_pool.h" #include "net/proxy_resolution/proxy_config_service.h" #include "net/proxy_resolution/proxy_resolution_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 @@ -29,8 +28,6 @@ scoped_refptr InitializeAndCreateTaskRunner() { base::FeatureList::InitializeInstance(std::string(), std::string()); - url::Initialize(); - // Note that in component builds this ThreadPoolInstance 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 diff --git a/components/cronet/ios/cronet_global_state_ios.mm b/components/cronet/ios/cronet_global_state_ios.mm index 4e625d49dfec20..b38c0598d4f97e 100644 --- a/components/cronet/ios/cronet_global_state_ios.mm +++ b/components/cronet/ios/cronet_global_state_ios.mm @@ -14,7 +14,6 @@ #include "ios/web/public/init/ios_global_state_configuration.h" #include "net/proxy_resolution/proxy_config_service.h" #include "net/proxy_resolution/proxy_resolution_service.h" -#include "url/url_util.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "This file requires ARC support." @@ -31,8 +30,6 @@ void InitializeOnMainThread() { ios_global_state::Create(create_params); ios_global_state::StartThreadPool(); - url::Initialize(); - ios_global_state::BuildSingleThreadTaskExecutor(); ios_global_state::CreateNetworkChangeNotifier(); } diff --git a/components/test/components_test_suite.cc b/components/test/components_test_suite.cc index 5206ea6ce5ca52..da287d932a0afc 100644 --- a/components/test/components_test_suite.cc +++ b/components/test/components_test_suite.cc @@ -55,7 +55,7 @@ class ComponentsTestSuite : public base::TestSuite { mojo::core::Init(); // Before registering any schemes, clear GURL's internal state. - url::Shutdown(); + url::ResetForTests(); #if !defined(OS_IOS) gl::GLSurfaceTestSupport::InitializeOneOff(); diff --git a/content/public/test/blink_test_environment.cc b/content/public/test/blink_test_environment.cc index 98bd3a4cf44b65..06e3b51cc76d82 100644 --- a/content/public/test/blink_test_environment.cc +++ b/content/public/test/blink_test_environment.cc @@ -19,7 +19,6 @@ #include "third_party/blink/public/platform/web_cache.h" #include "third_party/blink/public/platform/web_runtime_features.h" #include "third_party/blink/public/web/blink.h" -#include "url/url_util.h" #if defined(OS_WIN) #include "ui/display/win/dpi.h" @@ -81,10 +80,6 @@ void SetUpBlinkTestEnvironment() { display::win::SetDefaultDeviceScaleFactor(1.0f); #endif - // Explicitly initialize the GURL library before spawning any threads. - // Otherwise crash may happend when different threads try to create a GURL - // at same time. - url::Initialize(); test_environment = new TestEnvironment; } diff --git a/content/public/test/test_utils.cc b/content/public/test/test_utils.cc index 25d9e746a3445e..523f9e525293e5 100644 --- a/content/public/test/test_utils.cc +++ b/content/public/test/test_utils.cc @@ -200,9 +200,8 @@ void IsolateAllSitesForTesting(base::CommandLine* command_line) { } void ResetSchemesAndOriginsWhitelist() { - url::Shutdown(); + url::ResetForTests(); RegisterContentSchemes(false); - url::Initialize(); } GURL GetWebUIURL(const std::string& host) { diff --git a/google_apis/drive/drive_api_url_generator_unittest.cc b/google_apis/drive/drive_api_url_generator_unittest.cc index 596929bfdfc75e..2629141a72b247 100644 --- a/google_apis/drive/drive_api_url_generator_unittest.cc +++ b/google_apis/drive/drive_api_url_generator_unittest.cc @@ -29,7 +29,7 @@ class DriveApiUrlGeneratorTest : public testing::Test { url::AddStandardScheme("chrome-extension", url::SCHEME_WITH_HOST); } - ~DriveApiUrlGeneratorTest() override { url::Shutdown(); } + ~DriveApiUrlGeneratorTest() override { url::ResetForTests(); } protected: DriveApiUrlGenerator url_generator_; diff --git a/third_party/blink/renderer/platform/weborigin/security_origin_test.cc b/third_party/blink/renderer/platform/weborigin/security_origin_test.cc index b5bd179c1710d6..040a9897072c56 100644 --- a/third_party/blink/renderer/platform/weborigin/security_origin_test.cc +++ b/third_party/blink/renderer/platform/weborigin/security_origin_test.cc @@ -865,7 +865,7 @@ TEST_F(SecurityOriginTest, NonStandardSchemeWithAndroidWebViewHack) { EXPECT_EQ("cow", origin->Protocol()); EXPECT_EQ("", origin->Host()); EXPECT_EQ(0, origin->Port()); - url::Shutdown(); + url::ResetForTests(); } TEST_F(SecurityOriginTest, OpaqueIsolatedCopy) { diff --git a/url/origin_unittest.cc b/url/origin_unittest.cc index 2f65757a70ba51..978a83301a87fa 100644 --- a/url/origin_unittest.cc +++ b/url/origin_unittest.cc @@ -55,7 +55,7 @@ class OriginTest : public ::testing::Test { AddStandardScheme("standard-but-noaccess", SchemeType::SCHEME_WITH_HOST); AddNoAccessScheme("standard-but-noaccess"); } - void TearDown() override { url::Shutdown(); } + void TearDown() override { url::ResetForTests(); } ::testing::AssertionResult DoEqualityComparisons(const url::Origin& a, const url::Origin& b, @@ -667,7 +667,7 @@ TEST_F(OriginTest, NonStandardSchemeWithAndroidWebViewHack) { EXPECT_EQ("cow", origin.scheme()); EXPECT_EQ("", origin.host()); EXPECT_EQ(0, origin.port()); - Shutdown(); + ResetForTests(); } TEST_F(OriginTest, CanBeDerivedFrom) { diff --git a/url/scheme_host_port_unittest.cc b/url/scheme_host_port_unittest.cc index ed1aaec9339988..874c100767b7ac 100644 --- a/url/scheme_host_port_unittest.cc +++ b/url/scheme_host_port_unittest.cc @@ -18,7 +18,7 @@ class SchemeHostPortTest : public testing::Test { SchemeHostPortTest() = default; ~SchemeHostPortTest() override { // Reset any added schemes. - url::Shutdown(); + url::ResetForTests(); } private: diff --git a/url/url_util.cc b/url/url_util.cc index 63613aae47b937..927ed7222184fc 100644 --- a/url/url_util.cc +++ b/url/url_util.cc @@ -494,11 +494,7 @@ void DoAddSchemeWithType(const char* new_scheme, } // namespace -void Initialize() { - // Deprecated. -} - -void Shutdown() { +void ResetForTests() { *GetSchemeRegistry() = SchemeRegistry(); } diff --git a/url/url_util.h b/url/url_util.h index b618999d9d0aa3..3ea449b1b60fe8 100644 --- a/url/url_util.h +++ b/url/url_util.h @@ -19,11 +19,8 @@ namespace url { // Init ------------------------------------------------------------------------ -// Deprecated. Does not do anything. -COMPONENT_EXPORT(URL) void Initialize(); - // Resets all custom schemes to the default values. Not thread-safe. -COMPONENT_EXPORT(URL) void Shutdown(); +COMPONENT_EXPORT(URL) void ResetForTests(); // Schemes --------------------------------------------------------------------- diff --git a/url/url_util_unittest.cc b/url/url_util_unittest.cc index da578e815404b5..aed5fa899ac8ee 100644 --- a/url/url_util_unittest.cc +++ b/url/url_util_unittest.cc @@ -19,7 +19,7 @@ class URLUtilTest : public testing::Test { URLUtilTest() = default; ~URLUtilTest() override { // Reset any added schemes. - Shutdown(); + ResetForTests(); } private: @@ -106,7 +106,7 @@ TEST_F(URLUtilTest, ShutdownCleansUpSchemes) { AddReferrerScheme(kFooScheme, url::SCHEME_WITH_HOST); EXPECT_TRUE(IsReferrerScheme(kFooScheme, Component(0, strlen(kFooScheme)))); - Shutdown(); + ResetForTests(); EXPECT_FALSE(IsReferrerScheme(kFooScheme, Component(0, strlen(kFooScheme)))); }