Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / notifications / notification_ui_manager.h
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.
4
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_H_
7
8 #include <set>
9 #include <string>
10 #include <vector>
11
12 #include "base/basictypes.h"
13
14 typedef void* ProfileID;
15
16 class GURL;
17 class Notification;
18 class PrefService;
19 class Profile;
20
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);
39   }
40
41   virtual ~NotificationUIManager() {}
42
43   // Creates an initialized UI manager.
44   static NotificationUIManager* Create(PrefService* local_state);
45
46   // Adds a notification to be displayed. Virtual for unit test override.
47   virtual void Add(const Notification& notification, Profile* profile) = 0;
48
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;
52
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;
60
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;
68
69   // Returns the set of all delegate IDs for notifications from the passed
70   // |profile| and |source|.
71   virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin(
72       Profile* profile,
73       const GURL& source) = 0;
74
75   // Removes notifications matching the |source_origin| (which could be an
76   // extension ID). Returns true if anything was removed.
77   virtual bool CancelAllBySourceOrigin(const GURL& source_origin) = 0;
78
79   // Removes notifications matching |profile_id|. Returns true if any were
80   // removed.
81   virtual bool CancelAllByProfile(ProfileID profile_id) = 0;
82
83   // Cancels all pending notifications and closes anything currently showing.
84   // Used when the app is terminating.
85   virtual void CancelAll() = 0;
86
87  protected:
88   NotificationUIManager() {}
89
90  private:
91   DISALLOW_COPY_AND_ASSIGN(NotificationUIManager);
92 };
93
94 #endif  // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_H_