blob: 05016b14636fcd2ffa1e6317f2e56efafc0252d7 [file] [log] [blame]
[email protected]75e51b52012-02-04 16:57:541// 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
aviaa346b0d2016-10-28 14:52:518#include <memory>
Findit62fdfbd22019-03-22 09:10:559#include <set>
[email protected]75e51b52012-02-04 16:57:5410
avie4d7b6f2015-12-26 00:59:1811#include "base/macros.h"
Xing Liu5c41b0a2017-07-14 19:16:4612#include "components/download/content/public/all_download_item_notifier.h"
Min Qina9f487872018-02-09 20:43:2313#include "components/download/public/common/download_item.h"
[email protected]75e51b52012-02-04 16:57:5414#include "content/public/browser/download_manager.h"
15
16// Keeps track of download progress for the entire browser.
17class DownloadStatusUpdater
Xing Liu5c41b0a2017-07-14 19:16:4618 : public download::AllDownloadItemNotifier::Observer {
[email protected]75e51b52012-02-04 16:57:5419 public:
20 DownloadStatusUpdater();
dcheng0c8ba27e2014-10-21 12:00:5321 ~DownloadStatusUpdater() override;
[email protected]75e51b52012-02-04 16:57:5422
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 Sahu4af06b8d2019-03-27 22:17:0234 void AddManager(content::DownloadManager* manager);
[email protected]75e51b52012-02-04 16:57:5435
[email protected]3d70c632012-09-25 01:09:5836 // AllDownloadItemNotifier::Observer
dcheng0c8ba27e2014-10-21 12:00:5337 void OnDownloadCreated(content::DownloadManager* manager,
Min Qina9f487872018-02-09 20:43:2338 download::DownloadItem* item) override;
dcheng0c8ba27e2014-10-21 12:00:5339 void OnDownloadUpdated(content::DownloadManager* manager,
Min Qina9f487872018-02-09 20:43:2340 download::DownloadItem* item) override;
[email protected]75e51b52012-02-04 16:57:5441
[email protected]1310b7f2012-02-09 01:45:3942 protected:
[email protected]27ee16f2012-08-12 02:25:1343 // 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 Qina9f487872018-02-09 20:43:2347 virtual void UpdateAppIconDownloadProgress(download::DownloadItem* download);
[email protected]1310b7f2012-02-09 01:45:3948
[email protected]75e51b52012-02-04 16:57:5449 private:
Shakti Sahu4af06b8d2019-03-27 22:17:0250 std::vector<std::unique_ptr<download::AllDownloadItemNotifier>> notifiers_;
[email protected]75e51b52012-02-04 16:57:5451
52 DISALLOW_COPY_AND_ASSIGN(DownloadStatusUpdater);
53};
54
55#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_STATUS_UPDATER_H_