Index: chrome/browser/download/save_package.cc |
=================================================================== |
--- chrome/browser/download/save_package.cc (revision 91473) |
+++ chrome/browser/download/save_package.cc (working copy) |
@@ -21,6 +21,7 @@ |
#include "chrome/browser/browser_process.h" |
#include "chrome/browser/download/download_item.h" |
#include "chrome/browser/download/download_item_model.h" |
+#include "chrome/browser/download/download_history.h" |
#include "chrome/browser/download/download_manager.h" |
#include "chrome/browser/download/download_prefs.h" |
#include "chrome/browser/download/download_util.h" |
@@ -173,6 +174,7 @@ |
wait_state_(INITIALIZE), |
tab_id_(tab_contents()->GetRenderProcessHost()->id()), |
unique_id_(g_save_package_id++), |
+ download_manager_(tab_contents()->profile()->GetDownloadManager()), |
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
DCHECK(page_url_.is_valid()); |
DCHECK(save_type_ == SAVE_AS_ONLY_HTML || |
@@ -199,6 +201,7 @@ |
wait_state_(INITIALIZE), |
tab_id_(tab_contents()->GetRenderProcessHost()->id()), |
unique_id_(g_save_package_id++), |
+ download_manager_(tab_contents()->profile()->GetDownloadManager()), |
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
DCHECK(page_url_.is_valid()); |
InternalInit(); |
@@ -224,6 +227,7 @@ |
wait_state_(INITIALIZE), |
tab_id_(0), |
unique_id_(g_save_package_id++), |
+ download_manager_(tab_contents()->profile()->GetDownloadManager()), |
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
} |
@@ -315,18 +319,22 @@ |
} |
// Create the fake DownloadItem and display the view. |
- DownloadManager* download_manager = |
- tab_contents()->profile()->GetDownloadManager(); |
- download_ = new DownloadItem(download_manager, |
+ if (!download_manager_) { |
+ NOTREACHED(); |
+ return false; |
+ } |
+ 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_); |
+ download_manager_->SavePageAsDownloadStarted(download_); |
- wrapper_->download_tab_helper()->OnStartDownload(download_); |
+ // Add this entry to the history service, which also notifies the UI. |
+ download_manager_->download_history()->AddEntry(download_, |
+ NewCallback(this, &SavePackage::OnDownloadEntryAdded)); |
Randy Smith (Not in Mondays)
2011/07/08 16:56:25
I'm concerned that there's a race here if SavePack
achuithb
2011/07/08 21:23:54
Done.
|
// Check save type and process the save page job. |
if (save_type_ == SAVE_AS_COMPLETE_HTML) { |
@@ -691,6 +699,8 @@ |
// Inform the DownloadItem we have canceled whole save page job. |
download_->Cancel(false); |
+ if (download_manager_) |
+ download_manager_->download_history()->UpdateEntry(download_); |
} |
void SavePackage::CheckFinish() { |
@@ -745,6 +755,8 @@ |
download_->OnAllDataSaved(all_save_items_count_); |
download_->MarkAsComplete(); |
+ if (download_manager_) |
+ download_manager_->download_history()->UpdateEntry(download_); |
NotificationService::current()->Notify( |
NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED, |
@@ -1474,3 +1486,14 @@ |
void SavePackage::FileSelectionCanceled(void* params) { |
} |
+ |
+void SavePackage::ManagerGoingDown() { |
Randy Smith (Not in Mondays)
2011/07/08 16:56:25
Where is the SavePackage registered as an observer
achuithb
2011/07/08 21:23:54
I left it out by mistake. I've added the calls to
|
+ download_manager_ = NULL; |
Randy Smith (Not in Mondays)
2011/07/08 16:56:25
I believe that it isn't possible for the download
achuithb
2011/07/08 21:23:54
Makes sense. DCHECKs added. Done.
|
+} |
+ |
+void SavePackage::OnDownloadEntryAdded(int32 download_id, int64 db_handle) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ if (download_manager_) |
+ download_manager_->AddDownloadItemToHistory(download_, db_handle); |
+} |
+ |