Eliminate task runner injection from the configurator.
The new task scheduler API makes it possible to simplify the
configurator and avoid injecting task runners.
Bug: 740992
Change-Id: Iaabdc498993745372cee47193f16f1df4d09f7a2
Reviewed-on: https://chromium-review.googlesource.com/582030
Reviewed-by: David Roger <[email protected]>
Reviewed-by: Joshua Pawlicki <[email protected]>
Reviewed-by: Devlin <[email protected]>
Commit-Queue: Sorin Jianu <[email protected]>
Cr-Commit-Position: refs/heads/master@{#489528}
diff --git a/chrome/browser/component_updater/chrome_component_updater_configurator.cc b/chrome/browser/component_updater/chrome_component_updater_configurator.cc
index a7f3b5a..1eecd2c 100644
--- a/chrome/browser/component_updater/chrome_component_updater_configurator.cc
+++ b/chrome/browser/component_updater/chrome_component_updater_configurator.cc
@@ -9,10 +9,7 @@
#include <string>
#include <vector>
-#include "base/sequenced_task_runner.h"
#include "base/strings/sys_string_conversions.h"
-#include "base/task_scheduler/post_task.h"
-#include "base/task_scheduler/task_traits.h"
#include "base/version.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
@@ -64,8 +61,6 @@
bool EnabledComponentUpdates() const override;
bool EnabledBackgroundDownloader() const override;
bool EnabledCupSigning() const override;
- scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner()
- const override;
PrefService* GetPrefService() const override;
bool IsPerUserInstall() const override;
std::vector<uint8_t> GetRunActionKeyHash() const override;
@@ -183,14 +178,6 @@
return configurator_impl_.EnabledCupSigning();
}
-// Returns a task runner to run blocking tasks.
-scoped_refptr<base::SequencedTaskRunner>
-ChromeConfigurator::GetSequencedTaskRunner() const {
- return base::CreateSequencedTaskRunnerWithTraits(
- {base::MayBlock(), base::TaskPriority::BACKGROUND,
- base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN});
-}
-
PrefService* ChromeConfigurator::GetPrefService() const {
DCHECK(pref_service_);
return pref_service_;
diff --git a/chrome/browser/extensions/updater/chrome_update_client_config.h b/chrome/browser/extensions/updater/chrome_update_client_config.h
index b3a53ac8..b44ffad2 100644
--- a/chrome/browser/extensions/updater/chrome_update_client_config.h
+++ b/chrome/browser/extensions/updater/chrome_update_client_config.h
@@ -13,7 +13,7 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "components/component_updater/configurator_impl.h"
-#include "extensions/browser/updater/update_client_config.h"
+#include "components/update_client/configurator.h"
namespace content {
class BrowserContext;
@@ -21,7 +21,7 @@
namespace extensions {
-class ChromeUpdateClientConfig : public UpdateClientConfig {
+class ChromeUpdateClientConfig : public update_client::Configurator {
public:
explicit ChromeUpdateClientConfig(content::BrowserContext* context);
diff --git a/components/component_updater/component_updater_service_unittest.cc b/components/component_updater/component_updater_service_unittest.cc
index 4389e14..5e033c0 100644
--- a/components/component_updater/component_updater_service_unittest.cc
+++ b/components/component_updater/component_updater_service_unittest.cc
@@ -126,10 +126,12 @@
private:
base::test::ScopedTaskEnvironment scoped_task_environment_;
base::RunLoop runloop_;
- base::Closure quit_closure_;
+ const base::Closure quit_closure_ = runloop_.QuitClosure();
- scoped_refptr<TestConfigurator> config_;
- scoped_refptr<MockUpdateClient> update_client_;
+ scoped_refptr<TestConfigurator> config_ =
+ base::MakeRefCounted<TestConfigurator>();
+ scoped_refptr<MockUpdateClient> update_client_ =
+ base::MakeRefCounted<MockUpdateClient>();
std::unique_ptr<ComponentUpdateService> component_updater_;
DISALLOW_COPY_AND_ASSIGN(ComponentUpdaterTest);
@@ -181,16 +183,7 @@
return base::MakeUnique<CrxUpdateService>(config, new MockUpdateClient());
}
-ComponentUpdaterTest::ComponentUpdaterTest()
- : scoped_task_environment_(
- base::test::ScopedTaskEnvironment::MainThreadType::UI) {
- quit_closure_ = runloop_.QuitClosure();
-
- config_ = base::MakeRefCounted<TestConfigurator>(
- base::CreateSequencedTaskRunnerWithTraits({base::MayBlock()}),
- base::ThreadTaskRunnerHandle::Get());
-
- update_client_ = base::MakeRefCounted<MockUpdateClient>();
+ComponentUpdaterTest::ComponentUpdaterTest() {
EXPECT_CALL(update_client(), AddObserver(_)).Times(1);
component_updater_ =
base::MakeUnique<CrxUpdateService>(config_, update_client_);
diff --git a/components/component_updater/default_component_installer_unittest.cc b/components/component_updater/default_component_installer_unittest.cc
index cd2fff2..4fa8646 100644
--- a/components/component_updater/default_component_installer_unittest.cc
+++ b/components/component_updater/default_component_installer_unittest.cc
@@ -167,24 +167,17 @@
const scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_ =
base::ThreadTaskRunnerHandle::Get();
base::RunLoop runloop_;
- base::Closure quit_closure_;
+ base::Closure quit_closure_ = runloop_.QuitClosure();
- scoped_refptr<TestConfigurator> config_;
- scoped_refptr<MockUpdateClient> update_client_;
+ scoped_refptr<TestConfigurator> config_ =
+ base::MakeRefCounted<TestConfigurator>();
+ scoped_refptr<MockUpdateClient> update_client_ =
+ base::MakeRefCounted<MockUpdateClient>();
std::unique_ptr<ComponentUpdateService> component_updater_;
ComponentUnpacker::Result result_;
};
-DefaultComponentInstallerTest::DefaultComponentInstallerTest()
- : scoped_task_environment_(
- base::test::ScopedTaskEnvironment::MainThreadType::UI) {
- quit_closure_ = runloop_.QuitClosure();
-
- config_ = base::MakeRefCounted<TestConfigurator>(
- base::CreateSequencedTaskRunnerWithTraits({base::MayBlock()}),
- base::ThreadTaskRunnerHandle::Get());
-
- update_client_ = base::MakeRefCounted<MockUpdateClient>();
+DefaultComponentInstallerTest::DefaultComponentInstallerTest() {
EXPECT_CALL(update_client(), AddObserver(_)).Times(1);
component_updater_ =
base::MakeUnique<CrxUpdateService>(config_, update_client_);
diff --git a/components/update_client/component_unpacker_unittest.cc b/components/update_client/component_unpacker_unittest.cc
index a8b2da4..65eca6d 100644
--- a/components/update_client/component_unpacker_unittest.cc
+++ b/components/update_client/component_unpacker_unittest.cc
@@ -12,6 +12,7 @@
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/macros.h"
+#include "base/memory/ref_counted.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/task_scheduler/post_task.h"
@@ -78,24 +79,14 @@
const scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_ =
base::ThreadTaskRunnerHandle::Get();
base::RunLoop runloop_;
- base::Closure quit_closure_;
-
- scoped_refptr<update_client::TestConfigurator> config_;
+ const base::Closure quit_closure_ = runloop_.QuitClosure();
ComponentUnpacker::Result result_;
};
-ComponentUnpackerTest::ComponentUnpackerTest()
- : scoped_task_environment_(
- base::test::ScopedTaskEnvironment::MainThreadType::UI) {
- quit_closure_ = runloop_.QuitClosure();
+ComponentUnpackerTest::ComponentUnpackerTest() = default;
- config_ = new TestConfigurator(
- base::CreateSequencedTaskRunnerWithTraits({base::MayBlock()}),
- base::ThreadTaskRunnerHandle::Get());
-}
-
-ComponentUnpackerTest::~ComponentUnpackerTest() {}
+ComponentUnpackerTest::~ComponentUnpackerTest() = default;
void ComponentUnpackerTest::RunThreads() {
runloop_.Run();
diff --git a/components/update_client/configurator.h b/components/update_client/configurator.h
index ddb5b5d..44a2d04 100644
--- a/components/update_client/configurator.h
+++ b/components/update_client/configurator.h
@@ -15,7 +15,6 @@
class PrefService;
namespace base {
-class SequencedTaskRunner;
class Version;
}
@@ -116,10 +115,6 @@
// True if signing of update checks is enabled.
virtual bool EnabledCupSigning() const = 0;
- // Gets a task runner to a blocking pool of threads suitable for worker jobs.
- virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner()
- const = 0;
-
// Returns a PrefService that the update_client can use to store persistent
// update information. The PrefService must outlive the entire update_client,
// and be safe to access from the thread the update_client is constructed
diff --git a/components/update_client/ping_manager_unittest.cc b/components/update_client/ping_manager_unittest.cc
index 503a4d59..b883d376 100644
--- a/components/update_client/ping_manager_unittest.cc
+++ b/components/update_client/ping_manager_unittest.cc
@@ -50,9 +50,8 @@
PingManagerTest::PingManagerTest() {}
void PingManagerTest::SetUp() {
- config_ = new TestConfigurator(base::ThreadTaskRunnerHandle::Get(),
- base::ThreadTaskRunnerHandle::Get());
- ping_manager_.reset(new PingManager(config_));
+ config_ = base::MakeRefCounted<TestConfigurator>();
+ ping_manager_ = base::MakeUnique<PingManager>(config_);
}
void PingManagerTest::TearDown() {
diff --git a/components/update_client/request_sender_unittest.cc b/components/update_client/request_sender_unittest.cc
index 82a07c2..ec79ea1d 100644
--- a/components/update_client/request_sender_unittest.cc
+++ b/components/update_client/request_sender_unittest.cc
@@ -84,8 +84,7 @@
RequestSenderTest::~RequestSenderTest() {}
void RequestSenderTest::SetUp() {
- config_ = base::MakeRefCounted<TestConfigurator>(
- base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get());
+ config_ = base::MakeRefCounted<TestConfigurator>();
interceptor_factory_ =
base::MakeUnique<InterceptorFactory>(base::ThreadTaskRunnerHandle::Get());
post_interceptor_1_ =
diff --git a/components/update_client/test_configurator.cc b/components/update_client/test_configurator.cc
index ade005de..a61c093 100644
--- a/components/update_client/test_configurator.cc
+++ b/components/update_client/test_configurator.cc
@@ -6,8 +6,7 @@
#include <utility>
-#include "base/sequenced_task_runner.h"
-#include "base/single_thread_task_runner.h"
+#include "base/threading/thread_task_runner_handle.h"
#include "base/version.h"
#include "components/prefs/pref_service.h"
#include "components/update_client/out_of_process_patcher.h"
@@ -27,16 +26,14 @@
} // namespace
-TestConfigurator::TestConfigurator(
- const scoped_refptr<base::SequencedTaskRunner>& worker_task_runner,
- const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner)
- : worker_task_runner_(worker_task_runner),
- brand_("TEST"),
+TestConfigurator::TestConfigurator()
+ : brand_("TEST"),
initial_time_(0),
ondemand_time_(0),
enabled_cup_signing_(false),
enabled_component_updates_(true),
- context_(new net::TestURLRequestContextGetter(network_task_runner)) {}
+ context_(base::MakeRefCounted<net::TestURLRequestContextGetter>(
+ base::ThreadTaskRunnerHandle::Get())) {}
TestConfigurator::~TestConfigurator() {
}
@@ -163,12 +160,6 @@
ping_url_ = url;
}
-scoped_refptr<base::SequencedTaskRunner>
-TestConfigurator::GetSequencedTaskRunner() const {
- DCHECK(worker_task_runner_.get());
- return worker_task_runner_;
-}
-
PrefService* TestConfigurator::GetPrefService() const {
return nullptr;
}
diff --git a/components/update_client/test_configurator.h b/components/update_client/test_configurator.h
index fd0bc2f3..01a9674 100644
--- a/components/update_client/test_configurator.h
+++ b/components/update_client/test_configurator.h
@@ -18,11 +18,6 @@
class PrefService;
-namespace base {
-class SequencedTaskRunner;
-class SingleThreadTaskRunner;
-} // namespace base
-
namespace net {
class TestURLRequestContextGetter;
class URLRequestContextGetter;
@@ -61,9 +56,7 @@
class TestConfigurator : public Configurator {
public:
- TestConfigurator(
- const scoped_refptr<base::SequencedTaskRunner>& worker_task_runner,
- const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner);
+ TestConfigurator();
// Overrrides for Configurator.
int InitialDelay() const override;
@@ -86,8 +79,6 @@
bool EnabledComponentUpdates() const override;
bool EnabledBackgroundDownloader() const override;
bool EnabledCupSigning() const override;
- scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner()
- const override;
PrefService* GetPrefService() const override;
bool IsPerUserInstall() const override;
std::vector<uint8_t> GetRunActionKeyHash() const override;
@@ -103,11 +94,8 @@
private:
friend class base::RefCountedThreadSafe<TestConfigurator>;
-
~TestConfigurator() override;
- scoped_refptr<base::SequencedTaskRunner> worker_task_runner_;
-
std::string brand_;
int initial_time_;
int ondemand_time_;
diff --git a/components/update_client/update_checker_unittest.cc b/components/update_client/update_checker_unittest.cc
index 033118b..ba63c7c4 100644
--- a/components/update_client/update_checker_unittest.cc
+++ b/components/update_client/update_checker_unittest.cc
@@ -99,8 +99,7 @@
}
void UpdateCheckerTest::SetUp() {
- config_ = base::MakeRefCounted<TestConfigurator>(
- base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get());
+ config_ = base::MakeRefCounted<TestConfigurator>();
pref_ = base::MakeUnique<TestingPrefServiceSimple>();
PersistedData::RegisterPrefs(pref_->registry());
metadata_ = base::MakeUnique<PersistedData>(pref_.get());
diff --git a/components/update_client/update_client_unittest.cc b/components/update_client/update_client_unittest.cc
index fca7137..05b872f 100644
--- a/components/update_client/update_client_unittest.cc
+++ b/components/update_client/update_client_unittest.cc
@@ -172,10 +172,12 @@
base::test::ScopedTaskEnvironment scoped_task_environment_;
base::RunLoop runloop_;
- base::Closure quit_closure_;
+ const base::Closure quit_closure_ = runloop_.QuitClosure();
- scoped_refptr<update_client::TestConfigurator> config_;
- std::unique_ptr<TestingPrefServiceSimple> pref_;
+ scoped_refptr<update_client::TestConfigurator> config_ =
+ base::MakeRefCounted<TestConfigurator>();
+ std::unique_ptr<TestingPrefServiceSimple> pref_ =
+ base::MakeUnique<TestingPrefServiceSimple>();
std::unique_ptr<update_client::PersistedData> metadata_;
DISALLOW_COPY_AND_ASSIGN(UpdateClientTest);
@@ -183,15 +185,7 @@
constexpr int UpdateClientTest::kNumWorkerThreads_;
-UpdateClientTest::UpdateClientTest()
- : scoped_task_environment_(
- base::test::ScopedTaskEnvironment::MainThreadType::UI),
- pref_(base::MakeUnique<TestingPrefServiceSimple>()) {
- quit_closure_ = runloop_.QuitClosure();
-
- config_ = base::MakeRefCounted<TestConfigurator>(
- base::CreateSequencedTaskRunnerWithTraits({base::MayBlock()}),
- base::ThreadTaskRunnerHandle::Get());
+UpdateClientTest::UpdateClientTest() {
PersistedData::RegisterPrefs(pref_->registry());
metadata_ = base::MakeUnique<PersistedData>(pref_.get());
}
diff --git a/extensions/browser/extensions_browser_client.cc b/extensions/browser/extensions_browser_client.cc
index 8e7fe3e..3624e86d 100644
--- a/extensions/browser/extensions_browser_client.cc
+++ b/extensions/browser/extensions_browser_client.cc
@@ -8,7 +8,6 @@
#include "components/update_client/update_client.h"
#include "extensions/browser/extension_api_frame_id_map.h"
#include "extensions/browser/extension_error.h"
-#include "extensions/browser/updater/update_client_config.h"
namespace extensions {
diff --git a/extensions/browser/updater/BUILD.gn b/extensions/browser/updater/BUILD.gn
index 91279bd..12590472 100644
--- a/extensions/browser/updater/BUILD.gn
+++ b/extensions/browser/updater/BUILD.gn
@@ -23,8 +23,6 @@
"request_queue_impl.h",
"safe_manifest_parser.cc",
"safe_manifest_parser.h",
- "update_client_config.cc",
- "update_client_config.h",
"update_data_provider.cc",
"update_data_provider.h",
"update_install_shim.cc",
diff --git a/extensions/browser/updater/update_client_config.cc b/extensions/browser/updater/update_client_config.cc
deleted file mode 100644
index 8c21593c..0000000
--- a/extensions/browser/updater/update_client_config.cc
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2015 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 "extensions/browser/updater/update_client_config.h"
-
-#include "base/sequenced_task_runner.h"
-#include "base/task_scheduler/post_task.h"
-#include "base/task_scheduler/task_traits.h"
-#include "build/build_config.h"
-
-namespace extensions {
-
-UpdateClientConfig::UpdateClientConfig() {}
-
-scoped_refptr<base::SequencedTaskRunner>
-UpdateClientConfig::GetSequencedTaskRunner() const {
- constexpr base::TaskTraits traits = {
- base::MayBlock(), base::TaskPriority::BACKGROUND,
- base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN};
-#if defined(OS_WIN)
- // Use the COM STA task runner as the Windows background downloader requires
- // COM initialization.
- return base::CreateCOMSTATaskRunnerWithTraits(traits);
-#else
- return base::CreateSequencedTaskRunnerWithTraits(traits);
-#endif
-}
-
-UpdateClientConfig::~UpdateClientConfig() {}
-
-} // namespace extensions
diff --git a/extensions/browser/updater/update_client_config.h b/extensions/browser/updater/update_client_config.h
deleted file mode 100644
index e54fde4b..0000000
--- a/extensions/browser/updater/update_client_config.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2015 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.
-
-#ifndef EXTENSIONS_BROWSER_UPDATER_UPDATE_CLIENT_CONFIG_H_
-#define EXTENSIONS_BROWSER_UPDATER_UPDATE_CLIENT_CONFIG_H_
-
-#include <string>
-
-#include "base/macros.h"
-#include "base/memory/ref_counted.h"
-#include "components/update_client/configurator.h"
-
-namespace base {
-class SequencedTaskRunner;
-}
-
-namespace extensions {
-
-// Used to provide configuration settings to the UpdateClient.
-class UpdateClientConfig : public update_client::Configurator {
- public:
- UpdateClientConfig();
-
- scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner()
- const override;
-
- protected:
- friend class base::RefCountedThreadSafe<UpdateClientConfig>;
- ~UpdateClientConfig() override;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(UpdateClientConfig);
-};
-
-} // namespace extensions
-
-#endif // EXTENSIONS_BROWSER_UPDATER_UPDATE_CLIENT_CONFIG_H_
diff --git a/ios/chrome/browser/component_updater/ios_component_updater_configurator.cc b/ios/chrome/browser/component_updater/ios_component_updater_configurator.cc
index 10fc8d9..484fe768 100644
--- a/ios/chrome/browser/component_updater/ios_component_updater_configurator.cc
+++ b/ios/chrome/browser/component_updater/ios_component_updater_configurator.cc
@@ -9,7 +9,6 @@
#include <string>
#include <vector>
-#include "base/task_scheduler/post_task.h"
#include "base/version.h"
#include "components/component_updater/configurator_impl.h"
#include "components/update_client/out_of_process_patcher.h"
@@ -49,8 +48,6 @@
bool EnabledComponentUpdates() const override;
bool EnabledBackgroundDownloader() const override;
bool EnabledCupSigning() const override;
- scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner()
- const override;
PrefService* GetPrefService() const override;
bool IsPerUserInstall() const override;
std::vector<uint8_t> GetRunActionKeyHash() const override;
@@ -155,13 +152,6 @@
return configurator_impl_.EnabledCupSigning();
}
-scoped_refptr<base::SequencedTaskRunner>
-IOSConfigurator::GetSequencedTaskRunner() const {
- return base::CreateSequencedTaskRunnerWithTraits(
- {base::MayBlock(), base::TaskPriority::BACKGROUND,
- base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN});
-}
-
PrefService* IOSConfigurator::GetPrefService() const {
return GetApplicationContext()->GetLocalState();
}