Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: chrome/browser/download/notification/download_notification_item.h

Issue 1159363002: [Download Notification] Show preview if downloaded file is image (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Read file content in the browser process Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/download/notification/download_notification_item.h" 8 #include "chrome/browser/download/notification/download_notification_item.h"
9 9
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "chrome/browser/download/download_commands.h" 11 #include "chrome/browser/download/download_commands.h"
12 #include "chrome/browser/image_decoder.h"
12 #include "chrome/browser/notifications/notification.h" 13 #include "chrome/browser/notifications/notification.h"
13 #include "chrome/browser/notifications/notification_delegate.h" 14 #include "chrome/browser/notifications/notification_delegate.h"
14 #include "chrome/browser/notifications/notification_test_util.h" 15 #include "chrome/browser/notifications/notification_test_util.h"
15 #include "content/public/browser/download_item.h" 16 #include "content/public/browser/download_item.h"
16 #include "grit/theme_resources.h" 17 #include "grit/theme_resources.h"
18 #include "third_party/skia/include/core/SkBitmap.h"
17 #include "ui/message_center/message_center.h" 19 #include "ui/message_center/message_center.h"
18 #include "ui/message_center/message_center_observer.h" 20 #include "ui/message_center/message_center_observer.h"
19 21
20 namespace test { 22 namespace test {
21 class DownloadNotificationItemTest; 23 class DownloadNotificationItemTest;
22 } 24 }
23 25
24 class DownloadNotificationItem : public content::DownloadItem::Observer { 26 class DownloadNotificationItem : public content::DownloadItem::Observer,
27 public ImageDecoder::ImageRequest {
25 public: 28 public:
26 class Delegate { 29 class Delegate {
27 public: 30 public:
28 virtual void OnCreated(DownloadNotificationItem* item) = 0; 31 virtual void OnCreated(DownloadNotificationItem* item) = 0;
29 virtual void OnDownloadStarted(DownloadNotificationItem* item) = 0; 32 virtual void OnDownloadStarted(DownloadNotificationItem* item) = 0;
30 virtual void OnDownloadStopped(DownloadNotificationItem* item) = 0; 33 virtual void OnDownloadStopped(DownloadNotificationItem* item) = 0;
31 virtual void OnDownloadRemoved(DownloadNotificationItem* item) = 0; 34 virtual void OnDownloadRemoved(DownloadNotificationItem* item) = 0;
32 }; 35 };
33 36
34 static const char kDownloadNotificationOrigin[]; 37 static const char kDownloadNotificationOrigin[];
35 38
36 DownloadNotificationItem(content::DownloadItem* item, 39 DownloadNotificationItem(content::DownloadItem* item,
37 Profile* profile, 40 Profile* profile,
38 Delegate* delegate); 41 Delegate* delegate);
39 42
40 ~DownloadNotificationItem() override; 43 ~DownloadNotificationItem() override;
41 44
42 private: 45 private:
43 friend class test::DownloadNotificationItemTest; 46 friend class test::DownloadNotificationItemTest;
44 47
45 enum NotificationUpdateType { 48 enum NotificationUpdateType {
46 ADD_NEW, 49 ADD_NEW,
47 UPDATE_EXISTING 50 UPDATE_EXISTING
48 }; 51 };
49 52
53 enum ImageDecodeStatus {
54 NOT_STARTED,
55 IN_PROGRESS,
56 DONE,
57 FAILED,
58 NOT_IMAGE
59 };
60
50 class NotificationWatcher : public NotificationDelegate { 61 class NotificationWatcher : public NotificationDelegate {
51 public: 62 public:
52 explicit NotificationWatcher(DownloadNotificationItem* item); 63 explicit NotificationWatcher(DownloadNotificationItem* item);
53 64
54 // NotificationDelegate overrides: 65 // NotificationDelegate overrides:
55 void Close(bool by_user) override; 66 void Close(bool by_user) override;
56 void Click() override; 67 void Click() override;
57 bool HasClickedListener() override; 68 bool HasClickedListener() override;
58 void ButtonClick(int button_index) override; 69 void ButtonClick(int button_index) override;
59 std::string id() const override; 70 std::string id() const override;
60 71
61 private: 72 private:
62 ~NotificationWatcher() override; 73 ~NotificationWatcher() override;
63 74
64 DownloadNotificationItem* item_; 75 DownloadNotificationItem* item_;
65 }; 76 };
66 77
67 // For testing. This is set by SetStubNotificationUIManagerForTesting method. 78 // For testing. This is set by SetStubNotificationUIManagerForTesting method.
68 static StubNotificationUIManager* stub_notification_ui_manager_for_testing_; 79 static StubNotificationUIManager* stub_notification_ui_manager_for_testing_;
69 80
70 // Replaces the NotificationUIManager for tests. 81 // Replaces the NotificationUIManager for tests.
71 static void SetStubNotificationUIManagerForTesting( 82 static void SetStubNotificationUIManagerForTesting(
72 StubNotificationUIManager* stub_notification_ui_manager) { 83 StubNotificationUIManager* stub_notification_ui_manager) {
73 stub_notification_ui_manager_for_testing_ = stub_notification_ui_manager; 84 stub_notification_ui_manager_for_testing_ = stub_notification_ui_manager;
74 } 85 }
75 86
76 // Methods called from NotificationWatcher. 87 // Methods called from NotificationWatcher.
77 void OnNotificationClick(); 88 void OnNotificationClick();
78 void OnNotificationButtonClick(int button_index); 89 void OnNotificationButtonClick(int button_index);
90 void OnNotificationClose(bool by_user);
79 91
80 // DownloadItem::Observer overrides: 92 // DownloadItem::Observer overrides:
81 void OnDownloadUpdated(content::DownloadItem* item) override; 93 void OnDownloadUpdated(content::DownloadItem* item) override;
82 void OnDownloadOpened(content::DownloadItem* item) override; 94 void OnDownloadOpened(content::DownloadItem* item) override;
83 void OnDownloadRemoved(content::DownloadItem* item) override; 95 void OnDownloadRemoved(content::DownloadItem* item) override;
84 void OnDownloadDestroyed(content::DownloadItem* item) override; 96 void OnDownloadDestroyed(content::DownloadItem* item) override;
85 97
86 void CloseNotificationByUser(); 98 void CloseNotificationByUser();
87 void CloseNotificationByNonUser(); 99 void CloseNotificationByNonUser();
88 void UpdateNotificationData(NotificationUpdateType type); 100 void UpdateNotificationData(NotificationUpdateType type);
89 void SetNotificationImage(int resource_id); 101
102 // Set icon of the notification.
103 void SetNotificationIcon(int resource_id);
104
105 // Set preview image of the notification. Must be called on IO thread.
106 void OnImageLoaded(std::string image_data);
Lei Zhang 2015/06/12 07:26:37 pass by const ref.
yoshiki 2015/06/12 08:00:20 Done.
107
108 // ImageDecoder::ImageRequest overrides:
109 void OnImageDecoded(const SkBitmap& decoded_image) override;
110 void OnDecodeImageFailed() override;
90 111
91 NotificationUIManager* notification_ui_manager() const; 112 NotificationUIManager* notification_ui_manager() const;
92 113
93 // Returns a short one-line status string for the download. 114 // Returns a short one-line status string for the download.
94 base::string16 GetTitle() const; 115 base::string16 GetTitle() const;
95 116
96 // Returns a short one-line status string for a download command. 117 // Returns a short one-line status string for a download command.
97 base::string16 GetCommandLabel(DownloadCommands::Command command) const; 118 base::string16 GetCommandLabel(DownloadCommands::Command command) const;
98 119
99 // Get the warning test to notify a dangerous download. Should only be called 120 // Get the warning test to notify a dangerous download. Should only be called
100 // if IsDangerous() is true. 121 // if IsDangerous() is true.
101 base::string16 GetWarningText() const; 122 base::string16 GetWarningText() const;
102 123
103 Browser* GetBrowser(); 124 Browser* GetBrowser();
104 125
105 // Returns the list of possible extra (all except the default) actions. 126 // Returns the list of possible extra (all except the default) actions.
106 scoped_ptr<std::vector<DownloadCommands::Command>> GetExtraActions() const; 127 scoped_ptr<std::vector<DownloadCommands::Command>> GetExtraActions() const;
107 128
108 int image_resource_id_ = 0; 129 int image_resource_id_ = 0;
109 content::DownloadItem::DownloadState previous_download_state_ = 130 content::DownloadItem::DownloadState previous_download_state_ =
110 content::DownloadItem::MAX_DOWNLOAD_STATE; // As uninitialized state 131 content::DownloadItem::MAX_DOWNLOAD_STATE; // As uninitialized state
111 Profile* profile_; 132 Profile* profile_;
112 scoped_refptr<NotificationWatcher> watcher_; 133 scoped_refptr<NotificationWatcher> watcher_;
113 scoped_ptr<Notification> notification_; 134 scoped_ptr<Notification> notification_;
114 content::DownloadItem* item_; 135 content::DownloadItem* item_;
115 scoped_ptr<std::vector<DownloadCommands::Command>> button_actions_; 136 scoped_ptr<std::vector<DownloadCommands::Command>> button_actions_;
116 Delegate* const delegate_; 137 Delegate* const delegate_;
117 138
139 // Status of the preview image decode.
140 ImageDecodeStatus image_decode_status_ = NOT_STARTED;
141
142 base::WeakPtrFactory<DownloadNotificationItem> weak_factory_;
143
118 DISALLOW_COPY_AND_ASSIGN(DownloadNotificationItem); 144 DISALLOW_COPY_AND_ASSIGN(DownloadNotificationItem);
119 }; 145 };
120 146
121 #endif // CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_ 147 #endif // CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698