[Download Notification] Show preview if downloaded file is image
[chromium-blink-merge.git] / chrome / browser / download / notification / download_notification_item.h
blob51d710f3ad03f2c6ed7733bf7584d55d6ff73211
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_
6 #define CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_
8 #include "base/strings/string_number_conversions.h"
9 #include "chrome/browser/download/download_commands.h"
10 #include "chrome/browser/download/notification/download_notification.h"
11 #include "chrome/browser/image_decoder.h"
12 #include "chrome/browser/notifications/notification.h"
13 #include "chrome/browser/notifications/notification_delegate.h"
14 #include "chrome/browser/notifications/notification_test_util.h"
15 #include "content/public/browser/download_item.h"
16 #include "grit/theme_resources.h"
17 #include "third_party/skia/include/core/SkBitmap.h"
18 #include "ui/message_center/message_center.h"
19 #include "ui/message_center/message_center_observer.h"
21 namespace test {
22 class DownloadNotificationItemTest;
25 class DownloadNotificationItem : public DownloadNotification,
26 public ImageDecoder::ImageRequest {
27 public:
28 DownloadNotificationItem(content::DownloadItem* item,
29 DownloadNotificationManagerForProfile* manager);
31 ~DownloadNotificationItem() override;
33 // Methods called from NotificationWatcher.
34 void OnDownloadUpdated(content::DownloadItem* item) override;
35 void OnDownloadRemoved(content::DownloadItem* item) override;
36 void OnNotificationClose() override;
37 void OnNotificationClick() override;
38 void OnNotificationButtonClick(int button_index) override;
39 std::string GetNotificationId() const override;
41 private:
42 friend class test::DownloadNotificationItemTest;
44 enum ImageDecodeStatus { NOT_STARTED, IN_PROGRESS, DONE, FAILED, NOT_IMAGE };
46 enum NotificationUpdateType {
47 ADD,
48 UPDATE,
49 UPDATE_AND_POPUP
52 void CloseNotificationByUser();
53 void CloseNotificationByNonUser();
54 void Update();
55 void UpdateNotificationData(NotificationUpdateType type);
57 // Set icon of the notification.
58 void SetNotificationIcon(int resource_id);
60 // Set preview image of the notification. Must be called on IO thread.
61 void OnImageLoaded(const std::string& image_data);
63 // ImageDecoder::ImageRequest overrides:
64 void OnImageDecoded(const SkBitmap& decoded_image) override;
65 void OnDecodeImageFailed() override;
67 // Returns a short one-line status string for the download.
68 base::string16 GetTitle() const;
70 // Returns a short one-line status string for a download command.
71 base::string16 GetCommandLabel(DownloadCommands::Command command) const;
73 // Get the warning test to notify a dangerous download. Should only be called
74 // if IsDangerous() is true.
75 base::string16 GetWarningText() const;
77 Browser* GetBrowser() const;
78 Profile* profile() const;
80 // Returns the list of possible extra (all except the default) actions.
81 scoped_ptr<std::vector<DownloadCommands::Command>> GetExtraActions() const;
83 // Flag to show the notification on next update. If true, the notification
84 // goes visible. The initial value is true so it gets shown on initial update.
85 bool show_next_ = true;
86 // Current vilibility status of the notification.
87 bool visible_ = false;
89 int image_resource_id_ = 0;
90 content::DownloadItem::DownloadState previous_download_state_ =
91 content::DownloadItem::MAX_DOWNLOAD_STATE; // As uninitialized state
92 scoped_ptr<Notification> notification_;
93 content::DownloadItem* item_;
94 scoped_ptr<std::vector<DownloadCommands::Command>> button_actions_;
96 // Status of the preview image decode.
97 ImageDecodeStatus image_decode_status_ = NOT_STARTED;
99 base::WeakPtrFactory<DownloadNotificationItem> weak_factory_;
101 DISALLOW_COPY_AND_ASSIGN(DownloadNotificationItem);
104 #endif // CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_