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

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

Issue 10665049: Make DownloadHistory observe manager, items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 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/chrome_download_manager_delegate.cc
diff --git a/chrome/browser/download/chrome_download_manager_delegate.cc b/chrome/browser/download/chrome_download_manager_delegate.cc
index fc95cbf4f129ef68b2e2c50d187f02548b1c81d1..5f8186ffab0d0e3d293e98151ff7be8c6f79d560 100644
--- a/chrome/browser/download/chrome_download_manager_delegate.cc
+++ b/chrome/browser/download/chrome_download_manager_delegate.cc
@@ -20,14 +20,15 @@
#include "chrome/browser/download/download_extensions.h"
#include "chrome/browser/download/download_file_picker.h"
#include "chrome/browser/download/download_history.h"
-#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/download/download_path_reservation_tracker.h"
+#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/download/download_status_updater.h"
#include "chrome/browser/download/download_util.h"
#include "chrome/browser/download/save_package_file_picker.h"
#include "chrome/browser/extensions/api/downloads/downloads_api.h"
#include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/prefs/pref_member.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
@@ -39,6 +40,7 @@
#include "chrome/common/pref_names.h"
#include "content/public/browser/download_item.h"
#include "content/public/browser/download_manager.h"
+#include "content/public/browser/download_persistent_store_info.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
@@ -118,6 +120,48 @@ void GenerateFileNameFromRequest(const DownloadItem& download_item,
default_file_name);
}
+class HistoryServiceDownloadAdapter : public HistoryServiceDownloadInterface {
+ public:
+ explicit HistoryServiceDownloadAdapter(HistoryService* history_service)
+ : history_service_(history_service) {
+ }
+ virtual ~HistoryServiceDownloadAdapter() {}
+ virtual void QueryDownloads(
+ const HistoryService::DownloadQueryCallback& callback) OVERRIDE {
+ history_service_->QueryDownloads(&history_consumer_, callback);
+ history_service_->CleanUpInProgressEntries();
+ }
+ virtual HistoryService::Handle GetVisibleVisitCountToHost(
+ const GURL& referrer_url,
+ const HistoryService::GetVisibleVisitCountToHostCallback&
+ callback) OVERRIDE {
+ return history_service_->GetVisibleVisitCountToHost(
+ referrer_url, &history_consumer_, callback);
+ }
+ virtual void CreateDownload(
+ int32 id,
+ const content::DownloadPersistentStoreInfo& info,
+ const HistoryService::DownloadCreateCallback& callback) OVERRIDE {
+ history_service_->CreateDownload(id, info, &history_consumer_, callback);
+ }
+ virtual void UpdateDownload(
+ const content::DownloadPersistentStoreInfo& info) OVERRIDE {
+ history_service_->UpdateDownload(info);
+ }
+ virtual void RemoveDownloads(const std::set<int64>& handles) OVERRIDE {
+ history_service_->RemoveDownloads(handles);
+ }
+ virtual void OnDownloadHistoryDestroyed() OVERRIDE {
+ delete this;
+ }
+
+ private:
+ CancelableRequestConsumer history_consumer_;
+ HistoryService* history_service_;
+
+ DISALLOW_COPY_AND_ASSIGN(HistoryServiceDownloadAdapter);
+};
+
} // namespace
ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile)
@@ -131,18 +175,26 @@ ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() {
void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) {
download_manager_ = dm;
- download_history_.reset(new DownloadHistory(profile_));
- download_history_->Load(
- base::Bind(&DownloadManager::OnPersistentStoreQueryComplete,
- base::Unretained(dm)));
+
#if !defined(OS_ANDROID)
extension_event_router_.reset(new ExtensionDownloadsEventRouter(
profile_, download_manager_));
#endif
+
+ if (profile_ == profile_->GetOriginalProfile()) {
+ HistoryService* hs = HistoryServiceFactory::GetForProfile(
+ profile_, Profile::EXPLICIT_ACCESS);
+ if (hs) {
+ download_history_.reset(new DownloadHistory(
+ download_manager_, new HistoryServiceDownloadAdapter(hs)));
+ download_history_->Load(base::Bind(
+ &DownloadManager::OnPersistentStoreQueryComplete,
+ download_manager_));
+ }
+ }
}
void ChromeDownloadManagerDelegate::Shutdown() {
- download_history_.reset();
download_prefs_.reset();
#if !defined(OS_ANDROID)
extension_event_router_.reset();
@@ -252,12 +304,12 @@ bool ChromeDownloadManagerDelegate::ShouldOpenFileBasedOnExtension(
void ChromeDownloadManagerDelegate::DisableSafeBrowsing(DownloadItem* item) {
#if defined(ENABLE_SAFE_BROWSING)
SafeBrowsingState* state = static_cast<SafeBrowsingState*>(
- item->GetExternalData(&safe_browsing_id));
+ item->GetUserData(&safe_browsing_id));
DCHECK(!state);
if (!state)
state = new SafeBrowsingState();
state->SetVerdict(DownloadProtectionService::SAFE);
- item->SetExternalData(&safe_browsing_id, state);
+ item->SetUserData(&safe_browsing_id, state);
#endif
}
@@ -266,7 +318,7 @@ bool ChromeDownloadManagerDelegate::IsDownloadReadyForCompletion(
const base::Closure& internal_complete_callback) {
#if defined(ENABLE_SAFE_BROWSING)
SafeBrowsingState* state = static_cast<SafeBrowsingState*>(
- item->GetExternalData(&safe_browsing_id));
+ item->GetUserData(&safe_browsing_id));
if (!state) {
// Begin the safe browsing download protection check.
DownloadProtectionService* service = GetDownloadProtectionService();
@@ -275,7 +327,7 @@ bool ChromeDownloadManagerDelegate::IsDownloadReadyForCompletion(
<< item->DebugString(false);
state = new SafeBrowsingState();
state->set_callback(internal_complete_callback);
- item->SetExternalData(&safe_browsing_id, state);
+ item->SetUserData(&safe_browsing_id, state);
service->CheckClientDownload(
DownloadProtectionService::DownloadInfo::FromDownloadItem(*item),
base::Bind(
@@ -422,35 +474,6 @@ bool ChromeDownloadManagerDelegate::GenerateFileHash() {
#endif
}
-void ChromeDownloadManagerDelegate::AddItemToPersistentStore(
- DownloadItem* item) {
- download_history_->AddEntry(item,
- base::Bind(&ChromeDownloadManagerDelegate::OnItemAddedToPersistentStore,
- base::Unretained(this)));
-}
-
-void ChromeDownloadManagerDelegate::UpdateItemInPersistentStore(
- DownloadItem* item) {
- download_history_->UpdateEntry(item);
-}
-
-void ChromeDownloadManagerDelegate::UpdatePathForItemInPersistentStore(
- DownloadItem* item,
- const FilePath& new_path) {
- download_history_->UpdateDownloadPath(item, new_path);
-}
-
-void ChromeDownloadManagerDelegate::RemoveItemFromPersistentStore(
- DownloadItem* item) {
- download_history_->RemoveEntry(item);
-}
-
-void ChromeDownloadManagerDelegate::RemoveItemsFromPersistentStoreBetween(
- base::Time remove_begin,
- base::Time remove_end) {
- download_history_->RemoveEntriesBetween(remove_begin, remove_end);
-}
-
void ChromeDownloadManagerDelegate::GetSaveDir(WebContents* web_contents,
FilePath* website_save_dir,
FilePath* download_save_dir,
@@ -609,7 +632,7 @@ void ChromeDownloadManagerDelegate::CheckClientDownloadDone(
}
SafeBrowsingState* state = static_cast<SafeBrowsingState*>(
- item->GetExternalData(&safe_browsing_id));
+ item->GetUserData(&safe_browsing_id));
state->SetVerdict(result);
}
@@ -815,15 +838,3 @@ void ChromeDownloadManagerDelegate::OnTargetPathDetermined(
}
callback.Run(target_path, disposition, danger_type, intermediate_path);
}
-
-void ChromeDownloadManagerDelegate::OnItemAddedToPersistentStore(
- int32 download_id, int64 db_handle) {
- // It's not immediately obvious, but HistoryBackend::CreateDownload() can
- // call this function with an invalid |db_handle|. For instance, this can
- // happen when the history database is offline. We cannot have multiple
- // DownloadItems with the same invalid db_handle, so we need to assign a
- // unique |db_handle| here.
- if (db_handle == DownloadItem::kUninitializedHandle)
- db_handle = download_history_->GetNextFakeDbHandle();
- download_manager_->OnItemAddedToPersistentStore(download_id, db_handle);
-}

Powered by Google App Engine
This is Rietveld 408576698