summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-01 16:30:47 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-01 16:30:47 +0000
commit6a7fb04b7475b355cb571c9aca6b192d2a96ca5f (patch)
tree189b6f31c49e34874d3308cbffb9beb6becd8b26 /chrome/browser/download
parentc702d70890ab023ce723dde7aea8c66adb7ef98e (diff)
downloadchromium_src-6a7fb04b7475b355cb571c9aca6b192d2a96ca5f.zip
chromium_src-6a7fb04b7475b355cb571c9aca6b192d2a96ca5f.tar.gz
chromium_src-6a7fb04b7475b355cb571c9aca6b192d2a96ca5f.tar.bz2
Add temporary download progress overlay to the dock icon for the Mac (real UI coming soon), and provide the hooks for the Win7 implementation.
BUG=http://crbug.com/8039 TEST=download; see progress in the dock icon Review URL: http://codereview.chromium.org/545157 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37698 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download')
-rw-r--r--chrome/browser/download/download_manager.cc38
-rw-r--r--chrome/browser/download/download_manager.h3
-rw-r--r--chrome/browser/download/download_util.cc8
-rw-r--r--chrome/browser/download/download_util.h9
4 files changed, 58 insertions, 0 deletions
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc
index c327944..252b43c 100644
--- a/chrome/browser/download/download_manager.cc
+++ b/chrome/browser/download/download_manager.cc
@@ -789,6 +789,8 @@ void DownloadManager::ContinueStartDownload(DownloadCreateInfo* info,
NewCallback(this, &DownloadManager::OnCreateDownloadEntryComplete));
}
}
+
+ UpdateAppIcon();
}
// Convenience function for updating the history service for a download.
@@ -833,6 +835,7 @@ void DownloadManager::UpdateDownload(int32 download_id, int64 size) {
download->Update(size);
UpdateHistoryForDownload(download);
}
+ UpdateAppIcon();
}
void DownloadManager::DownloadFinished(int32 download_id, int64 size) {
@@ -865,6 +868,8 @@ void DownloadManager::DownloadFinished(int32 download_id, int64 size) {
UpdateHistoryForDownload(download);
}
+ UpdateAppIcon();
+
// If this a dangerous download not yet validated by the user, don't do
// anything. When the user notifies us, it will trigger a call to
// ProceedWithFinishedDangerousDownload.
@@ -1018,6 +1023,7 @@ void DownloadManager::DownloadCancelled(int32 download_id) {
DownloadCancelledInternal(download_id,
download->render_process_id(),
download->request_id());
+ UpdateAppIcon();
}
void DownloadManager::DownloadCancelledInternal(int download_id,
@@ -1071,6 +1077,36 @@ bool DownloadManager::IsDangerous(const FilePath& file_name) {
return IsExecutableFile(file_name);
}
+void DownloadManager::UpdateAppIcon() {
+ int64 total_bytes = 0;
+ int64 received_bytes = 0;
+ int download_count = 0;
+ bool progress_known = true;
+
+ for (DownloadMap::iterator i = in_progress_.begin();
+ i != in_progress_.end();
+ ++i) {
+ ++download_count;
+ const DownloadItem* item = i->second;
+ if (item->total_bytes() > 0) {
+ total_bytes += item->total_bytes();
+ received_bytes += item->received_bytes();
+ } else {
+ // This download didn't specify a Content-Length, so the combined progress
+ // bar neeeds to be indeterminate.
+ progress_known = false;
+ }
+ }
+
+ float progress = 0;
+ if (progress_known && download_count)
+ progress = (float)received_bytes / total_bytes;
+
+ download_util::UpdateAppIconDownloadProgress(download_count,
+ progress_known,
+ progress);
+}
+
void DownloadManager::RenameDownload(DownloadItem* download,
const FilePath& new_path) {
download->Rename(new_path);
@@ -1640,6 +1676,8 @@ void DownloadManager::OnCreateDownloadEntryComplete(DownloadCreateInfo info,
UpdateHistoryForDownload(download);
download->UpdateObservers();
}
+
+ UpdateAppIcon();
}
// Called when the history service has retrieved the list of downloads that
diff --git a/chrome/browser/download/download_manager.h b/chrome/browser/download/download_manager.h
index b562bc2..4d7a709 100644
--- a/chrome/browser/download/download_manager.h
+++ b/chrome/browser/download/download_manager.h
@@ -600,6 +600,9 @@ class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>,
// Checks whether a file represents a risk if downloaded.
bool IsDangerous(const FilePath& file_name);
+ // Updates the app icon about the overall download progress.
+ void UpdateAppIcon();
+
// Changes the paths and file name of the specified |download|, propagating
// the change to the history system.
void RenameDownload(DownloadItem* download, const FilePath& new_path);
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc
index 711c24c..48cb86f 100644
--- a/chrome/browser/download/download_util.cc
+++ b/chrome/browser/download/download_util.cc
@@ -400,4 +400,12 @@ std::wstring GetProgressStatusText(DownloadItem* download) {
amount, time_remaining);
}
+#if !defined(OS_MACOSX)
+void UpdateAppIconDownloadProgress(int download_count,
+ bool progress_known,
+ float progress) {
+ // Win7 Superbar wants some pixel lovin! http://crbug.com/8039
+}
+#endif
+
} // namespace download_util
diff --git a/chrome/browser/download/download_util.h b/chrome/browser/download/download_util.h
index 93114fe..f14be9a 100644
--- a/chrome/browser/download/download_util.h
+++ b/chrome/browser/download/download_util.h
@@ -144,6 +144,15 @@ DictionaryValue* CreateDownloadItemValue(DownloadItem* download, int id);
// Get the localized status text for an in-progress download.
std::wstring GetProgressStatusText(DownloadItem* download);
+// Update the application icon to indicate overall download progress.
+// |download_count| is the number of downloads currently in progress. If
+// |progress_known| is false, then at least one download is of indeterminate
+// size and |progress| is invalid, otherwise |progress| indicates the overall
+// download progress (float value from 0..1).
+void UpdateAppIconDownloadProgress(int download_count,
+ bool progress_known,
+ float progress);
+
} // namespace download_util
#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_