Commit dfba2ada authored by A Olsen's avatar A Olsen Committed by Commit Bot

StubCrosSettingsProvider: Fix infinite loop risk

There is no circumstance in which in an infinite loop actually ever
happens - especially not in production which doesn't use
StubCrosSettingsProvider - but in tests there is a bigger risk,
and it is currently only narrowly avoided.

This CL no longer notifies listeners when the value does not
actually change, which should prevent infinite loops of the form
where a listener tries to immediately write the same value
after it is notified of a change to that value.

See go/onsystemprefchanged for a longer explanation.

(In a different CL I want to make a change that exposes this
infinite loop problem, so I am fixing it first in this CL.)

Change-Id: Ie47ac2db905a54c4d6244e06b54471c36454583d
Reviewed-on: https://chromium-review.googlesource.com/c/1340305
Commit-Queue: A Olsen <olsen@chromium.org>
Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609270}
parent b0dc23de
......@@ -163,6 +163,7 @@ IN_PROC_BROWSER_TEST_F(ArcKioskAppManagerTest, Basic) {
ASSERT_EQ(app2.display_name(), apps[1]->name());
EXPECT_FALSE(manager()->GetAutoLaunchAccountId().is_valid());
EXPECT_FALSE(manager()->current_app_was_auto_launched_with_zero_delay());
CleanApps();
}
// Set auto-launch app.
......
......@@ -62,11 +62,14 @@ void StubCrosSettingsProvider::SetCurrentUserIsOwner(bool owner) {
void StubCrosSettingsProvider::DoSet(const std::string& path,
const base::Value& value) {
bool is_value_changed = false;
if (current_user_is_owner_)
values_.SetValue(path, value.CreateDeepCopy());
is_value_changed = values_.SetValue(path, value.CreateDeepCopy());
else
LOG(WARNING) << "Changing settings from non-owner, setting=" << path;
NotifyObservers(path);
if (is_value_changed || !current_user_is_owner_)
NotifyObservers(path);
}
void StubCrosSettingsProvider::SetDefaults() {
......
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