Roll src/third_party/WebKit aa8346d:dbb8a38 (svn 202629:202630)
[chromium-blink-merge.git] / chrome / browser / notifications / notification_ui_manager.h
blobd86a9a578492f206dd9c001ae2b216d42643d76c
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_H_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
14 typedef void* ProfileID;
16 class GURL;
17 class Notification;
18 class PrefService;
19 class Profile;
21 // This virtual interface is used to manage the UI surfaces for desktop
22 // notifications. There is just one instance for all profiles.
23 // This represents the middle layer of notification and it's aware of profile.
24 // It identifies a notification by the id string and a profile, hence two
25 // notifications from two different profiles, even though they may have
26 // identical ids, will not be considered the same notification.
27 // This interface will generate a new id behind the scene based on the id string
28 // and the profile's characteristics for each notification and use this new id
29 // to call lower layer MessageCenter interface which is profile agnostic.
30 // Therefore the ids passed into this interface are not the same as those passed
31 // into the MessageCenter interface.
32 class NotificationUIManager {
33 public:
34 // Convert a profile pointer into an opaque profile id, which can be safely
35 // used by FindById() and CancelById() even after a profile may have been
36 // destroyed.
37 static ProfileID GetProfileID(Profile* profile) {
38 return static_cast<ProfileID>(profile);
41 virtual ~NotificationUIManager() {}
43 // Creates an initialized UI manager.
44 // TODO(dewittj): Remove the PrefService argument which is unused. See
45 // crbug.com/530376
46 static NotificationUIManager* Create(PrefService* local_state);
48 // Adds a notification to be displayed. Virtual for unit test override.
49 virtual void Add(const Notification& notification, Profile* profile) = 0;
51 // Updates an existing notification. If |update_progress_only|, assume
52 // only message and progress properties are updated.
53 virtual bool Update(const Notification& notification, Profile* profile) = 0;
55 // Returns the pointer to a notification if it match the supplied ID, either
56 // currently displayed or in the queue.
57 // This function can be bound for delayed execution, where a profile pointer
58 // may not be valid. Hence caller needs to call the static GetProfileID(...)
59 // function to turn a profile pointer into a profile id and pass that in.
60 virtual const Notification* FindById(const std::string& delegate_id,
61 ProfileID profile_id) const = 0;
63 // Removes any notifications matching the supplied ID, either currently
64 // displayed or in the queue. Returns true if anything was removed.
65 // This function can be bound for delayed execution, where a profile pointer
66 // may not be valid. Hence caller needs to call the static GetProfileID(...)
67 // function to turn a profile pointer into a profile id and pass that in.
68 virtual bool CancelById(const std::string& delegate_id,
69 ProfileID profile_id) = 0;
71 // Returns the set of all delegate IDs for notifications from the passed
72 // |profile_id| and |source|.
73 virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin(
74 ProfileID profile_id,
75 const GURL& source) = 0;
77 // Returns the set of all delegate IDs for notifications from |profile_id|.
78 virtual std::set<std::string> GetAllIdsByProfile(ProfileID profile_id) = 0;
80 // Removes notifications matching the |source_origin| (which could be an
81 // extension ID). Returns true if anything was removed.
82 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) = 0;
84 // Removes notifications matching |profile_id|. Returns true if any were
85 // removed.
86 virtual bool CancelAllByProfile(ProfileID profile_id) = 0;
88 // Cancels all pending notifications and closes anything currently showing.
89 // Used when the app is terminating.
90 virtual void CancelAll() = 0;
92 protected:
93 NotificationUIManager() {}
95 private:
96 DISALLOW_COPY_AND_ASSIGN(NotificationUIManager);
99 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_H_