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 430702bf48f1f272e579ea9b7e36e86b5d8dcfda..74f94a66f0d90ae6d2a12bf3b009d01271a6e8eb 100644 |
| --- a/chrome/browser/download/chrome_download_manager_delegate.cc |
| +++ b/chrome/browser/download/chrome_download_manager_delegate.cc |
| @@ -43,6 +43,22 @@ |
| using content::BrowserThread; |
| using safe_browsing::DownloadProtectionService; |
| +namespace { |
| + |
| +// String pointer used for identifying safebrowing data associated with |
| +// a download item. |
| +static const char safe_browsing_id[] = "Safe Browsing ID"; |
| + |
| +// The state of a safebrowsing check. If there is no data associated with the |
|
asanka
2011/12/07 04:10:57
cliffhanger :)
Randy Smith (Not in Mondays)
2011/12/07 18:36:12
Removed :-}.
|
| +struct SafeBrowsingState : public DownloadItem::ExternalData { |
| + // If true the SafeBrowsing check is not done yet. |
| + bool pending; |
| + // The verdict that we got from calling CheckClientDownload. |
| + safe_browsing::DownloadProtectionService::DownloadCheckResult verdict; |
| +}; |
| + |
| +} |
| + |
| ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile) |
| : profile_(profile), |
| download_prefs_(new DownloadPrefs(profile->GetPrefs())) { |
| @@ -153,14 +169,12 @@ bool ChromeDownloadManagerDelegate::ShouldOpenFileBasedOnExtension( |
| bool ChromeDownloadManagerDelegate::ShouldCompleteDownload(DownloadItem* item) { |
| #if defined(ENABLE_SAFE_BROWSING) |
| // See if there is already a pending SafeBrowsing check for that download. |
| - SafeBrowsingStateMap::iterator it = safe_browsing_state_.find(item->GetId()); |
| - if (it != safe_browsing_state_.end()) { |
| - SafeBrowsingState state = it->second; |
| - if (!state.pending) { |
| - safe_browsing_state_.erase(it); |
| - } |
| - return !state.pending; |
| - } |
| + SafeBrowsingState* state = static_cast<SafeBrowsingState*>( |
| + item->GetExternalData(&safe_browsing_id)); |
| + if (state) |
| + // Don't complete the download until we have an answer. |
| + return !state->pending; |
| + |
| // Begin the safe browsing download protection check. |
| DownloadProtectionService* service = GetDownloadProtectionService(); |
| if (service) { |
| @@ -172,10 +186,10 @@ bool ChromeDownloadManagerDelegate::ShouldCompleteDownload(DownloadItem* item) { |
| &ChromeDownloadManagerDelegate::CheckClientDownloadDone, |
| this, |
| item->GetId())); |
| - SafeBrowsingState state; |
| - state.pending = true; |
| - state.verdict = DownloadProtectionService::SAFE; |
| - safe_browsing_state_[item->GetId()] = state; |
| + state = new SafeBrowsingState(); |
| + state->pending = true; |
| + state->verdict = DownloadProtectionService::SAFE; |
| + item->SetExternalData(&safe_browsing_id, state); |
| return false; |
| } |
| #endif |
| @@ -331,10 +345,8 @@ void ChromeDownloadManagerDelegate::CheckClientDownloadDone( |
| int32 download_id, |
| DownloadProtectionService::DownloadCheckResult result) { |
| DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); |
| - if (!item) { |
| - safe_browsing_state_.erase(download_id); // Just in case. |
| + if (!item) |
| return; |
| - } |
| VLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false) |
| << " verdict = " << result; |
| @@ -344,11 +356,12 @@ void ChromeDownloadManagerDelegate::CheckClientDownloadDone( |
| item->GetSafetyState() == DownloadItem::SAFE) |
| item->MarkContentDangerous(); |
| - SafeBrowsingStateMap::iterator it = safe_browsing_state_.find(item->GetId()); |
| - DCHECK(it != safe_browsing_state_.end() && it->second.pending); |
| - if (it != safe_browsing_state_.end()) { |
| - it->second.pending = false; |
| - it->second.verdict = result; |
| + SafeBrowsingState* state = static_cast<SafeBrowsingState*>( |
| + item->GetExternalData(&safe_browsing_id)); |
| + DCHECK(state); |
| + if (state) { |
| + state->pending = false; |
| + state->verdict = result; |
| } |
| item->MaybeCompleteDownload(); |
| } |