Commit 7a5d8fed authored by Alexey Baskakov's avatar Alexey Baskakov Committed by Commit Bot

WebApp: Fix WebAppSyncBridge::SetAppIsDisabled

We should commit ScopedRegistryUpdate before calling the notification.

Bug: 1069605
Change-Id: I161fa70218531b194a49c8c344a87bfd2f1005e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2215396
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarEric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarAya Elsayed <ayaelattar@google.com>
Cr-Commit-Position: refs/heads/master@{#772014}
parent e9c58c10
......@@ -32,9 +32,7 @@ class AppRegistrarObserver : public base::CheckedObserver {
}
// The disabled status WebApp::chromeos_data().is_disabled of the app backing
// |app_id| is updated. Sometimes OnWebAppDisabledStateChanged is called but
// WebApp::chromos_data().is_disabled isn't updated yet, that's why it's
// recommended to depend on the value of |is_disabled|.
// |app_id| changed.
virtual void OnWebAppDisabledStateChanged(const AppId& app_id,
bool is_disabled) {}
};
......
......@@ -183,19 +183,25 @@ void WebAppSyncBridge::SetAppIsDisabled(const AppId& app_id, bool is_disabled) {
if (!IsChromeOs())
return;
ScopedRegistryUpdate update(this);
WebApp* web_app = update->UpdateApp(app_id);
if (!web_app)
return;
bool notify = false;
{
ScopedRegistryUpdate update(this);
WebApp* web_app = update->UpdateApp(app_id);
if (!web_app)
return;
auto cros_data = web_app->chromeos_data();
DCHECK(cros_data.has_value());
base::Optional<WebAppChromeOsData> cros_data = web_app->chromeos_data();
DCHECK(cros_data.has_value());
if (cros_data->is_disabled != is_disabled) {
cros_data->is_disabled = is_disabled;
web_app->SetWebAppChromeOsData(cros_data);
registrar_->NotifyWebAppDisabledStateChanged(app_id, is_disabled);
if (cros_data->is_disabled != is_disabled) {
cros_data->is_disabled = is_disabled;
web_app->SetWebAppChromeOsData(std::move(cros_data));
notify = true;
}
}
if (notify)
registrar_->NotifyWebAppDisabledStateChanged(app_id, is_disabled);
}
void WebAppSyncBridge::SetAppIsLocallyInstalled(const AppId& app_id,
......
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