Commit 242a3f1e authored by Anqing Zhao's avatar Anqing Zhao Committed by Commit Bot

Replace the deprecated MessageLoopRunner with base::RunLoop

The class content::MessageLoopRunner class has been deprecated for a
long time. Not 100% sure if this is related to the flaky tests, but
nothing to lose replace them with the recommanded one - base::RunLoop.

Bug: 1044417, 783450
Change-Id: I969f32550c7f1679c8dc398b9b1c17da97b4d137
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2214943Reviewed-by: default avatarSergey Poromov <poromov@chromium.org>
Reviewed-by: default avatarAnatoliy Potapchuk <apotapchuk@chromium.org>
Commit-Queue: Anqing Zhao <anqing@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771732}
parent 48d35a30
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/run_loop.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/system/sys_info.h" #include "base/system/sys_info.h"
...@@ -142,8 +143,8 @@ class AppDataLoadWaiter : public KioskAppManagerObserver { ...@@ -142,8 +143,8 @@ class AppDataLoadWaiter : public KioskAppManagerObserver {
void Wait() { void Wait() {
if (quit_) if (quit_)
return; return;
runner_ = new content::MessageLoopRunner; run_loop_ = std::make_unique<base::RunLoop>();
runner_->Run(); run_loop_->Run();
} }
void Reset() { void Reset() {
...@@ -163,16 +164,16 @@ class AppDataLoadWaiter : public KioskAppManagerObserver { ...@@ -163,16 +164,16 @@ class AppDataLoadWaiter : public KioskAppManagerObserver {
return; return;
loaded_ = true; loaded_ = true;
quit_ = true; quit_ = true;
if (runner_.get()) if (run_loop_)
runner_->Quit(); run_loop_->Quit();
} }
void OnKioskAppDataLoadFailure(const std::string& app_id) override { void OnKioskAppDataLoadFailure(const std::string& app_id) override {
++data_load_failure_count_; ++data_load_failure_count_;
loaded_ = false; loaded_ = false;
quit_ = true; quit_ = true;
if (runner_.get()) if (run_loop_)
runner_->Quit(); run_loop_->Quit();
} }
void OnKioskExtensionLoadedInCache(const std::string& app_id) override { void OnKioskExtensionLoadedInCache(const std::string& app_id) override {
...@@ -186,7 +187,7 @@ class AppDataLoadWaiter : public KioskAppManagerObserver { ...@@ -186,7 +187,7 @@ class AppDataLoadWaiter : public KioskAppManagerObserver {
// to missing update URL in manifest. // to missing update URL in manifest.
} }
scoped_refptr<content::MessageLoopRunner> runner_; std::unique_ptr<base::RunLoop> run_loop_;
KioskAppManager* manager_; KioskAppManager* manager_;
bool loaded_ = false; bool loaded_ = false;
bool quit_ = false; bool quit_ = false;
...@@ -206,21 +207,21 @@ class ExternalCachePutWaiter { ...@@ -206,21 +207,21 @@ class ExternalCachePutWaiter {
void Wait() { void Wait() {
if (quit_) if (quit_)
return; return;
runner_ = new content::MessageLoopRunner; run_loop_ = std::make_unique<base::RunLoop>();
runner_->Run(); run_loop_->Run();
} }
void OnPutExtension(const std::string& id, bool success) { void OnPutExtension(const std::string& id, bool success) {
success_ = success; success_ = success;
quit_ = true; quit_ = true;
if (runner_.get()) if (run_loop_)
runner_->Quit(); run_loop_->Quit();
} }
bool success() const { return success_; } bool success() const { return success_; }
private: private:
scoped_refptr<content::MessageLoopRunner> runner_; std::unique_ptr<base::RunLoop> run_loop_;
bool quit_ = false; bool quit_ = false;
bool success_ = false; bool success_ = false;
...@@ -293,8 +294,7 @@ class KioskAppManagerTest : public InProcessBrowserTest { ...@@ -293,8 +294,7 @@ class KioskAppManagerTest : public InProcessBrowserTest {
std::unique_ptr<InstallAttributes::LockResult> lock_result = std::unique_ptr<InstallAttributes::LockResult> lock_result =
std::make_unique<InstallAttributes::LockResult>( std::make_unique<InstallAttributes::LockResult>(
InstallAttributes::LOCK_NOT_READY); InstallAttributes::LOCK_NOT_READY);
scoped_refptr<content::MessageLoopRunner> runner = base::RunLoop run_loop;
new content::MessageLoopRunner;
policy::BrowserPolicyConnectorChromeOS* connector = policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos(); g_browser_process->platform_part()->browser_policy_connector_chromeos();
connector->GetInstallAttributes()->LockDevice( connector->GetInstallAttributes()->LockDevice(
...@@ -302,8 +302,8 @@ class KioskAppManagerTest : public InProcessBrowserTest { ...@@ -302,8 +302,8 @@ class KioskAppManagerTest : public InProcessBrowserTest {
std::string(), // realm std::string(), // realm
"device-id", "device-id",
base::BindOnce(&OnEnterpriseDeviceLock, lock_result.get(), base::BindOnce(&OnEnterpriseDeviceLock, lock_result.get(),
runner->QuitClosure())); run_loop.QuitClosure()));
runner->Run(); run_loop.Run();
return *lock_result.get(); return *lock_result.get();
} }
...@@ -828,25 +828,22 @@ IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, EnableConsumerKiosk) { ...@@ -828,25 +828,22 @@ IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, EnableConsumerKiosk) {
KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED; KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED;
bool locked = false; bool locked = false;
scoped_refptr<content::MessageLoopRunner> runner = base::RunLoop run_loop;
new content::MessageLoopRunner;
manager()->GetConsumerKioskAutoLaunchStatus(base::BindOnce( manager()->GetConsumerKioskAutoLaunchStatus(base::BindOnce(
&ConsumerKioskAutoLaunchStatusCheck, &status, runner->QuitClosure())); &ConsumerKioskAutoLaunchStatusCheck, &status, run_loop.QuitClosure()));
runner->Run(); run_loop.Run();
EXPECT_EQ(status, KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE); EXPECT_EQ(status, KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE);
scoped_refptr<content::MessageLoopRunner> runner2 = base::RunLoop run_loop2;
new content::MessageLoopRunner;
manager()->EnableConsumerKioskAutoLaunch(base::BindOnce( manager()->EnableConsumerKioskAutoLaunch(base::BindOnce(
&ConsumerKioskModeLockCheck, &locked, runner2->QuitClosure())); &ConsumerKioskModeLockCheck, &locked, run_loop2.QuitClosure()));
runner2->Run(); run_loop2.Run();
EXPECT_TRUE(locked); EXPECT_TRUE(locked);
scoped_refptr<content::MessageLoopRunner> runner3 = base::RunLoop run_loop3;
new content::MessageLoopRunner;
manager()->GetConsumerKioskAutoLaunchStatus(base::BindOnce( manager()->GetConsumerKioskAutoLaunchStatus(base::BindOnce(
&ConsumerKioskAutoLaunchStatusCheck, &status, runner3->QuitClosure())); &ConsumerKioskAutoLaunchStatusCheck, &status, run_loop3.QuitClosure()));
runner3->Run(); run_loop3.Run();
EXPECT_EQ(status, KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_ENABLED); EXPECT_EQ(status, KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_ENABLED);
} }
...@@ -854,11 +851,10 @@ IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, ConsumerKioskDisabled) { ...@@ -854,11 +851,10 @@ IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, ConsumerKioskDisabled) {
KioskAppManager::ConsumerKioskAutoLaunchStatus status = KioskAppManager::ConsumerKioskAutoLaunchStatus status =
KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE; KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE;
scoped_refptr<content::MessageLoopRunner> runner = base::RunLoop run_loop;
new content::MessageLoopRunner;
manager()->GetConsumerKioskAutoLaunchStatus(base::BindOnce( manager()->GetConsumerKioskAutoLaunchStatus(base::BindOnce(
&ConsumerKioskAutoLaunchStatusCheck, &status, runner->QuitClosure())); &ConsumerKioskAutoLaunchStatusCheck, &status, run_loop.QuitClosure()));
runner->Run(); run_loop.Run();
EXPECT_EQ(status, KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED); EXPECT_EQ(status, KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED);
} }
...@@ -875,25 +871,22 @@ IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, ...@@ -875,25 +871,22 @@ IN_PROC_BROWSER_TEST_F(KioskAppManagerTest,
KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED; KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED;
bool locked = true; bool locked = true;
scoped_refptr<content::MessageLoopRunner> runner = base::RunLoop run_loop;
new content::MessageLoopRunner;
manager()->GetConsumerKioskAutoLaunchStatus(base::BindOnce( manager()->GetConsumerKioskAutoLaunchStatus(base::BindOnce(
&ConsumerKioskAutoLaunchStatusCheck, &status, runner->QuitClosure())); &ConsumerKioskAutoLaunchStatusCheck, &status, run_loop.QuitClosure()));
runner->Run(); run_loop.Run();
EXPECT_EQ(status, KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED); EXPECT_EQ(status, KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED);
scoped_refptr<content::MessageLoopRunner> runner2 = base::RunLoop run_loop2;
new content::MessageLoopRunner;
manager()->EnableConsumerKioskAutoLaunch(base::BindOnce( manager()->EnableConsumerKioskAutoLaunch(base::BindOnce(
&ConsumerKioskModeLockCheck, &locked, runner2->QuitClosure())); &ConsumerKioskModeLockCheck, &locked, run_loop2.QuitClosure()));
runner2->Run(); run_loop2.Run();
EXPECT_FALSE(locked); EXPECT_FALSE(locked);
scoped_refptr<content::MessageLoopRunner> runner3 = base::RunLoop run_loop3;
new content::MessageLoopRunner;
manager()->GetConsumerKioskAutoLaunchStatus(base::BindOnce( manager()->GetConsumerKioskAutoLaunchStatus(base::BindOnce(
&ConsumerKioskAutoLaunchStatusCheck, &status, runner3->QuitClosure())); &ConsumerKioskAutoLaunchStatusCheck, &status, run_loop3.QuitClosure()));
runner3->Run(); run_loop3.Run();
EXPECT_EQ(status, KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED); EXPECT_EQ(status, KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED);
} }
......
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