blob: 252be03d391b00c8ee9881e2563d28be87b9c019 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_STATUS_UPDATER_H_
#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_STATUS_UPDATER_H_
#include <set>
#include "base/basictypes.h"
#include "content/public/browser/download_item.h"
#include "content/public/browser/download_manager.h"
// Keeps track of download progress for the entire browser.
class DownloadStatusUpdater
: public content::DownloadManager::Observer,
public content::DownloadItem::Observer {
public:
DownloadStatusUpdater();
virtual ~DownloadStatusUpdater();
// Fills in |*download_count| with the number of currently active downloads.
// If we know the final size of all downloads, this routine returns true
// with |*progress| set to the percentage complete of all in-progress
// downloads. Otherwise, it returns false.
bool GetProgress(float* progress, int* download_count) const;
// Add the specified DownloadManager to the list of managers for which
// this object reports status.
// The manager must not have previously been added to this updater.
// The updater will automatically disassociate itself from the
// manager when the manager is shutdown.
void AddManager(content::DownloadManager* manager);
// Methods inherited from content::DownloadManager::Observer.
virtual void ModelChanged(content::DownloadManager* manager) OVERRIDE;
virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE;
// Methods inherited from content::DownloadItem::Observer.
virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE;
virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE;
virtual void OnDownloadDestroyed(content::DownloadItem* download) OVERRIDE;
protected:
// Update the app icon. Virtual to be overridable for testing.
virtual void UpdateAppIconDownloadProgress();
private:
// Update the internal state tracking an item.
void UpdateItem(content::DownloadItem* download);
std::set<content::DownloadManager*> managers_;
std::set<content::DownloadItem*> items_;
DISALLOW_COPY_AND_ASSIGN(DownloadStatusUpdater);
};
#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_STATUS_UPDATER_H_
|