Commit 65715ad8 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik Committed by Commit Bot

If Notifications service isn't registered, check if it could be activated

DBus supports launching services on demand the first time a call is made to them.
In case the service isn't currently running, check whether it would be activated
when we try to call it.
Especially in case of session restoration the browser might be launched before
the shell's notification service is fully up and running.

Change-Id: I6b2905aa1d74fe4c99a10b27637d842f7fb836cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1975711Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733842}
parent 28cbcb25
......@@ -63,6 +63,7 @@ const char kFreedesktopNotificationsPath[] = "/org/freedesktop/Notifications";
// DBus methods.
const char kMethodCloseNotification[] = "CloseNotification";
const char kMethodGetCapabilities[] = "GetCapabilities";
const char kMethodListActivatableNames[] = "ListActivatableNames";
const char kMethodNameHasOwner[] = "NameHasOwner";
const char kMethodNotify[] = "Notify";
......@@ -251,7 +252,7 @@ std::unique_ptr<ResourceFile> WriteDataToTmpFile(
return resource_file;
}
bool CheckNotificationsNameHasOwner(dbus::Bus* bus) {
bool CheckNotificationsNameHasOwnerOrIsActivatable(dbus::Bus* bus) {
dbus::ObjectProxy* dbus_proxy =
bus->GetObjectProxy(DBUS_SERVICE_DBUS, dbus::ObjectPath(DBUS_PATH_DBUS));
dbus::MethodCall name_has_owner_call(DBUS_INTERFACE_DBUS,
......@@ -263,7 +264,22 @@ bool CheckNotificationsNameHasOwner(dbus::Bus* bus) {
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT);
dbus::MessageReader reader(name_has_owner_response.get());
bool owned = false;
return name_has_owner_response && reader.PopBool(&owned) && owned;
if (name_has_owner_response && reader.PopBool(&owned) && owned)
return true;
// If the service currently isn't running, maybe it is activatable.
dbus::MethodCall list_activatable_names_call(DBUS_INTERFACE_DBUS,
kMethodListActivatableNames);
std::unique_ptr<dbus::Response> list_activatable_names_response =
dbus_proxy->CallMethodAndBlock(&list_activatable_names_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT);
if (list_activatable_names_response) {
dbus::MessageReader reader(list_activatable_names_response.get());
std::vector<std::string> activatable_names;
reader.PopArrayOfStrings(&activatable_names);
return base::Contains(activatable_names, kFreedesktopNotificationsName);
}
return false;
}
} // namespace
......@@ -441,7 +457,7 @@ class NotificationPlatformBridgeLinuxImpl
bus_ = base::MakeRefCounted<dbus::Bus>(bus_options);
}
if (!CheckNotificationsNameHasOwner(bus_.get())) {
if (!CheckNotificationsNameHasOwnerOrIsActivatable(bus_.get())) {
OnConnectionInitializationFinishedOnTaskRunner(
ConnectionInitializationStatusCode::
NATIVE_NOTIFICATIONS_NOT_SUPPORTED);
......
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