| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_ |
| 6 #define CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_ |
| 7 | 7 |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "chrome/browser/download/download_commands.h" | 9 #include "chrome/browser/download/download_commands.h" |
| 10 #include "chrome/browser/download/notification/download_notification.h" | 10 #include "chrome/browser/download/notification/download_notification.h" |
| 11 #include "chrome/browser/image_decoder.h" |
| 11 #include "chrome/browser/notifications/notification.h" | 12 #include "chrome/browser/notifications/notification.h" |
| 12 #include "chrome/browser/notifications/notification_delegate.h" | 13 #include "chrome/browser/notifications/notification_delegate.h" |
| 13 #include "chrome/browser/notifications/notification_test_util.h" | 14 #include "chrome/browser/notifications/notification_test_util.h" |
| 14 #include "content/public/browser/download_item.h" | 15 #include "content/public/browser/download_item.h" |
| 15 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 17 #include "third_party/skia/include/core/SkBitmap.h" |
| 16 #include "ui/message_center/message_center.h" | 18 #include "ui/message_center/message_center.h" |
| 17 #include "ui/message_center/message_center_observer.h" | 19 #include "ui/message_center/message_center_observer.h" |
| 18 | 20 |
| 19 namespace test { | 21 namespace test { |
| 20 class DownloadNotificationItemTest; | 22 class DownloadNotificationItemTest; |
| 21 } | 23 } |
| 22 | 24 |
| 23 class DownloadNotificationItem : public DownloadNotification { | 25 class DownloadNotificationItem : public DownloadNotification, |
| 26 public ImageDecoder::ImageRequest { |
| 24 public: | 27 public: |
| 25 DownloadNotificationItem(content::DownloadItem* item, | 28 DownloadNotificationItem(content::DownloadItem* item, |
| 26 DownloadNotificationManagerForProfile* manager); | 29 DownloadNotificationManagerForProfile* manager); |
| 27 | 30 |
| 28 ~DownloadNotificationItem() override; | 31 ~DownloadNotificationItem() override; |
| 29 | 32 |
| 30 // Methods called from NotificationWatcher. | 33 // Methods called from NotificationWatcher. |
| 31 void OnDownloadUpdated(content::DownloadItem* item) override; | 34 void OnDownloadUpdated(content::DownloadItem* item) override; |
| 32 void OnDownloadRemoved(content::DownloadItem* item) override; | 35 void OnDownloadRemoved(content::DownloadItem* item) override; |
| 33 void OnNotificationClose() override; | 36 void OnNotificationClose() override; |
| 34 void OnNotificationClick() override; | 37 void OnNotificationClick() override; |
| 35 void OnNotificationButtonClick(int button_index) override; | 38 void OnNotificationButtonClick(int button_index) override; |
| 36 std::string GetNotificationId() const override; | 39 std::string GetNotificationId() const override; |
| 37 | 40 |
| 38 private: | 41 private: |
| 39 friend class test::DownloadNotificationItemTest; | 42 friend class test::DownloadNotificationItemTest; |
| 40 | 43 |
| 44 enum ImageDecodeStatus { NOT_STARTED, IN_PROGRESS, DONE, FAILED, NOT_IMAGE }; |
| 45 |
| 41 enum NotificationUpdateType { | 46 enum NotificationUpdateType { |
| 42 ADD, | 47 ADD, |
| 43 UPDATE, | 48 UPDATE, |
| 44 UPDATE_AND_POPUP | 49 UPDATE_AND_POPUP |
| 45 }; | 50 }; |
| 46 | 51 |
| 47 void CloseNotificationByUser(); | 52 void CloseNotificationByUser(); |
| 48 void CloseNotificationByNonUser(); | 53 void CloseNotificationByNonUser(); |
| 49 void Update(); | 54 void Update(); |
| 50 void UpdateNotificationData(NotificationUpdateType type); | 55 void UpdateNotificationData(NotificationUpdateType type); |
| 51 void SetNotificationImage(int resource_id); | 56 |
| 57 // Set icon of the notification. |
| 58 void SetNotificationIcon(int resource_id); |
| 59 |
| 60 // Set preview image of the notification. Must be called on IO thread. |
| 61 void OnImageLoaded(const std::string& image_data); |
| 62 |
| 63 // ImageDecoder::ImageRequest overrides: |
| 64 void OnImageDecoded(const SkBitmap& decoded_image) override; |
| 65 void OnDecodeImageFailed() override; |
| 52 | 66 |
| 53 // Returns a short one-line status string for the download. | 67 // Returns a short one-line status string for the download. |
| 54 base::string16 GetTitle() const; | 68 base::string16 GetTitle() const; |
| 55 | 69 |
| 56 // Returns a short one-line status string for a download command. | 70 // Returns a short one-line status string for a download command. |
| 57 base::string16 GetCommandLabel(DownloadCommands::Command command) const; | 71 base::string16 GetCommandLabel(DownloadCommands::Command command) const; |
| 58 | 72 |
| 59 // Get the warning test to notify a dangerous download. Should only be called | 73 // Get the warning test to notify a dangerous download. Should only be called |
| 60 // if IsDangerous() is true. | 74 // if IsDangerous() is true. |
| 61 base::string16 GetWarningText() const; | 75 base::string16 GetWarningText() const; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 72 // Current vilibility status of the notification. | 86 // Current vilibility status of the notification. |
| 73 bool visible_ = false; | 87 bool visible_ = false; |
| 74 | 88 |
| 75 int image_resource_id_ = 0; | 89 int image_resource_id_ = 0; |
| 76 content::DownloadItem::DownloadState previous_download_state_ = | 90 content::DownloadItem::DownloadState previous_download_state_ = |
| 77 content::DownloadItem::MAX_DOWNLOAD_STATE; // As uninitialized state | 91 content::DownloadItem::MAX_DOWNLOAD_STATE; // As uninitialized state |
| 78 scoped_ptr<Notification> notification_; | 92 scoped_ptr<Notification> notification_; |
| 79 content::DownloadItem* item_; | 93 content::DownloadItem* item_; |
| 80 scoped_ptr<std::vector<DownloadCommands::Command>> button_actions_; | 94 scoped_ptr<std::vector<DownloadCommands::Command>> button_actions_; |
| 81 | 95 |
| 96 // Status of the preview image decode. |
| 97 ImageDecodeStatus image_decode_status_ = NOT_STARTED; |
| 98 |
| 99 base::WeakPtrFactory<DownloadNotificationItem> weak_factory_; |
| 100 |
| 82 DISALLOW_COPY_AND_ASSIGN(DownloadNotificationItem); | 101 DISALLOW_COPY_AND_ASSIGN(DownloadNotificationItem); |
| 83 }; | 102 }; |
| 84 | 103 |
| 85 #endif // CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_ | 104 #endif // CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_ |
| OLD | NEW |