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

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

Issue 6312027: Add files saved using 'Save page as' to the download history.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 10 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 73953)
+++ chrome/browser/download/save_package.cc (working copy)
@@ -20,6 +20,7 @@
#include "base/threading/thread.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/download/download_history.h"
#include "chrome/browser/download/download_item.h"
#include "chrome/browser/download/download_item_model.h"
#include "chrome/browser/download/download_manager.h"
@@ -347,18 +348,11 @@
request_context_getter_ = profile->GetRequestContext();
- // Create the fake DownloadItem and display the view.
- DownloadManager* download_manager =
- tab_contents_->profile()->GetDownloadManager();
- download_ = new DownloadItem(download_manager,
- saved_main_file_path_,
- page_url_,
- profile->IsOffTheRecord());
+ // Create the fake DownloadItem and add it to the download history.
+ CreateDownloadItem(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_);
-
tab_contents_->OnStartDownload(download_);
// Check save type and process the save page job.
@@ -386,6 +380,41 @@
return true;
}
+void SavePackage::OnDownloadEntryAdded(DownloadCreateInfo info,
+ int64 db_handle) {
+ DownloadManager* download_manager =
+ tab_contents_->profile()->GetDownloadManager();
+
+ download_manager->AddDownloadItemToHistory(download_, db_handle);
+}
+
+void SavePackage::CreateDownloadItem(const FilePath& path,
+ const GURL& url,
+ bool is_otr) {
+ DownloadManager* download_manager =
+ tab_contents_->profile()->GetDownloadManager();
+
+ download_ = new DownloadItem(download_manager, path, url, is_otr);
+
+ // 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_);
+
+ // Copy over the fields used by the history service.
+ DownloadCreateInfo info(download_->full_path(),
+ download_->url(),
+ download_->start_time(),
+ 0, 0,
+ download_->state(),
+ download_->id(),
+ false);
+
+ // Add entry to the history service.
+ DownloadHistory* download_history = download_manager->download_history();
+ download_history->AddEntry(info, download_,
+ NewCallback(this, &SavePackage::OnDownloadEntryAdded));
+}
+
// Generate name for saving resource.
bool SavePackage::GenerateFileName(const std::string& disposition,
const GURL& url,
@@ -664,6 +693,9 @@
// Inform the DownloadItem we have canceled whole save page job.
download_->Cancel(false);
+ DownloadManager* download_manager =
+ tab_contents_->profile()->GetDownloadManager();
+ download_manager->download_history()->UpdateEntry(download_);
}
void SavePackage::CheckFinish() {
@@ -718,10 +750,16 @@
download_->OnAllDataSaved(all_save_items_count_);
download_->MarkAsComplete();
+
// Notify download observers that we are complete (the call
// to OnReadyToFinish() set the state to complete but did not notify).
download_->UpdateObservers();
+ // Update the download history.
+ DownloadManager* download_manager =
+ tab_contents_->profile()->GetDownloadManager();
+ download_manager->download_history()->UpdateEntry(download_);
+
NotificationService::current()->Notify(
NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED,
Source<SavePackage>(this),

Powered by Google App Engine
This is Rietveld 408576698