Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Side by Side Diff: chrome/browser/notifications/notification_ui_manager_mac.h

Issue 10021026: [Mac] Implement a NotificationUIManager that uses Notification Center on 10.8 for text notifications (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change notification_map_ Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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_MAC_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_MAC_H_
7 #pragma once
8
9 #import <AppKit/AppKit.h>
10
11 #include <map>
12
13 #include "base/basictypes.h"
14 #include "base/memory/scoped_nsobject.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/string16.h"
17 #include "chrome/browser/notifications/notification_ui_manager.h"
18
19 @protocol CrUserNotification;
20 class Notification;
21 @class NotificationCenterDelegate;
22 class NotificationUIManagerImpl;
23 class PrefService;
24 class Profile;
25
26 // This class is an implementation of NotificationUIManager that will send
27 // text-only (non-HTML) notifications to Notification Center on 10.8. This
28 // class is only instantiated on 10.8 and above. For HTML notifications,
29 // this class uses an instance of NotificationUIManagerImpl to present
30 // notifications in the typical way.
31 class NotificationUIManagerMac : public NotificationUIManager {
32 public:
33 explicit NotificationUIManagerMac(PrefService* local_state);
34 virtual ~NotificationUIManagerMac();
35
36 // NotificationUIManager:
37 virtual void Add(const Notification& notification,
38 Profile* profile) OVERRIDE;
39 virtual bool CancelById(const std::string& notification_id) OVERRIDE;
40 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE;
41 virtual void CancelAll() OVERRIDE;
42 virtual BalloonCollection* balloon_collection() OVERRIDE;
43 virtual NotificationPrefsManager* prefs_manager() OVERRIDE;
44 virtual void GetQueuedNotificationsForTesting(
45 std::vector<const Notification*>* notifications) OVERRIDE;
46
47 // Returns the corresponding C++ object for the Cocoa notification object,
48 // or NULL if it could not be found.
49 const Notification* FindNotificationWithCocoaNotification(
50 id<CrUserNotification> notification) const;
51
52 NotificationUIManagerImpl* builtin_manager() const {
53 return builtin_manager_.get();
54 }
55
56 private:
57 // A ControllerNotification links the Cocoa (view) notification to the C++
58 // (model) notification. This assumes ownership (i.e. does not retain a_view)
59 // of both objects and will delete them on destruction.
60 struct ControllerNotification {
61 ControllerNotification(id<CrUserNotification> a_view,
62 Notification* a_model);
63 ~ControllerNotification();
64
65 id<CrUserNotification> view;
66 Notification* model;
67
68 private:
69 DISALLOW_COPY_AND_ASSIGN(ControllerNotification);
70 };
71 typedef std::map<std::string, ControllerNotification*> NotificationMap;
72
73 // Erases a Cocoa notification from both the application and Notification
74 // Center, and deletes the corresponding C++ object.
75 bool RemoveNotification(id<CrUserNotification> notification);
76
77 // Finds a notification with a given replacement id.
78 id<CrUserNotification> FindNotificationWithReplacementId(
79 const string16& replacement_id) const;
80
81 // The class used to present HTML notifications that can't be sent to
82 // Notification Center.
83 scoped_ptr<NotificationUIManagerImpl> builtin_manager_;
84
85 // Cocoa class that receives callbacks from the NSUserNotificationCenter.
86 scoped_nsobject<NotificationCenterDelegate> delegate_;
87
88 // Maps notification_ids to ControllerNotifications. The map owns the value,
89 // so it must be deleted when remvoed from the map. This is typically handled
90 // in RemoveNotification.
91 NotificationMap notification_map_;
92
93 DISALLOW_COPY_AND_ASSIGN(NotificationUIManagerMac);
94 };
95
96 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698