Commit 94b6e423 authored by Ella Ge's avatar Ella Ge Committed by Chromium LUCI CQ

Convert StatusCallback to base::RepeatingCallback

Bug: 1152282
Change-Id: Ieced102dbf0f15feadd688c5cc990438d0cdec08
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2595846Reviewed-by: default avatarJohn Lee <johntlee@chromium.org>
Commit-Queue: Ella Ge <eirage@chromium.org>
Cr-Commit-Position: refs/heads/master@{#838746}
parent 7c580fbb
......@@ -8,7 +8,7 @@ TestVersionUpdater::TestVersionUpdater() = default;
TestVersionUpdater::~TestVersionUpdater() = default;
void TestVersionUpdater::CheckForUpdate(const StatusCallback& callback,
void TestVersionUpdater::CheckForUpdate(StatusCallback callback,
const PromoteCallback&) {
callback.Run(status_, progress_, rollback_, powerwash_, version_,
update_size_, message_);
......
......@@ -19,8 +19,7 @@ class TestVersionUpdater : public VersionUpdater {
TestVersionUpdater();
~TestVersionUpdater() override;
void CheckForUpdate(const StatusCallback& callback,
const PromoteCallback&) override;
void CheckForUpdate(StatusCallback callback, const PromoteCallback&) override;
void SetReturnedStatus(Status status) { status_ = status; }
......@@ -34,7 +33,7 @@ class TestVersionUpdater : public VersionUpdater {
void GetChannel(bool get_current_channel,
const ChannelCallback& callback) override {}
void GetEolInfo(EolInfoCallback callback) override {}
void SetUpdateOverCellularOneTimePermission(const StatusCallback& callback,
void SetUpdateOverCellularOneTimePermission(StatusCallback callback,
const std::string& update_version,
int64_t update_size) override {}
#endif
......
......@@ -65,13 +65,13 @@ class VersionUpdater {
// |update_size| is the size of the available update in bytes and should be 0
// when update is not available.
// |message| is a message explaining a failure.
typedef base::Callback<void(Status status,
int progress,
bool rollback,
bool powerwash,
const std::string& version,
int64_t update_size,
const base::string16& message)>
typedef base::RepeatingCallback<void(Status status,
int progress,
bool rollback,
bool powerwash,
const std::string& version,
int64_t update_size,
const base::string16& message)>
StatusCallback;
// Used to show or hide the promote UI elements. Mac-only.
......@@ -89,7 +89,7 @@ class VersionUpdater {
// |status_callback| is called for each status update. |promote_callback|
// (which is only used on the Mac) can be used to show or hide the promote UI
// elements.
virtual void CheckForUpdate(const StatusCallback& status_callback,
virtual void CheckForUpdate(StatusCallback status_callback,
const PromoteCallback& promote_callback) = 0;
#if defined(OS_MAC)
......@@ -115,7 +115,7 @@ class VersionUpdater {
// there's a new update available or a delta update becomes a full update with
// a larger size.
virtual void SetUpdateOverCellularOneTimePermission(
const StatusCallback& callback,
StatusCallback callback,
const std::string& update_version,
int64_t update_size) = 0;
#endif
......
......@@ -7,9 +7,8 @@
#include "base/strings/string16.h"
#include "chrome/browser/upgrade_detector/upgrade_detector.h"
void VersionUpdaterBasic::CheckForUpdate(
const StatusCallback& status_callback,
const PromoteCallback&) {
void VersionUpdaterBasic::CheckForUpdate(StatusCallback status_callback,
const PromoteCallback&) {
const Status status = UpgradeDetector::GetInstance()->notify_upgrade()
? NEARLY_UPDATED
: DISABLED;
......
......@@ -13,8 +13,8 @@
class VersionUpdaterBasic : public VersionUpdater {
public:
// VersionUpdater implementation.
void CheckForUpdate(const StatusCallback& callback,
const PromoteCallback&) override;
void CheckForUpdate(StatusCallback callback, const PromoteCallback&) override;
protected:
friend class VersionUpdater;
......
......@@ -136,11 +136,11 @@ VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) {
return new VersionUpdaterCros(web_contents);
}
void VersionUpdaterCros::GetUpdateStatus(const StatusCallback& callback) {
callback_ = callback;
void VersionUpdaterCros::GetUpdateStatus(StatusCallback callback) {
callback_ = std::move(callback);
// User is not actively checking for updates.
if (!EnsureCanUpdate(false /* interactive */, callback))
if (!EnsureCanUpdate(false /* interactive */, callback_))
return;
UpdateEngineClient* update_engine_client =
......@@ -152,12 +152,12 @@ void VersionUpdaterCros::GetUpdateStatus(const StatusCallback& callback) {
DBusThreadManager::Get()->GetUpdateEngineClient()->GetLastStatus());
}
void VersionUpdaterCros::CheckForUpdate(const StatusCallback& callback,
void VersionUpdaterCros::CheckForUpdate(StatusCallback callback,
const PromoteCallback&) {
callback_ = callback;
callback_ = std::move(callback);
// User is actively checking for updates.
if (!EnsureCanUpdate(true /* interactive */, callback))
if (!EnsureCanUpdate(true /* interactive */, callback_))
return;
UpdateEngineClient* update_engine_client =
......@@ -195,10 +195,10 @@ void VersionUpdaterCros::SetChannel(const std::string& channel,
}
void VersionUpdaterCros::SetUpdateOverCellularOneTimePermission(
const StatusCallback& callback,
StatusCallback callback,
const std::string& update_version,
int64_t update_size) {
callback_ = callback;
callback_ = std::move(callback);
DBusThreadManager::Get()
->GetUpdateEngineClient()
->SetUpdateOverCellularOneTimePermission(
......
......@@ -19,19 +19,18 @@ class VersionUpdaterCros : public VersionUpdater,
public chromeos::UpdateEngineClient::Observer {
public:
// VersionUpdater implementation.
void CheckForUpdate(const StatusCallback& callback,
const PromoteCallback&) override;
void CheckForUpdate(StatusCallback callback, const PromoteCallback&) override;
void SetChannel(const std::string& channel,
bool is_powerwash_allowed) override;
void GetChannel(bool get_current_channel,
const ChannelCallback& callback) override;
void GetEolInfo(EolInfoCallback callback) override;
void SetUpdateOverCellularOneTimePermission(const StatusCallback& callback,
void SetUpdateOverCellularOneTimePermission(StatusCallback callback,
const std::string& update_version,
int64_t update_size) override;
// Gets the last update status, without triggering a new check or download.
void GetUpdateStatus(const StatusCallback& callback);
void GetUpdateStatus(StatusCallback callback);
protected:
friend class VersionUpdater;
......
......@@ -126,7 +126,7 @@ TEST_F(VersionUpdaterCrosTest, TwoOverlappingSetChannelRequests) {
EXPECT_EQ(0, fake_update_engine_client_->request_update_check_call_count());
// IDLE -> DOWNLOADING transition after update check.
version_updater_->CheckForUpdate(base::Bind(&CheckNotification),
version_updater_->CheckForUpdate(base::BindRepeating(&CheckNotification),
VersionUpdater::PromoteCallback());
EXPECT_EQ(1, fake_update_engine_client_->request_update_check_call_count());
......@@ -150,7 +150,7 @@ TEST_F(VersionUpdaterCrosTest, TwoOverlappingSetChannelRequests) {
fake_update_engine_client_->NotifyObserversThatStatusChanged(status);
}
version_updater_->CheckForUpdate(base::Bind(&CheckNotification),
version_updater_->CheckForUpdate(base::BindRepeating(&CheckNotification),
VersionUpdater::PromoteCallback());
EXPECT_EQ(1, fake_update_engine_client_->request_update_check_call_count());
......@@ -172,7 +172,7 @@ TEST_F(VersionUpdaterCrosTest, TwoOverlappingSetChannelRequests) {
TEST_F(VersionUpdaterCrosTest, InteractiveCellularUpdateAllowed) {
SetCellularService();
EXPECT_EQ(0, fake_update_engine_client_->request_update_check_call_count());
version_updater_->CheckForUpdate(base::Bind(&CheckNotification),
version_updater_->CheckForUpdate(base::BindRepeating(&CheckNotification),
VersionUpdater::PromoteCallback());
EXPECT_EQ(1, fake_update_engine_client_->request_update_check_call_count());
}
......@@ -185,7 +185,7 @@ TEST_F(VersionUpdaterCrosTest, CellularUpdateOneTimePermission) {
const std::string& update_version = "9999.0.0";
const int64_t update_size = 99999;
version_updater_->SetUpdateOverCellularOneTimePermission(
base::Bind(&CheckNotification), update_version, update_size);
base::BindRepeating(&CheckNotification), update_version, update_size);
EXPECT_EQ(1, fake_update_engine_client_->request_update_check_call_count());
}
......
......@@ -27,7 +27,7 @@ class BrowserUpdaterClient;
class VersionUpdaterMac : public VersionUpdater {
public:
// VersionUpdater implementation.
void CheckForUpdate(const StatusCallback& status_callback,
void CheckForUpdate(StatusCallback status_callback,
const PromoteCallback& promote_callback) override;
void PromoteUpdater() const override;
......
......@@ -78,7 +78,7 @@ int GetDownloadProgress(int64_t downloaded_bytes, int64_t total_bytes) {
}
void UpdateStatusFromChromiumUpdater(
const VersionUpdater::StatusCallback& status_callback,
VersionUpdater::StatusCallback status_callback,
updater::UpdateService::UpdateState update_state) {
VersionUpdater::Status status = VersionUpdater::Status::CHECKING;
int progress = 0;
......@@ -136,17 +136,17 @@ VersionUpdaterMac::VersionUpdaterMac()
VersionUpdaterMac::~VersionUpdaterMac() {}
void VersionUpdaterMac::CheckForUpdate(
const StatusCallback& status_callback,
StatusCallback status_callback,
const PromoteCallback& promote_callback) {
#if BUILDFLAG(ENABLE_CHROMIUM_UPDATER)
if (!update_client_)
update_client_ = BrowserUpdaterClient::Create();
update_client_->CheckForUpdate(
base::BindRepeating(&UpdateStatusFromChromiumUpdater, status_callback));
update_client_->CheckForUpdate(base::BindRepeating(
&UpdateStatusFromChromiumUpdater, std::move(status_callback)));
return;
#else
status_callback_ = status_callback;
status_callback_ = std::move(status_callback);
promote_callback_ = promote_callback;
KeystoneGlue* keystone_glue = [KeystoneGlue defaultKeystoneGlue];
......
......@@ -26,10 +26,10 @@ VersionUpdaterWin::VersionUpdaterWin(gfx::AcceleratedWidget owner_widget)
VersionUpdaterWin::~VersionUpdaterWin() {
}
void VersionUpdaterWin::CheckForUpdate(const StatusCallback& callback,
void VersionUpdaterWin::CheckForUpdate(StatusCallback callback,
const PromoteCallback&) {
// There is no supported integration with Google Update for Chromium.
callback_ = callback;
callback_ = std::move(callback);
callback_.Run(CHECKING, 0, false, false, std::string(), 0, base::string16());
DoBeginUpdateCheck(false /* !install_update_if_possible */);
......
......@@ -25,8 +25,7 @@ class VersionUpdaterWin : public VersionUpdater,
~VersionUpdaterWin() override;
// VersionUpdater:
void CheckForUpdate(const StatusCallback& callback,
const PromoteCallback&) override;
void CheckForUpdate(StatusCallback callback, const PromoteCallback&) override;
// UpdateCheckDelegate:
void OnUpdateCheckComplete(const base::string16& new_version) override;
......
......@@ -470,7 +470,8 @@ void AboutHandler::HandleSetChannel(const base::ListValue* args) {
if (user_manager::UserManager::Get()->IsCurrentUserOwner()) {
// Check for update after switching release channel.
version_updater_->CheckForUpdate(
base::Bind(&AboutHandler::SetUpdateStatus, base::Unretained(this)),
base::BindRepeating(&AboutHandler::SetUpdateStatus,
base::Unretained(this)),
VersionUpdater::PromoteCallback());
}
}
......@@ -570,7 +571,8 @@ void AboutHandler::HandleRequestUpdateOverCellular(
void AboutHandler::RequestUpdateOverCellular(const std::string& update_version,
int64_t update_size) {
version_updater_->SetUpdateOverCellularOneTimePermission(
base::Bind(&AboutHandler::SetUpdateStatus, base::Unretained(this)),
base::BindRepeating(&AboutHandler::SetUpdateStatus,
base::Unretained(this)),
update_version, update_size);
}
......@@ -625,9 +627,11 @@ void AboutHandler::OnGetEndOfLifeInfo(
void AboutHandler::RequestUpdate() {
version_updater_->CheckForUpdate(
base::Bind(&AboutHandler::SetUpdateStatus, base::Unretained(this)),
base::BindRepeating(&AboutHandler::SetUpdateStatus,
base::Unretained(this)),
#if defined(OS_MAC)
base::Bind(&AboutHandler::SetPromotionState, base::Unretained(this)));
base::BindRepeating(&AboutHandler::SetPromotionState,
base::Unretained(this)));
#else
VersionUpdater::PromoteCallback());
#endif // OS_MAC
......
......@@ -388,8 +388,8 @@ void SafetyCheckHandler::HandleGetParentRanDisplayString(
void SafetyCheckHandler::CheckUpdates() {
// Usage of base::Unretained(this) is safe, because we own `version_updater_`.
version_updater_->CheckForUpdate(
base::Bind(&SafetyCheckHandler::OnVersionUpdaterResult,
base::Unretained(this)),
base::BindRepeating(&SafetyCheckHandler::OnVersionUpdaterResult,
base::Unretained(this)),
VersionUpdater::PromoteCallback());
}
......
......@@ -99,7 +99,7 @@ class TestDestructionVersionUpdater : public TestVersionUpdater {
public:
~TestDestructionVersionUpdater() override { destructor_invoked_ = true; }
void CheckForUpdate(const StatusCallback& callback,
void CheckForUpdate(StatusCallback callback,
const PromoteCallback&) override {}
static bool GetDestructorInvoked() { return destructor_invoked_; }
......
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