blob: 9da6936079142501dc8155c8a34625c62ab34692 [file] [log] [blame]
miguelg23cd2dd72016-04-21 15:24:031// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_DISPLAY_SERVICE_H_
6#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_DISPLAY_SERVICE_H_
7
miguelgabf610a2017-06-02 17:31:438#include <map>
miguelgbfe768352017-03-20 15:34:319#include <memory>
miguelg23cd2dd72016-04-21 15:24:0310#include <set>
11#include <string>
miguelg87e986d2016-07-08 18:04:4412
miguelgbfe768352017-03-20 15:34:3113#include "base/callback_forward.h"
miguelg23cd2dd72016-04-21 15:24:0314#include "base/macros.h"
miguelg87e986d2016-07-08 18:04:4415#include "chrome/browser/notifications/notification_common.h"
Peter Beverloo7426194d2017-12-11 17:39:3816#include "chrome/browser/notifications/notification_handler.h"
miguelg23cd2dd72016-04-21 15:24:0317#include "components/keyed_service/core/keyed_service.h"
18
miguelg23cd2dd72016-04-21 15:24:0319class Profile;
20
Evan Stade4755cf22017-10-17 18:35:4321namespace message_center {
22class Notification;
23}
24
Peter Beverloo7426194d2017-12-11 17:39:3825// Profile-bound service that enables user-visible notifications to be displayed
26// and managed. Notifications may either be presented using a notification
27// center provided by the platform, or by Chrome's Message Center.
miguelg23cd2dd72016-04-21 15:24:0328class NotificationDisplayService : public KeyedService {
29 public:
Peter Beverloo7426194d2017-12-11 17:39:3830 ~NotificationDisplayService() override;
31
32 // Callback to be used with the GetDisplayed() method. Includes the set of
33 // notification ids that is being displayed to the user. The
34 // |supports_synchronization| callback indicates whether the platform has the
35 // ability to query which notifications are still being displayed.
36 //
37 // TODO(peter): Rename |supports_synchronization| to |supported|.
38 // TODO(peter): Change this to be a base::OnceCallback, remove use of the
39 // std::unique_ptr<> in favor of move semantics.
miguelgbfe768352017-03-20 15:34:3140 using DisplayedNotificationsCallback =
41 base::Callback<void(std::unique_ptr<std::set<std::string>>,
42 bool /* supports_synchronization */)>;
Evan Stade6e154152017-11-10 01:58:2543
Peter Beverloo7426194d2017-12-11 17:39:3844 // Returns an instance of the display service for the given |profile|.
Evan Stade6e154152017-11-10 01:58:2545 static NotificationDisplayService* GetForProfile(Profile* profile);
46
Evan Stade5d6e4692017-12-08 17:43:5247 // Returns the NDS for system notifications which aren't tied to a particular
48 // user. Currently only implemented on Chrome OS. TODO(estade): implement
49 // elsewhere as needed.
50 static NotificationDisplayService* GetForSystemNotifications();
51
Peter Beverloo7426194d2017-12-11 17:39:3852 // Displays the |notification| of type |notification_type|. The |metadata|
53 // may be provided for certain notification types that require additional
54 // information for the notification to be displayed.
Evan Stade4ebefdf42017-09-21 23:50:1855 virtual void Display(
Peter Beverloo6dba2e102017-11-23 17:46:3356 NotificationHandler::Type notification_type,
Evan Stade4755cf22017-10-17 18:35:4357 const message_center::Notification& notification,
Evan Stade4ebefdf42017-09-21 23:50:1858 std::unique_ptr<NotificationCommon::Metadata> metadata = nullptr) = 0;
miguelg23cd2dd72016-04-21 15:24:0359
Peter Beverloo7426194d2017-12-11 17:39:3860 // Closes the notification having |notification_id| of |notification_type|.
Peter Beverloo6dba2e102017-11-23 17:46:3361 virtual void Close(NotificationHandler::Type notification_type,
miguelg87e986d2016-07-08 18:04:4462 const std::string& notification_id) = 0;
miguelg23cd2dd72016-04-21 15:24:0363
Peter Beverloo7426194d2017-12-11 17:39:3864 // Gets the IDs of currently displaying notifications and invokes |callback|
65 // once available. Not all backends support retrieving this information.
peterb5298ae2017-04-11 21:52:5166 virtual void GetDisplayed(const DisplayedNotificationsCallback& callback) = 0;
miguelg23cd2dd72016-04-21 15:24:0367
Peter Beverloo7426194d2017-12-11 17:39:3868 protected:
69 NotificationDisplayService() = default;
Evan Stade0bf465e52017-10-03 18:12:0070
Evan Stadecc63b182017-09-26 16:05:1271 private:
miguelg23cd2dd72016-04-21 15:24:0372 DISALLOW_COPY_AND_ASSIGN(NotificationDisplayService);
73};
74
75#endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_DISPLAY_SERVICE_H_