Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / notifications / notification_ui_manager.h
blob64c06a3d4ad717dad823c3c063919061f351b06e
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 static NotificationUIManager* Create(PrefService* local_state);
46 // Adds a notification to be displayed. Virtual for unit test override.
47 virtual void Add(const Notification& notification, Profile* profile) = 0;
49 // Updates an existing notification. If |update_progress_only|, assume
50 // only message and progress properties are updated.
51 virtual bool Update(const Notification& notification, Profile* profile) = 0;
53 // Returns the pointer to a notification if it match the supplied ID, either
54 // currently displayed or in the queue.
55 // This function can be bound for delayed execution, where a profile pointer
56 // may not be valid. Hence caller needs to call the static GetProfileID(...)
57 // function to turn a profile pointer into a profile id and pass that in.
58 virtual const Notification* FindById(const std::string& delegate_id,
59 ProfileID profile_id) const = 0;
61 // Removes any notifications matching the supplied ID, either currently
62 // displayed or in the queue. Returns true if anything was removed.
63 // This function can be bound for delayed execution, where a profile pointer
64 // may not be valid. Hence caller needs to call the static GetProfileID(...)
65 // function to turn a profile pointer into a profile id and pass that in.
66 virtual bool CancelById(const std::string& delegate_id,
67 ProfileID profile_id) = 0;
69 // Returns the set of all delegate IDs for notifications from the passed
70 // |profile_id| and |source|.
71 virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin(
72 ProfileID profile_id,
73 const GURL& source) = 0;
75 // Returns the set of all delegate IDs for notifications from |profile_id|.
76 virtual std::set<std::string> GetAllIdsByProfile(ProfileID profile_id) = 0;
78 // Removes notifications matching the |source_origin| (which could be an
79 // extension ID). Returns true if anything was removed.
80 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) = 0;
82 // Removes notifications matching |profile_id|. Returns true if any were
83 // removed.
84 virtual bool CancelAllByProfile(ProfileID profile_id) = 0;
86 // Cancels all pending notifications and closes anything currently showing.
87 // Used when the app is terminating.
88 virtual void CancelAll() = 0;
90 protected:
91 NotificationUIManager() {}
93 private:
94 DISALLOW_COPY_AND_ASSIGN(NotificationUIManager);
97 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_H_