[email protected] | 75e51b5 | 2012-02-04 16:57:54 | [diff] [blame] | 1 | // Copyright (c) 2012 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_DOWNLOAD_STATUS_UPDATER_H_ | ||||
6 | #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_STATUS_UPDATER_H_ | ||||
7 | |||||
avi | aa346b0d | 2016-10-28 14:52:51 | [diff] [blame] | 8 | #include <memory> |
Findit | 62fdfbd2 | 2019-03-22 09:10:55 | [diff] [blame] | 9 | #include <set> |
[email protected] | 75e51b5 | 2012-02-04 16:57:54 | [diff] [blame] | 10 | |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 11 | #include "base/macros.h" |
Xing Liu | 5c41b0a | 2017-07-14 19:16:46 | [diff] [blame] | 12 | #include "components/download/content/public/all_download_item_notifier.h" |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 13 | #include "components/download/public/common/download_item.h" |
[email protected] | 75e51b5 | 2012-02-04 16:57:54 | [diff] [blame] | 14 | #include "content/public/browser/download_manager.h" |
15 | |||||
16 | // Keeps track of download progress for the entire browser. | ||||
17 | class DownloadStatusUpdater | ||||
Xing Liu | 5c41b0a | 2017-07-14 19:16:46 | [diff] [blame] | 18 | : public download::AllDownloadItemNotifier::Observer { |
[email protected] | 75e51b5 | 2012-02-04 16:57:54 | [diff] [blame] | 19 | public: |
20 | DownloadStatusUpdater(); | ||||
dcheng | 0c8ba27e | 2014-10-21 12:00:53 | [diff] [blame] | 21 | ~DownloadStatusUpdater() override; |
[email protected] | 75e51b5 | 2012-02-04 16:57:54 | [diff] [blame] | 22 | |
23 | // Fills in |*download_count| with the number of currently active downloads. | ||||
24 | // If we know the final size of all downloads, this routine returns true | ||||
25 | // with |*progress| set to the percentage complete of all in-progress | ||||
26 | // downloads. Otherwise, it returns false. | ||||
27 | bool GetProgress(float* progress, int* download_count) const; | ||||
28 | |||||
29 | // Add the specified DownloadManager to the list of managers for which | ||||
30 | // this object reports status. | ||||
31 | // The manager must not have previously been added to this updater. | ||||
32 | // The updater will automatically disassociate itself from the | ||||
33 | // manager when the manager is shutdown. | ||||
Shakti Sahu | 4af06b8d | 2019-03-27 22:17:02 | [diff] [blame] | 34 | void AddManager(content::DownloadManager* manager); |
[email protected] | 75e51b5 | 2012-02-04 16:57:54 | [diff] [blame] | 35 | |
[email protected] | 3d70c63 | 2012-09-25 01:09:58 | [diff] [blame] | 36 | // AllDownloadItemNotifier::Observer |
dcheng | 0c8ba27e | 2014-10-21 12:00:53 | [diff] [blame] | 37 | void OnDownloadCreated(content::DownloadManager* manager, |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 38 | download::DownloadItem* item) override; |
dcheng | 0c8ba27e | 2014-10-21 12:00:53 | [diff] [blame] | 39 | void OnDownloadUpdated(content::DownloadManager* manager, |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 40 | download::DownloadItem* item) override; |
[email protected] | 75e51b5 | 2012-02-04 16:57:54 | [diff] [blame] | 41 | |
[email protected] | 1310b7f | 2012-02-09 01:45:39 | [diff] [blame] | 42 | protected: |
[email protected] | 27ee16f | 2012-08-12 02:25:13 | [diff] [blame] | 43 | // Platform-specific function to update the platform UI for download progress. |
44 | // |download| is the download item that changed. Implementations should not | ||||
45 | // hold the value of |download| as it is not guaranteed to remain valid. | ||||
46 | // Virtual to be overridable for testing. | ||||
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 47 | virtual void UpdateAppIconDownloadProgress(download::DownloadItem* download); |
[email protected] | 1310b7f | 2012-02-09 01:45:39 | [diff] [blame] | 48 | |
[email protected] | 75e51b5 | 2012-02-04 16:57:54 | [diff] [blame] | 49 | private: |
Shakti Sahu | 4af06b8d | 2019-03-27 22:17:02 | [diff] [blame] | 50 | std::vector<std::unique_ptr<download::AllDownloadItemNotifier>> notifiers_; |
[email protected] | 75e51b5 | 2012-02-04 16:57:54 | [diff] [blame] | 51 | |
52 | DISALLOW_COPY_AND_ASSIGN(DownloadStatusUpdater); | ||||
53 | }; | ||||
54 | |||||
55 | #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_STATUS_UPDATER_H_ |