| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ |
| 6 #define CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 message_center::MessageCenterTrayDelegate* delegate); | 90 message_center::MessageCenterTrayDelegate* delegate); |
| 91 | 91 |
| 92 // Returns the notification id which this manager will use to add to message | 92 // Returns the notification id which this manager will use to add to message |
| 93 // center, for this combination of delegate id and profile. | 93 // center, for this combination of delegate id and profile. |
| 94 std::string GetMessageCenterNotificationIdForTest( | 94 std::string GetMessageCenterNotificationIdForTest( |
| 95 const std::string& delegate_id, Profile* profile); | 95 const std::string& delegate_id, Profile* profile); |
| 96 | 96 |
| 97 private: | 97 private: |
| 98 FRIEND_TEST_ALL_PREFIXES(message_center::WebNotificationTrayTest, | 98 FRIEND_TEST_ALL_PREFIXES(message_center::WebNotificationTrayTest, |
| 99 ManuallyCloseMessageCenter); | 99 ManuallyCloseMessageCenter); |
| 100 class ImageDownloadsObserver { | |
| 101 public: | |
| 102 virtual void OnDownloadsCompleted() = 0; | |
| 103 }; | |
| 104 | |
| 105 typedef base::Callback<void(const gfx::Image&)> SetImageCallback; | |
| 106 class ImageDownloads | |
| 107 : public base::SupportsWeakPtr<ImageDownloads> { | |
| 108 public: | |
| 109 ImageDownloads( | |
| 110 message_center::MessageCenter* message_center, | |
| 111 ImageDownloadsObserver* observer); | |
| 112 virtual ~ImageDownloads(); | |
| 113 | |
| 114 void StartDownloads(const Notification& notification); | |
| 115 void StartDownloadWithImage(const Notification& notification, | |
| 116 const gfx::Image* image, | |
| 117 const GURL& url, | |
| 118 const SetImageCallback& callback); | |
| 119 void StartDownloadByKey(const Notification& notification, | |
| 120 const char* key, | |
| 121 int size, | |
| 122 const SetImageCallback& callback); | |
| 123 | |
| 124 // FaviconHelper callback. | |
| 125 void DownloadComplete(const SetImageCallback& callback, | |
| 126 int download_id, | |
| 127 int http_status_code, | |
| 128 const GURL& image_url, | |
| 129 const std::vector<SkBitmap>& bitmaps, | |
| 130 const std::vector<gfx::Size>& original_bitmap_sizes); | |
| 131 private: | |
| 132 // Used to keep track of the number of pending downloads. Once this | |
| 133 // reaches zero, we can tell the delegate that we don't need the | |
| 134 // RenderViewHost anymore. | |
| 135 void AddPendingDownload(); | |
| 136 void PendingDownloadCompleted(); | |
| 137 | |
| 138 // Weak reference to global message center. | |
| 139 message_center::MessageCenter* message_center_; | |
| 140 | |
| 141 // Count of downloads that remain. | |
| 142 size_t pending_downloads_; | |
| 143 | |
| 144 // Weak. | |
| 145 ImageDownloadsObserver* observer_; | |
| 146 | |
| 147 DISALLOW_COPY_AND_ASSIGN(ImageDownloads); | |
| 148 }; | |
| 149 | 100 |
| 150 // This class keeps a set of original Notification objects and corresponding | 101 // This class keeps a set of original Notification objects and corresponding |
| 151 // Profiles, so when MessageCenter calls back with a notification_id, this | 102 // Profiles, so when MessageCenter calls back with a notification_id, this |
| 152 // class has necessary mapping to other source info - for example, it calls | 103 // class has necessary mapping to other source info - for example, it calls |
| 153 // NotificationDelegate supplied by client when someone clicks on a | 104 // NotificationDelegate supplied by client when someone clicks on a |
| 154 // Notification in MessageCenter. Likewise, if a Profile or Extension is | 105 // Notification in MessageCenter. Likewise, if a Profile or Extension is |
| 155 // being removed, the map makes it possible to revoke the notifications from | 106 // being removed, the map makes it possible to revoke the notifications from |
| 156 // MessageCenter. To keep that set, we use the private ProfileNotification | 107 // MessageCenter. To keep that set, we use the private ProfileNotification |
| 157 // class that stores a superset of all information about a notification. | 108 // class that stores a superset of all information about a notification. |
| 158 | 109 |
| 159 // TODO(dimich): Consider merging all 4 types (Notification, | 110 // TODO(dimich): Consider merging all 4 types (Notification, |
| 160 // QueuedNotification, ProfileNotification and NotificationList::Notification) | 111 // QueuedNotification, ProfileNotification and NotificationList::Notification) |
| 161 // into a single class. | 112 // into a single class. |
| 162 class ProfileNotification : public ImageDownloadsObserver { | 113 class ProfileNotification { |
| 163 public: | 114 public: |
| 164 ProfileNotification(Profile* profile, | 115 ProfileNotification(Profile* profile, |
| 165 const Notification& notification, | 116 const Notification& notification, |
| 166 message_center::MessageCenter* message_center); | 117 message_center::MessageCenter* message_center); |
| 167 virtual ~ProfileNotification(); | 118 virtual ~ProfileNotification(); |
| 168 | 119 |
| 169 void StartDownloads(); | |
| 170 | |
| 171 // Overridden from ImageDownloadsObserver. | |
| 172 virtual void OnDownloadsCompleted() override; | |
| 173 | |
| 174 Profile* profile() const { return profile_; } | 120 Profile* profile() const { return profile_; } |
| 175 const Notification& notification() const { return notification_; } | 121 const Notification& notification() const { return notification_; } |
| 176 | 122 |
| 177 // Route a new notification to an app/extension. | 123 // Route a new notification to an app/extension. |
| 178 void AddToAlternateProvider(const std::string extension_id); | 124 void AddToAlternateProvider(const std::string extension_id); |
| 179 | 125 |
| 180 private: | 126 private: |
| 181 // Weak, guaranteed not to be used after profile removal by parent class. | 127 // Weak, guaranteed not to be used after profile removal by parent class. |
| 182 Profile* profile_; | 128 Profile* profile_; |
| 183 Notification notification_; | 129 Notification notification_; |
| 184 // Track the downloads for this notification so the notification can be | |
| 185 // updated properly. | |
| 186 scoped_ptr<ImageDownloads> downloads_; | |
| 187 }; | 130 }; |
| 188 | 131 |
| 189 scoped_ptr<message_center::MessageCenterTrayDelegate> tray_; | 132 scoped_ptr<message_center::MessageCenterTrayDelegate> tray_; |
| 190 message_center::MessageCenter* message_center_; // Weak, global. | 133 message_center::MessageCenter* message_center_; // Weak, global. |
| 191 | 134 |
| 192 // Use a map by notification_id since this mapping is the most often used. | 135 // Use a map by notification_id since this mapping is the most often used. |
| 193 typedef std::map<std::string, ProfileNotification*> NotificationMap; | 136 typedef std::map<std::string, ProfileNotification*> NotificationMap; |
| 194 NotificationMap profile_notifications_; | 137 NotificationMap profile_notifications_; |
| 195 | 138 |
| 196 // Helpers that add/remove the notification from local map. | 139 // Helpers that add/remove the notification from local map. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 // Keeps track of all notification statistics for UMA purposes. | 181 // Keeps track of all notification statistics for UMA purposes. |
| 239 MessageCenterStatsCollector stats_collector_; | 182 MessageCenterStatsCollector stats_collector_; |
| 240 | 183 |
| 241 // Keeps track of notifications specific to Google Now for UMA purposes. | 184 // Keeps track of notifications specific to Google Now for UMA purposes. |
| 242 GoogleNowNotificationStatsCollector google_now_stats_collector_; | 185 GoogleNowNotificationStatsCollector google_now_stats_collector_; |
| 243 | 186 |
| 244 DISALLOW_COPY_AND_ASSIGN(MessageCenterNotificationManager); | 187 DISALLOW_COPY_AND_ASSIGN(MessageCenterNotificationManager); |
| 245 }; | 188 }; |
| 246 | 189 |
| 247 #endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ | 190 #endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ |
| OLD | NEW |