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

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
« no previous file with comments | « chrome/browser/download/save_package.h ('k') | chrome/browser/download/save_page_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/download/save_package.cc
===================================================================
--- chrome/browser/download/save_package.cc (revision 76501)
+++ chrome/browser/download/save_package.cc (working copy)
@@ -19,6 +19,7 @@
#include "base/task.h"
#include "base/threading/thread.h"
#include "chrome/browser/browser_process.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"
@@ -313,18 +314,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.
@@ -352,6 +346,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));
+}
+
// On POSIX, the length of |pure_file_name| + |file_name_ext| is further
// restricted by NAME_MAX. The maximum allowed path looks like:
// '/path/to/save_dir' + '/' + NAME_MAX.
@@ -690,6 +719,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() {
@@ -744,10 +776,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),
« no previous file with comments | « chrome/browser/download/save_package.h ('k') | chrome/browser/download/save_page_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698