Add ICU message format support
[chromium-blink-merge.git] / chrome / browser / download / notification / download_item_notification.h
blob02f6f4d31fd6cb19e15b4ebedad535d8e23c73bb
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_ITEM_NOTIFICATION_H_
6 #define CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_ITEM_NOTIFICATION_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 DownloadItemNotificationTest;
25 class DownloadItemNotification : public DownloadNotification,
26 public ImageDecoder::ImageRequest {
27 public:
28 DownloadItemNotification(content::DownloadItem* item,
29 DownloadNotificationManagerForProfile* manager);
31 ~DownloadItemNotification() 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::DownloadItemNotificationTest;
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 bool IsNotificationVisible() const;
79 Browser* GetBrowser() const;
80 Profile* profile() const;
82 // Returns the list of possible extra (all except the default) actions.
83 scoped_ptr<std::vector<DownloadCommands::Command>> GetExtraActions() const;
85 // Flag to show the notification on next update. If true, the notification
86 // goes visible. The initial value is true so it gets shown on initial update.
87 bool show_next_ = true;
88 // Current vilibility status of the notification.
89 bool visible_ = false;
91 int image_resource_id_ = 0;
92 content::DownloadItem::DownloadState previous_download_state_ =
93 content::DownloadItem::MAX_DOWNLOAD_STATE; // As uninitialized state
94 bool previous_dangerous_state_ = false;
95 scoped_ptr<Notification> notification_;
96 content::DownloadItem* item_;
97 scoped_ptr<std::vector<DownloadCommands::Command>> button_actions_;
99 // Status of the preview image decode.
100 ImageDecodeStatus image_decode_status_ = NOT_STARTED;
102 base::WeakPtrFactory<DownloadItemNotification> weak_factory_;
104 DISALLOW_COPY_AND_ASSIGN(DownloadItemNotification);
107 #endif // CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_ITEM_NOTIFICATION_H_