Chromium Code Reviews| 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 960e149f7143cdb76a47207eb56c271fff972e16..01afd5de5dffec472d0f29fe4907f5709aa793cb 100644 |
| --- a/chrome/browser/download/chrome_download_manager_delegate.cc |
| +++ b/chrome/browser/download/chrome_download_manager_delegate.cc |
| @@ -23,12 +23,16 @@ |
| #include "chrome/browser/download/download_history.h" |
| #include "chrome/browser/download/download_path_reservation_tracker.h" |
| #include "chrome/browser/download/download_prefs.h" |
| +#include "chrome/browser/download/download_service.h" |
| +#include "chrome/browser/download/download_service_factory.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.h" |
| +#include "chrome/browser/history/history_service_factory.h" |
| #include "chrome/browser/intents/web_intents_util.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| #include "chrome/browser/profiles/profile.h" |
| @@ -153,18 +157,6 @@ ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { |
| void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { |
| download_manager_ = dm; |
| - download_history_.reset(new DownloadHistory(profile_)); |
| - if (!profile_->IsOffTheRecord()) { |
| - // DownloadManager should not be RefCountedThreadSafe. |
| - // ChromeDownloadManagerDelegate outlives DownloadManager, and |
| - // DownloadHistory uses a scoped canceller to cancel tasks when it is |
| - // deleted. Almost all callbacks to DownloadManager should use weak pointers |
| - // or bounce off a container object that uses ManagerGoingDown() to simulate |
| - // a weak pointer. |
| - download_history_->Load( |
| - base::Bind(&DownloadManager::OnPersistentStoreQueryComplete, |
| - download_manager_)); |
| - } |
| #if !defined(OS_ANDROID) |
| extension_event_router_.reset(new ExtensionDownloadsEventRouter( |
| profile_, download_manager_)); |
| @@ -172,7 +164,6 @@ void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { |
| } |
| void ChromeDownloadManagerDelegate::Shutdown() { |
| - download_history_.reset(); |
| download_prefs_.reset(); |
| #if !defined(OS_ANDROID) |
| extension_event_router_.reset(); |
| @@ -492,42 +483,6 @@ bool ChromeDownloadManagerDelegate::GenerateFileHash() { |
| #endif |
| } |
| -void ChromeDownloadManagerDelegate::AddItemToPersistentStore( |
| - DownloadItem* item) { |
| - if (profile_->IsOffTheRecord()) { |
| - OnItemAddedToPersistentStore( |
| - item->GetId(), download_history_->GetNextFakeDbHandle()); |
| - return; |
| - } |
| - download_history_->AddEntry(item, |
| - base::Bind(&ChromeDownloadManagerDelegate::OnItemAddedToPersistentStore, |
| - 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) { |
| - if (profile_->IsOffTheRecord()) |
| - return; |
| - download_history_->RemoveEntriesBetween(remove_begin, remove_end); |
| -} |
| - |
| void ChromeDownloadManagerDelegate::GetSaveDir(BrowserContext* browser_context, |
| FilePath* website_save_dir, |
| FilePath* download_save_dir, |
| @@ -635,6 +590,11 @@ void ChromeDownloadManagerDelegate::GetReservedPath( |
| callback); |
| } |
| +ChromeDownloadManagerDelegate::VisitedReferrerBeforeDoneParameters:: |
| + VisitedReferrerBeforeDoneParameters() {} |
| +ChromeDownloadManagerDelegate::VisitedReferrerBeforeDoneParameters:: |
| + ~VisitedReferrerBeforeDoneParameters() {} |
| + |
| void ChromeDownloadManagerDelegate::CheckDownloadUrlDone( |
| int32 download_id, |
| const content::DownloadTargetCallback& callback, |
| @@ -650,10 +610,25 @@ void ChromeDownloadManagerDelegate::CheckDownloadUrlDone( |
| if (result != DownloadProtectionService::SAFE) |
| danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL; |
| - download_history_->CheckVisitedReferrerBefore( |
| - download_id, download->GetReferrerUrl(), |
| + VisitedReferrerBeforeDoneParameters params; |
| + params.download_id = download_id; |
| + params.callback = callback; |
| + params.danger_type = danger_type; |
| + |
| + HistoryService* history = HistoryServiceFactory::GetForProfile( |
| + profile_->GetOriginalProfile(), Profile::EXPLICIT_ACCESS); |
|
Randy Smith (Not in Mondays)
2012/11/07 21:10:29
As I read the code, you don't need the GetOriginal
benjhayden
2012/11/08 18:57:03
Done.
|
| + if (!history || !download->GetReferrerUrl().is_valid()) { |
| + // If the original profile doesn't have a HistoryService or the referrer url |
| + // is invalid, then give up and assume the referrer has not been visited |
| + // before. There's no history for on-record profiles in unit_tests, for |
| + // example. |
| + CheckVisitedReferrerBeforeDone(params, 0, false, 0, base::Time::Now()); |
| + return; |
| + } |
| + history->GetVisibleVisitCountToHost( |
| + download->GetReferrerUrl(), &history_consumer_, |
| base::Bind(&ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone, |
| - this, download_id, callback, danger_type)); |
| + this, params)); |
| } |
| void ChromeDownloadManagerDelegate::CheckClientDownloadDone( |
| @@ -710,14 +685,18 @@ void ChromeDownloadManagerDelegate::Observe( |
| } |
| void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( |
| - int32 download_id, |
| - const content::DownloadTargetCallback& callback, |
| - content::DownloadDangerType danger_type, |
| - bool visited_referrer_before) { |
| + const VisitedReferrerBeforeDoneParameters& params, |
| + HistoryService::Handle unused_handle, |
| + bool found_visits, |
| + int count, |
| + base::Time first_visit) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + bool visited_referrer_before = (found_visits && count && |
| + (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight())); |
| + |
| DownloadItem* download = |
| - download_manager_->GetDownload(download_id); |
| + download_manager_->GetDownload(params.download_id); |
| if (!download || (download->GetState() != DownloadItem::IN_PROGRESS)) |
| return; |
| @@ -774,6 +753,8 @@ void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( |
| suggested_path = suggested_path.AddExtension(kWebIntentsFileExtension); |
| } |
| + content::DownloadDangerType danger_type = params.danger_type; |
| + |
| // If the download hasn't already been marked dangerous (could be |
| // DANGEROUS_URL), check if it is a dangerous file. |
| if (danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { |
| @@ -808,14 +789,14 @@ void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( |
| profile_, suggested_path, download, |
| base::Bind( |
| &ChromeDownloadManagerDelegate::SubstituteDriveDownloadPathCallback, |
| - this, download->GetId(), callback, should_prompt, is_forced_path, |
| - danger_type)); |
| + this, download->GetId(), params.callback, should_prompt, |
| + is_forced_path, danger_type)); |
| #else |
| GetReservedPath( |
| *download, suggested_path, download_prefs_->DownloadPath(), |
| !is_forced_path, |
| base::Bind(&ChromeDownloadManagerDelegate::OnPathReservationAvailable, |
| - this, download->GetId(), callback, should_prompt, |
| + this, download->GetId(), params.callback, should_prompt, |
| danger_type)); |
| #endif |
| } |
| @@ -901,15 +882,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); |
| -} |