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

Unified Diff: chrome/browser/download/download_manager.cc

Issue 7277073: Support for adding save page download items into downloads history. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/download/download_manager.cc
===================================================================
--- chrome/browser/download/download_manager.cc (revision 92431)
+++ chrome/browser/download/download_manager.cc (working copy)
@@ -55,7 +55,8 @@
: shutdown_needed_(false),
profile_(NULL),
file_manager_(NULL),
- status_updater_(status_updater->AsWeakPtr()) {
+ status_updater_(status_updater->AsWeakPtr()),
+ next_save_page_id_(0) {
if (status_updater_)
status_updater_->AddDelegate(this);
}
@@ -122,6 +123,7 @@
in_progress_.clear();
active_downloads_.clear();
+ save_page_downloads_.clear();
Randy Smith (Not in Mondays) 2011/07/15 17:58:39 If I'm reading the protocol right, save_page_downl
achuithb 2011/07/16 20:15:32 Didn't know that. I've deleted the line. Do you th
Randy Smith (Not in Mondays) 2011/07/17 18:25:47 Yes, if you would.
achuithb 2011/07/20 03:32:21 Done.
history_downloads_.clear();
#if !defined(NDEBUG)
save_page_as_downloads_.clear();
@@ -985,14 +987,18 @@
return RemoveDownloadsBetween(base::Time(), base::Time());
}
-void DownloadManager::SavePageAsDownloadStarted(DownloadItem* download) {
+void DownloadManager::SavePageDownloadStarted(DownloadItem* download) {
#if !defined(NDEBUG)
save_page_as_downloads_.insert(download);
#endif
+ DCHECK(!ContainsKey(save_page_downloads_, download->id()));
downloads_.insert(download);
- // Add to history and notify observers.
- AddDownloadItemToHistory(download, DownloadHistory::kUninitializedHandle);
- NotifyModelChanged();
+ save_page_downloads_[download->id()] = download;
+
+ // Add this entry to the history service.
+ // Additionally, the UI is notified in the callback.
+ download_history_->AddEntry(download,
+ NewCallback(this, &DownloadManager::OnSavePageDownloadEntryAdded));
}
// Initiate a download of a specific URL. We send the request to the
@@ -1197,6 +1203,13 @@
DCHECK(!ContainsKey(history_downloads_, download->db_handle()));
history_downloads_[download->db_handle()] = download;
+
+ // Show in the appropriate browser UI.
+ // This includes buttons to save or cancel, for a dangerous download.
+ ShowDownloadInBrowser(download);
+
+ // Inform interested objects about the new download.
+ NotifyModelChanged();
}
// Once the new DownloadItem's creation info has been committed to the history
@@ -1215,13 +1228,6 @@
AddDownloadItemToHistory(download, db_handle);
- // Show in the appropriate browser UI.
- // This includes buttons to save or cancel, for a dangerous download.
- ShowDownloadInBrowser(download);
-
- // Inform interested objects about the new download.
- NotifyModelChanged();
-
// If the download is still in progress, try to complete it.
//
// Otherwise, download has been cancelled or interrupted before we've
@@ -1367,3 +1373,38 @@
void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() {
observed_download_manager_ = NULL;
}
+
+void DownloadManager::OnSavePageDownloadEntryAdded(int32 download_id,
+ int64 db_handle) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ DownloadMap::const_iterator it = save_page_downloads_.find(download_id);
+ DCHECK(it != save_page_downloads_.end());
Randy Smith (Not in Mondays) 2011/07/15 17:58:39 I believe this DCHECK is inaccurate--specifically,
achuithb 2011/07/16 20:15:32 The item remains in save_page_downloads_ until bot
Randy Smith (Not in Mondays) 2011/07/17 18:25:47 Whoops, I'm sorry; I hadn't tracked that part of t
achuithb 2011/07/20 03:32:21 Ok, I've done what you suggest. I was following th
+ if (it == save_page_downloads_.end())
+ return;
+
+ DownloadItem* download = it->second;
+ DCHECK(download);
+ if (!download)
+ return;
+
+ AddDownloadItemToHistory(download, db_handle);
+
+ // The download may have completed before we received the DB handle.
Randy Smith (Not in Mondays) 2011/07/15 17:58:39 Not requesting a change, just registering a disqui
achuithb 2011/07/16 20:15:32 I've been thinking about this, and no elegant solu
Randy Smith (Not in Mondays) 2011/07/17 18:25:47 Nope--else I would have. I came to the same concl
+ if (!download->IsInProgress())
+ SavePageDownloadFinished(download);
+}
+
+void DownloadManager::SavePageDownloadFinished(DownloadItem* download) {
+ if (download->db_handle() > DownloadHistory::kUninitializedHandle) {
+ download_history_->UpdateEntry(download);
+ DCHECK(ContainsKey(save_page_downloads_, download->id()));
+ save_page_downloads_.erase(download->id());
+ }
+}
+
+int32 DownloadManager::GetNextSavePageId() {
benjhayden 2011/07/18 15:37:45 Apologies if this was addressed elsewhere, but how
achuithb 2011/07/18 18:33:18 Not addressed elsewhere. There's a GetNextId in b
benjhayden 2011/07/18 19:25:01 If the multi-thread accessibility is the only issu
achuith 2011/07/18 19:44:38 From reading the CL description, I feel like the i
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ return next_save_page_id_++;
+}
+

Powered by Google App Engine
This is Rietveld 408576698