| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 private: | 61 private: |
| 62 class ImageDownloadsObserver { | 62 class ImageDownloadsObserver { |
| 63 public: | 63 public: |
| 64 virtual void OnDownloadsCompleted() = 0; | 64 virtual void OnDownloadsCompleted() = 0; |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 typedef base::Callback<void(const gfx::Image&)> SetImageCallback; | 67 typedef base::Callback<void(const gfx::Image&)> SetImageCallback; |
| 68 class ImageDownloads | 68 class ImageDownloads |
| 69 : public base::SupportsWeakPtr<ImageDownloads> { | 69 : public base::SupportsWeakPtr<ImageDownloads> { |
| 70 public: | 70 public: |
| 71 ImageDownloads( | 71 ImageDownloads(message_center::Notification* notification, |
| 72 message_center::MessageCenter* message_center, | 72 ImageDownloadsObserver* observer); |
| 73 ImageDownloadsObserver* observer); | |
| 74 virtual ~ImageDownloads(); | 73 virtual ~ImageDownloads(); |
| 75 | 74 |
| 76 void StartDownloads(const Notification& notification); | 75 void StartDownloads(const Notification& notification); |
| 77 void StartDownloadWithImage(const Notification& notification, | 76 void StartDownloadByKey(content::RenderViewHost* host, |
| 78 const gfx::Image* image, | 77 const base::DictionaryValue* optional_fields, |
| 79 const GURL& url, | |
| 80 int size, | |
| 81 const SetImageCallback& callback); | |
| 82 void StartDownloadByKey(const Notification& notification, | |
| 83 const char* key, | 78 const char* key, |
| 84 int size, | 79 int size, |
| 85 const SetImageCallback& callback); | 80 const SetImageCallback& callback); |
| 81 void StartDownloadByURL(content::RenderViewHost* host, |
| 82 const GURL& url, |
| 83 int size, |
| 84 const SetImageCallback& callback); |
| 86 | 85 |
| 87 // FaviconHelper callback. | 86 // FaviconHelper callback. |
| 88 void DownloadComplete(const SetImageCallback& callback, | 87 void DownloadComplete(const SetImageCallback& callback, |
| 89 int download_id, | 88 int download_id, |
| 90 int http_status_code, | 89 int http_status_code, |
| 91 const GURL& image_url, | 90 const GURL& image_url, |
| 92 int requested_size, | 91 int requested_size, |
| 93 const std::vector<SkBitmap>& bitmaps); | 92 const std::vector<SkBitmap>& bitmaps); |
| 93 |
| 94 void SetIcon(const gfx::Image& icon); |
| 95 void SetImage(const gfx::Image& image); |
| 96 void SetButtonIcon(size_t button_number, const gfx::Image& image); |
| 97 |
| 94 private: | 98 private: |
| 95 // Used to keep track of the number of pending downloads. Once this | 99 // Used to keep track of the number of pending downloads. Once this |
| 96 // reaches zero, we can tell the delegate that we don't need the | 100 // reaches zero, we can tell the delegate that we don't need the |
| 97 // RenderViewHost anymore. | 101 // RenderViewHost anymore. |
| 98 void AddPendingDownload(); | 102 void AddPendingDownload(); |
| 99 void PendingDownloadCompleted(); | 103 void PendingDownloadCompleted(); |
| 100 | 104 |
| 101 // Weak reference to global message center. | 105 // Weak, lifetime is that of the ProfileNotification. |
| 102 message_center::MessageCenter* message_center_; | 106 // Notification model that is being filled out with image data. |
| 107 message_center::Notification* message_center_notification_; |
| 103 | 108 |
| 104 // Count of downloads that remain. | 109 // Count of downloads that remain. |
| 105 size_t pending_downloads_; | 110 size_t pending_downloads_; |
| 106 | 111 |
| 107 // Weak. | 112 // Weak. |
| 108 ImageDownloadsObserver* observer_; | 113 ImageDownloadsObserver* observer_; |
| 109 | 114 |
| 110 DISALLOW_COPY_AND_ASSIGN(ImageDownloads); | 115 DISALLOW_COPY_AND_ASSIGN(ImageDownloads); |
| 111 }; | 116 }; |
| 112 | 117 |
| 113 // This class keeps a set of original Notification objects and corresponding | 118 // This class keeps a set of original Notification objects and corresponding |
| 114 // Profiles, so when MessageCenter calls back with a notification_id, this | 119 // Profiles, so when MessageCenter calls back with a notification_id, this |
| 115 // class has necessary mapping to other source info - for example, it calls | 120 // class has necessary mapping to other source info - for example, it calls |
| 116 // NotificationDelegate supplied by client when someone clicks on a | 121 // NotificationDelegate supplied by client when someone clicks on a |
| 117 // Notification in MessageCenter. Likewise, if a Profile or Extension is | 122 // Notification in MessageCenter. Likewise, if a Profile or Extension is |
| 118 // being removed, the map makes it possible to revoke the notifications from | 123 // being removed, the map makes it possible to revoke the notifications from |
| 119 // MessageCenter. To keep that set, we use the private ProfileNotification | 124 // MessageCenter. To keep that set, we use the private ProfileNotification |
| 120 // class that stores a superset of all information about a notification. | 125 // class that stores a superset of all information about a notification. |
| 121 | 126 |
| 122 // TODO(dimich): Consider merging all 4 types (Notification, | 127 // TODO(dimich): Consider merging all 4 types (Notification, |
| 123 // QueuedNotification, ProfileNotification and NotificationList::Notification) | 128 // QueuedNotification, ProfileNotification and NotificationList::Notification) |
| 124 // into a single class. | 129 // into a single class. |
| 125 class ProfileNotification : public ImageDownloadsObserver { | 130 class ProfileNotification : public ImageDownloadsObserver { |
| 126 public: | 131 public: |
| 132 // Use for new notifications. |
| 127 ProfileNotification(Profile* profile, | 133 ProfileNotification(Profile* profile, |
| 128 const Notification& notification, | 134 const Notification& notification, |
| 129 message_center::MessageCenter* message_center); | 135 message_center::MessageCenter* message_center); |
| 136 // Use to update notifications. |
| 137 ProfileNotification(Profile* profile, |
| 138 const Notification& notification, |
| 139 message_center::MessageCenter* message_center, |
| 140 const std::string& updated_id); |
| 130 virtual ~ProfileNotification(); | 141 virtual ~ProfileNotification(); |
| 131 | 142 |
| 132 void StartDownloads(); | 143 void StartDownloads(); |
| 133 | 144 |
| 134 // Overridden from ImageDownloadsObserver. | 145 // Overridden from ImageDownloadsObserver. |
| 135 virtual void OnDownloadsCompleted() OVERRIDE; | 146 virtual void OnDownloadsCompleted() OVERRIDE; |
| 136 | 147 |
| 137 Profile* profile() const { return profile_; } | 148 Profile* profile() const { return profile_; } |
| 138 const Notification& notification() const { return notification_; } | 149 const Notification& notification() const { return notification_; } |
| 139 | 150 |
| 140 // Returns extension_id if the notification originates from an extension, | 151 // Returns extension_id if the notification originates from an extension, |
| 141 // empty string otherwise. | 152 // empty string otherwise. |
| 142 std::string GetExtensionId(); | 153 std::string GetExtensionId(); |
| 143 | 154 |
| 144 private: | 155 private: |
| 156 // Initializes message center notification and starts downloads. |
| 157 void Init(); |
| 145 // Weak, guaranteed not to be used after profile removal by parent class. | 158 // Weak, guaranteed not to be used after profile removal by parent class. |
| 146 Profile* profile_; | 159 Profile* profile_; |
| 147 Notification notification_; | 160 Notification notification_; |
| 161 // Weak, global lifetime. |
| 162 message_center::MessageCenter* message_center_; |
| 163 // Temporary data structure that holds the bits that have been downloaded |
| 164 // until they can be passed to the message center. |
| 165 scoped_ptr<message_center::Notification> message_center_notification_; |
| 166 // Whether to update message center or to add to it. |
| 167 bool update_; |
| 168 // Which id to update. |
| 169 std::string updated_id_; |
| 148 // Track the downloads for this notification so the notification can be | 170 // Track the downloads for this notification so the notification can be |
| 149 // updated properly. | 171 // updated properly. |
| 150 scoped_ptr<ImageDownloads> downloads_; | 172 scoped_ptr<ImageDownloads> downloads_; |
| 151 }; | 173 }; |
| 152 | 174 |
| 153 scoped_ptr<message_center::MessageCenterTrayDelegate> tray_; | 175 scoped_ptr<message_center::MessageCenterTrayDelegate> tray_; |
| 154 message_center::MessageCenter* message_center_; // Weak, global. | 176 message_center::MessageCenter* message_center_; // Weak, global. |
| 155 | 177 |
| 156 // Use a map by notification_id since this mapping is the most often used. | 178 // Use a map by notification_id since this mapping is the most often used. |
| 157 typedef std::map<std::string, ProfileNotification*> NotificationMap; | 179 typedef std::map<std::string, ProfileNotification*> NotificationMap; |
| 158 NotificationMap profile_notifications_; | 180 NotificationMap profile_notifications_; |
| 159 | 181 |
| 160 scoped_ptr<MessageCenterSettingsController> settings_controller_; | 182 scoped_ptr<MessageCenterSettingsController> settings_controller_; |
| 161 | 183 |
| 162 // Helpers that add/remove the notification from local map and MessageCenter. | 184 // Helpers that add/remove the notification from local map and MessageCenter. |
| 163 // They take ownership of profile_notification object. | 185 // They take ownership of profile_notification object. |
| 164 void AddProfileNotification(ProfileNotification* profile_notification); | 186 void AddProfileNotification(ProfileNotification* profile_notification); |
| 165 void RemoveProfileNotification(ProfileNotification* profile_notification, | 187 void RemoveProfileNotification(ProfileNotification* profile_notification, |
| 166 bool by_user); | 188 bool by_user); |
| 167 | 189 |
| 168 // Returns the ProfileNotification for the |id|, or NULL if no such | 190 // Returns the ProfileNotification for the |id|, or NULL if no such |
| 169 // notification is found. | 191 // notification is found. |
| 170 ProfileNotification* FindProfileNotification(const std::string& id) const; | 192 ProfileNotification* FindProfileNotification(const std::string& id) const; |
| 171 | 193 |
| 172 DISALLOW_COPY_AND_ASSIGN(MessageCenterNotificationManager); | 194 DISALLOW_COPY_AND_ASSIGN(MessageCenterNotificationManager); |
| 173 }; | 195 }; |
| 174 | 196 |
| 175 #endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ | 197 #endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ |
| OLD | NEW |