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..7549d3e7e2caba671826d77dde5211c6cb2671aa 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" |
| @@ -140,6 +144,18 @@ void OnWebIntentDispatchCompleted( |
| base::Bind(&DeleteFile, file_path)); |
| } |
| +typedef base::Callback<void(bool)> VisitedBeforeCallback; |
| + |
| +void VisitCountsToVisitedBefore( |
|
Randy Smith (Not in Mondays)
2012/11/09 21:36:39
*snort* No problem can't be solved by another lay
benjhayden
2012/11/12 18:44:16
Done.
|
| + const VisitedBeforeCallback& callback, |
| + HistoryService::Handle unused_handle, |
| + bool found_visits, |
| + int count, |
| + base::Time first_visit) { |
| + callback.Run(found_visits && count && |
| + (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight())); |
| +} |
| + |
| } // namespace |
| ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile) |
| @@ -153,18 +169,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 +176,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 +495,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, |
| @@ -650,10 +617,22 @@ void ChromeDownloadManagerDelegate::CheckDownloadUrlDone( |
| if (result != DownloadProtectionService::SAFE) |
| danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL; |
| - download_history_->CheckVisitedReferrerBefore( |
| - download_id, download->GetReferrerUrl(), |
| - base::Bind(&ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone, |
| - this, download_id, callback, danger_type)); |
| + // HistoryServiceFactory redirects incognito profiles to on-record profiles. |
| + HistoryService* history = HistoryServiceFactory::GetForProfile( |
| + profile_, Profile::EXPLICIT_ACCESS); |
| + 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(download_id, callback, danger_type, false); |
| + return; |
| + } |
| + history->GetVisibleVisitCountToHost( |
| + download->GetReferrerUrl(), &history_consumer_, |
| + base::Bind(&VisitCountsToVisitedBefore, base::Bind( |
| + &ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone, |
| + this, download_id, callback, danger_type))); |
| } |
| void ChromeDownloadManagerDelegate::CheckClientDownloadDone( |
| @@ -808,8 +787,8 @@ 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(), callback, should_prompt, |
| + is_forced_path, danger_type)); |
| #else |
| GetReservedPath( |
| *download, suggested_path, download_prefs_->DownloadPath(), |
| @@ -901,15 +880,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); |
| -} |