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

Unified Diff: chrome/browser/download/save_package.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/save_package.cc
===================================================================
--- chrome/browser/download/save_package.cc (revision 92431)
+++ chrome/browser/download/save_package.cc (working copy)
@@ -173,6 +173,7 @@
wait_state_(INITIALIZE),
tab_id_(tab_contents()->GetRenderProcessHost()->id()),
unique_id_(g_save_package_id++),
+ download_manager_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
DCHECK(page_url_.is_valid());
DCHECK(save_type_ == SAVE_AS_ONLY_HTML ||
@@ -199,6 +200,7 @@
wait_state_(INITIALIZE),
tab_id_(tab_contents()->GetRenderProcessHost()->id()),
unique_id_(g_save_package_id++),
+ download_manager_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
DCHECK(page_url_.is_valid());
InternalInit();
@@ -224,6 +226,7 @@
wait_state_(INITIALIZE),
tab_id_(0),
unique_id_(g_save_package_id++),
+ download_manager_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
}
@@ -234,6 +237,9 @@
Cancel(true);
}
+ // We should no longer be observing the DownloadManager.
+ CHECK(!download_manager_);
+
DCHECK(all_save_items_count_ == (waiting_item_queue_.size() +
completed_count() +
in_process_count()));
@@ -314,20 +320,23 @@
return false;
}
- // Create the fake DownloadItem and display the view.
- DownloadManager* download_manager =
- tab_contents()->profile()->GetDownloadManager();
- download_ = new DownloadItem(download_manager,
+ // Get the download manager and add ourselves as an observer.
+ download_manager_ = tab_contents()->profile()->GetDownloadManager();
+ if (!download_manager_) {
+ NOTREACHED();
+ return false;
+ }
+ download_manager_->AddObserver(this);
+
+ // Create the download item.
+ download_ = new DownloadItem(download_manager_,
saved_main_file_path_,
page_url_,
profile->IsOffTheRecord());
- // Transfer the ownership to the download manager. We need the DownloadItem
- // to be alive as long as the Profile is alive.
- download_manager->SavePageAsDownloadStarted(download_);
+ // Transfer ownership of download item to DownloadManager.
+ download_manager_->SavePageDownloadStarted(download_);
- wrapper_->download_tab_helper()->OnStartDownload(download_);
-
// Check save type and process the save page job.
if (save_type_ == SAVE_AS_COMPLETE_HTML) {
// Get directory
@@ -691,6 +700,7 @@
// Inform the DownloadItem we have canceled whole save page job.
download_->Cancel(false);
+ FinalizeDownloadEntry();
}
void SavePackage::CheckFinish() {
@@ -745,6 +755,7 @@
download_->OnAllDataSaved(all_save_items_count_);
download_->MarkAsComplete();
+ FinalizeDownloadEntry();
NotificationService::current()->Notify(
chrome::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED,
@@ -1474,3 +1485,18 @@
void SavePackage::FileSelectionCanceled(void* params) {
}
+
+void SavePackage::ManagerGoingDown() {
+ download_ = NULL;
+ download_manager_ = NULL;
+}
+
+void SavePackage::FinalizeDownloadEntry() {
+ DCHECK(download_manager_);
+ if (download_manager_) {
+ download_manager_->SavePageDownloadFinished(download_);
+ download_manager_->RemoveObserver(this);
+ download_manager_ = NULL;
+ }
+}
+

Powered by Google App Engine
This is Rietveld 408576698