| Index: chrome/browser/notifications/notification_display_service_proxy.cc
|
| diff --git a/chrome/browser/notifications/notification_display_service_proxy.cc b/chrome/browser/notifications/notification_display_service_proxy.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..fb82e7e0aa4e7b4c1ccb3263268b833963ea6794
|
| --- /dev/null
|
| +++ b/chrome/browser/notifications/notification_display_service_proxy.cc
|
| @@ -0,0 +1,102 @@
|
| +// 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/notification_display_service_proxy.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/memory/ptr_util.h"
|
| +#include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/notifications/message_center_display_service.h"
|
| +#include "chrome/browser/notifications/native_notification_display_service.h"
|
| +#include "chrome/browser/notifications/notification.h"
|
| +#include "chrome/browser/notifications/notification_platform_bridge_linux.h"
|
| +
|
| +NotificationDisplayServiceProxy::NotificationDisplayServiceProxy(
|
| + Profile* profile)
|
| + : profile_(profile) {
|
| + // TODO(thomasanderson): Add interface to avoid this cast?
|
| + auto* npbl = static_cast<NotificationPlatformBridgeLinux*>(
|
| + g_browser_process->notification_platform_bridge());
|
| + npbl->IsConnected(base::Bind(
|
| + &NotificationDisplayServiceProxy::OnNotificationPlatformBridgeInitialized,
|
| + base::Unretained(this)));
|
| +}
|
| +
|
| +NotificationDisplayServiceProxy::~NotificationDisplayServiceProxy() = default;
|
| +
|
| +NotificationDisplayService*
|
| +NotificationDisplayServiceProxy::GetNotificationDisplayService() const {
|
| + // Can't have both impls at once.
|
| + DCHECK(!native_notification_display_service_ ||
|
| + !message_center_display_service_);
|
| +
|
| + if (native_notification_display_service_) {
|
| + return native_notification_display_service_.get();
|
| + } else if (message_center_display_service_) {
|
| + return message_center_display_service_.get();
|
| + }
|
| +
|
| + return nullptr;
|
| +}
|
| +
|
| +void NotificationDisplayServiceProxy::OnNotificationPlatformBridgeInitialized(
|
| + bool success) {
|
| + if (success) {
|
| + native_notification_display_service_ =
|
| + base::MakeUnique<NativeNotificationDisplayService>(
|
| + profile_, g_browser_process->notification_platform_bridge());
|
| + } else {
|
| + // TODO(thomasanderson): clean up |g_browser_process->notification_bridge_|?
|
| + message_center_display_service_ =
|
| + base::MakeUnique<MessageCenterDisplayService>(
|
| + profile_, g_browser_process->notification_ui_manager());
|
| + }
|
| +
|
| + NotificationDisplayService* nds = GetNotificationDisplayService();
|
| + while (!actions_.empty()) {
|
| + actions_.front().Run(nds);
|
| + actions_.pop();
|
| + }
|
| +}
|
| +
|
| +void NotificationDisplayServiceProxy::RunAction(
|
| + base::Callback<void(NotificationDisplayService*)> action) {
|
| + NotificationDisplayService* nds = GetNotificationDisplayService();
|
| + if (nds)
|
| + action.Run(nds);
|
| + else
|
| + actions_.push(action);
|
| +}
|
| +
|
| +void NotificationDisplayServiceProxy::Display(
|
| + NotificationCommon::Type notification_type,
|
| + const std::string& notification_id,
|
| + const Notification& notification) {
|
| + RunAction(base::Bind(
|
| + [](NotificationCommon::Type notification_type,
|
| + const std::string& notification_id, const Notification& notification,
|
| + NotificationDisplayService* nds) {
|
| + nds->Display(notification_type, notification_id, notification);
|
| + },
|
| + notification_type, notification_id, notification));
|
| +}
|
| +
|
| +void NotificationDisplayServiceProxy::Close(
|
| + NotificationCommon::Type notification_type,
|
| + const std::string& notification_id) {
|
| + RunAction(base::Bind(
|
| + [](NotificationCommon::Type notification_type,
|
| + const std::string& notification_id, NotificationDisplayService* nds) {
|
| + nds->Close(notification_type, notification_id);
|
| + },
|
| + notification_type, notification_id));
|
| +}
|
| +
|
| +void NotificationDisplayServiceProxy::GetDisplayed(
|
| + const DisplayedNotificationsCallback& callback) {
|
| + RunAction(base::Bind(
|
| + [](const DisplayedNotificationsCallback& callback,
|
| + NotificationDisplayService* nds) { nds->GetDisplayed(callback); },
|
| + callback));
|
| +}
|
|
|