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