Skip to content

Commit

Permalink
Force update check if channel is set
Browse files Browse the repository at this point in the history
If SetUpdaterChannel is called with the same channel as the current
channel, an update check is forced just like the channel has changed, as
long as the channel is not "prod".

b/381954273
  • Loading branch information
yuying-y committed Dec 4, 2024
1 parent e67b550 commit 4cb2a4b
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 14 deletions.
8 changes: 4 additions & 4 deletions chrome/updater/configurator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Configurator::Configurator(network::NetworkModule* network_module)
: pref_service_(CreatePrefService()),
persisted_data_(std::make_unique<update_client::PersistedData>(
pref_service_.get(), nullptr)),
is_channel_changed_(0),
is_forced_update_(0),
unzip_factory_(base::MakeRefCounted<UnzipperFactory>()),
network_fetcher_factory_(
base::MakeRefCounted<NetworkFetcherFactoryCobalt>(network_module)),
Expand Down Expand Up @@ -174,7 +174,7 @@ base::flat_map<std::string, std::string> Configurator::ExtraRequestParams()
std::make_pair("jsengine", script::GetJavaScriptEngineNameAndVersion()));
params.insert(std::make_pair(
"updaterchannelchanged",
SbAtomicNoBarrier_Load(&is_channel_changed_) == 1 ? "True" : "False"));
SbAtomicNoBarrier_Load(&is_forced_update_) == 1 ? "True" : "False"));
// Brand name
params.insert(
std::make_pair("brand", GetDeviceProperty(kSbSystemPropertyBrandName)));
Expand Down Expand Up @@ -318,8 +318,8 @@ update_client::RecoveryCRXElevator Configurator::GetRecoveryCRXElevator()
return {};
}

void Configurator::CompareAndSwapChannelChanged(int old_value, int new_value) {
SbAtomicNoBarrier_CompareAndSwap(&is_channel_changed_, old_value, new_value);
void Configurator::CompareAndSwapForcedUpdate(int old_value, int new_value) {
SbAtomicNoBarrier_CompareAndSwap(&is_forced_update_, old_value, new_value);
}

// The updater channel is get and set by main web module thread and update
Expand Down
4 changes: 2 additions & 2 deletions chrome/updater/configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Configurator : public update_client::Configurator {

void SetChannel(const std::string& updater_channel) override;

void CompareAndSwapChannelChanged(int old_value, int new_value) override;
void CompareAndSwapForcedUpdate(int old_value, int new_value) override;

std::string GetUpdaterStatus() const override;
void SetUpdaterStatus(const std::string& status) override;
Expand Down Expand Up @@ -117,7 +117,7 @@ class Configurator : public update_client::Configurator {
scoped_refptr<update_client::PatcherFactory> patch_factory_;
std::string updater_channel_;
base::Lock updater_channel_lock_;
SbAtomic32 is_channel_changed_;
SbAtomic32 is_forced_update_;
std::string updater_status_;
base::Lock updater_status_lock_;
std::string previous_updater_status_;
Expand Down
4 changes: 2 additions & 2 deletions chrome/updater/updater_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ void UpdaterModule::Update() {

// The following methods are called by other threads than the updater_thread_.

void UpdaterModule::CompareAndSwapChannelChanged(int old_value, int new_value) {
void UpdaterModule::CompareAndSwapForcedUpdate(int old_value, int new_value) {
auto config = updater_configurator_;
if (config) config->CompareAndSwapChannelChanged(old_value, new_value);
if (config) config->CompareAndSwapForcedUpdate(old_value, new_value);
}

std::string UpdaterModule::GetUpdaterChannel() const {
Expand Down
2 changes: 1 addition & 1 deletion chrome/updater/updater_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class UpdaterModule {
std::string GetUpdaterChannel() const;
void SetUpdaterChannel(const std::string& updater_channel);

void CompareAndSwapChannelChanged(int old_value, int new_value);
void CompareAndSwapForcedUpdate(int old_value, int new_value);

void RunUpdateCheck();

Expand Down
7 changes: 5 additions & 2 deletions cobalt/h5vcc/h5vcc_updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ void H5vccUpdater::SetUpdaterChannel(const std::string& channel) {

if (updater_module_->GetUpdaterChannel().compare(channel) != 0) {
updater_module_->SetUpdaterChannel(channel);
updater_module_->CompareAndSwapChannelChanged(0, 1);
updater_module_->RunUpdateCheck();
} else if (channel.compare("prod") == 0) {
// If channel is not changed and is "prod", do nothing.
return;
}
updater_module_->CompareAndSwapForcedUpdate(0, 1);
updater_module_->RunUpdateCheck();
}

std::string H5vccUpdater::GetUpdateStatus() const {
Expand Down
2 changes: 1 addition & 1 deletion components/update_client/configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class Configurator : public base::RefCountedThreadSafe<Configurator> {
virtual void SetUpdaterStatus(const std::string& status) = 0;

// Compare and swap the is_channel_changed flag.
virtual void CompareAndSwapChannelChanged(int old_value, int new_value) = 0;
virtual void CompareAndSwapForcedUpdate(int old_value, int new_value) = 0;

virtual void SetMinFreeSpaceBytes(uint64_t bytes) = 0;
virtual uint64_t GetMinFreeSpaceBytes() = 0;
Expand Down
2 changes: 1 addition & 1 deletion components/update_client/test_configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class TestConfigurator : public Configurator {
#if defined(STARBOARD)
// TODO: add unit tests for updater channels, status, and compressed updates.
void SetChannel(const std::string& channel) override {}
void CompareAndSwapChannelChanged(int old_value, int new_value) override {}
void CompareAndSwapForcedUpdate(int old_value, int new_value) override {}
std::string GetUpdaterStatus() const override { return ""; }
void SetUpdaterStatus(const std::string& status) override {}

Expand Down
2 changes: 1 addition & 1 deletion components/update_client/update_checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ void UpdateCheckerImpl::CheckForUpdatesHelper(
base::Unretained(this)));
#if defined(STARBOARD)
// Reset is_channel_changed flag to false if it is true
config_->CompareAndSwapChannelChanged(1, 0);
config_->CompareAndSwapForcedUpdate(1, 0);
#endif
}

Expand Down

0 comments on commit 4cb2a4b

Please sign in to comment.