Chromium Code Reviews| Index: chrome/browser/notifications/dbus_notification_manager.cc | 
| diff --git a/chrome/browser/notifications/dbus_notification_manager.cc b/chrome/browser/notifications/dbus_notification_manager.cc | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..e7162c8c08dad799d27a44b7bb5be5d2abba74ad | 
| --- /dev/null | 
| +++ b/chrome/browser/notifications/dbus_notification_manager.cc | 
| @@ -0,0 +1,67 @@ | 
| +// Copyright 2017 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#include "chrome/browser/notifications/dbus_notification_manager.h" | 
| + | 
| +#include "base/strings/utf_string_conversions.h" | 
| + | 
| +namespace { | 
| + | 
| +const char kFreedesktopNotificationsName[] = "org.freedesktop.Notifications"; | 
| +const char kFreedesktopNotificationsPath[] = "/org/freedesktop/Notifications"; | 
| + | 
| +} // anonymous namespace | 
| + | 
| +// static | 
| +DbusNotificationManager* DbusNotificationManager::CreateDbusNotificationManager( | 
| + message_center::MessageCenter* message_center) { | 
| + GDBusProxy* notification_proxy = g_dbus_proxy_new_for_bus_sync( | 
| + G_BUS_TYPE_SESSION, | 
| + static_cast<GDBusProxyFlags>(G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | | 
| + G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS | | 
| + G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START), | 
| + nullptr, kFreedesktopNotificationsName, kFreedesktopNotificationsPath, | 
| + kFreedesktopNotificationsName, nullptr, nullptr); | 
| + if (notification_proxy) | 
| + return new DbusNotificationManager(message_center, notification_proxy); | 
| + return nullptr; | 
| +} | 
| + | 
| +DbusNotificationManager::DbusNotificationManager( | 
| + message_center::MessageCenter* message_center, | 
| + GDBusProxy* notification_proxy) | 
| + : message_center_(message_center), notification_proxy_(notification_proxy) { | 
| + message_center_->AddObserver(this); | 
| +} | 
| + | 
| +DbusNotificationManager::~DbusNotificationManager() { | 
| + g_object_unref(notification_proxy_); | 
| +} | 
| + | 
| +void DbusNotificationManager::OnNotificationAdded( | 
| + const std::string& notification_id) { | 
| + // TODO(thomasanderson): Add a complete implemenatation. | 
| 
 
Peter Beverloo
2017/04/03 23:39:29
What's the best documentation I can read on the av
 
Tom (Use chromium acct)
2017/04/04 02:43:17
The Freedesktop notifications spec:
https://develo
 
 | 
| + message_center::Notification* notification = | 
| + message_center_->FindVisibleNotificationById(notification_id); | 
| + if (!notification) | 
| + return; | 
| + g_dbus_proxy_call( | 
| + notification_proxy_, "Notify", | 
| + g_variant_new("(susssasa{sv}i)", "", 0, "", | 
| + base::UTF16ToUTF8(notification->title()).c_str(), | 
| + base::UTF16ToUTF8(notification->message()).c_str(), nullptr, | 
| + nullptr, -1), | 
| + G_DBUS_CALL_FLAGS_NONE, -1, nullptr, nullptr, nullptr); | 
| +} | 
| + | 
| +void DbusNotificationManager::OnNotificationRemoved( | 
| + const std::string& notification_id, | 
| + bool by_user) { | 
| + NOTIMPLEMENTED(); | 
| +} | 
| + | 
| +void DbusNotificationManager::OnNotificationUpdated( | 
| + const std::string& notification_id) { | 
| + NOTIMPLEMENTED(); | 
| +} |