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

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

Issue 852043002: Initial Implementation of Download Notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 9 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
(Empty)
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.
4
5 #ifndef CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_
6 #define CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_
7
8 #include "chrome/browser/download/notification/download_notification_item.h"
9
10 #include "base/strings/string_number_conversions.h"
11 #include "chrome/browser/download/download_commands.h"
12 #include "content/public/browser/download_item.h"
13 #include "grit/theme_resources.h"
14 #include "ui/message_center/message_center.h"
15 #include "ui/message_center/message_center_observer.h"
16 #include "ui/message_center/notification.h"
17 #include "ui/message_center/notification_delegate.h"
18
19 using message_center::Notification;
20
21 namespace test {
22 class DownloadNotificationItemTest;
23 }
24
25 class DownloadNotificationItem
26 : public base::RefCountedThreadSafe<DownloadNotificationItem>,
asanka 2015/02/27 01:26:49 Why does this need to be refcounted?
yoshiki 2015/02/28 10:50:54 No strong reasons. I changed back it into non-refc
27 public content::DownloadItem::Observer {
28 public:
29 class Delegate {
30 public:
31 virtual void OnDownloadStarted(DownloadNotificationItem* item) = 0;
32 virtual void OnDownloadStopped(DownloadNotificationItem* item) = 0;
33 virtual void OnDownloadRemoved(DownloadNotificationItem* item) = 0;
34 };
35
36 DownloadNotificationItem(content::DownloadItem* item,
37 Profile* profile,
38 Delegate* delegate);
39
40 protected:
41 ~DownloadNotificationItem() override;
42
43 private:
44 class NotificationWatcher : public message_center::NotificationDelegate,
45 public message_center::MessageCenterObserver {
46 public:
47 explicit NotificationWatcher(DownloadNotificationItem* item);
48
49 private:
50 ~NotificationWatcher() override;
51
52 // message_center::NotificationDelegate overrides:
53 void Close(bool by_user) override;
54 void Click() override;
55 bool HasClickedListener() override;
56 void ButtonClick(int button_index) override;
57
58 // message_center::MessageCenterObserver overrides:
59 void OnNotificationRemoved(const std::string& id, bool by_user) override;
60
61 DownloadNotificationItem* item_;
62 };
63
64 void OnNotificationClick();
65 void OnNotificationButtonClick(int button_index);
66 void OnNotificationClose(bool by_user);
67 void OnNotificationRemoved(bool by_user);
68
69 // DownloadItem::Observer overrides:
70 void OnDownloadUpdated(content::DownloadItem* item) override;
71 void OnDownloadOpened(content::DownloadItem* item) override;
72 void OnDownloadRemoved(content::DownloadItem* item) override;
73 void OnDownloadDestroyed(content::DownloadItem* item) override;
74
75 void UpdateNotificationData();
76 void SetNotificationImage(int resource_id);
77
78 // Returns a short one-line status string for the download.
79 base::string16 GetTitle() const;
80
81 // Returns a short one-line status string for a download command.
82 base::string16 GetCommandLabel(DownloadCommands::Command command) const;
83
84 // Get the warning test to notify a dangerous download. Should only be called
85 // if IsDangerous() is true.
86 base::string16 GetWarningText() const;
87
88 scoped_ptr<std::vector<DownloadCommands::Command>> GetPossibleActions() const;
89
90 scoped_ptr<Notification> notification_;
91 scoped_ptr<std::vector<DownloadCommands::Command>> button_actions_;
92
93 bool openable_;
94 bool downloading_;
95 bool reshow_after_remove_;
96 int image_resource_id_;
97 message_center::MessageCenter* message_center_;
98 content::DownloadItem* item_;
99 Profile* profile_;
asanka 2015/02/27 01:26:49 Profile is implied.
yoshiki 2015/02/28 10:50:54 Done.
100 scoped_refptr<NotificationWatcher> watcher_;
101
102 Delegate* const delegate_;
103
104 friend class base::RefCountedThreadSafe<DownloadNotificationItem>;
105 friend class test::DownloadNotificationItemTest;
106
107 DISALLOW_COPY_AND_ASSIGN(DownloadNotificationItem);
108 };
109
110 #endif // CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698