summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-15 02:17:40 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-15 02:17:40 +0000
commitdbe31472193ad4493df891d1e5e001621262b103 (patch)
tree6876d9f86bb48891ca9b13b1ec3813cb4f4d930f
parent29b658ad8a878c3f00fe79e99b453ede55116adb (diff)
downloadchromium_src-dbe31472193ad4493df891d1e5e001621262b103.zip
chromium_src-dbe31472193ad4493df891d1e5e001621262b103.tar.gz
chromium_src-dbe31472193ad4493df891d1e5e001621262b103.tar.bz2
Merge 101003 - Bring back safe browsing binary digest checking. I accidentally removed that code because I thought it didn't do anything (since the callback did nothing).
BUG=96511 Review URL: http://codereview.chromium.org/7888029 TBR=jam@chromium.org Review URL: http://codereview.chromium.org/7886055 git-svn-id: svn://svn.chromium.org/chrome/branches/874/src@101226 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/download/chrome_download_manager_delegate.cc33
-rw-r--r--chrome/browser/download/chrome_download_manager_delegate.h6
-rw-r--r--content/browser/download/download_manager.cc2
-rw-r--r--content/browser/download/download_manager.h5
-rw-r--r--content/browser/download/download_manager_delegate.h5
-rw-r--r--content/browser/download/mock_download_manager_delegate.cc4
-rw-r--r--content/browser/download/mock_download_manager_delegate.h2
7 files changed, 52 insertions, 5 deletions
diff --git a/chrome/browser/download/chrome_download_manager_delegate.cc b/chrome/browser/download/chrome_download_manager_delegate.cc
index 2fd34ca..e3055bc 100644
--- a/chrome/browser/download/chrome_download_manager_delegate.cc
+++ b/chrome/browser/download/chrome_download_manager_delegate.cc
@@ -179,6 +179,28 @@ bool ChromeDownloadManagerDelegate::GenerateFileHash() {
#endif
}
+void ChromeDownloadManagerDelegate::OnResponseCompleted(
+ DownloadItem* item,
+ const std::string& hash) {
+#if defined(ENABLE_SAFE_BROWSING)
+ // When hash is not available, it means either it is not calculated
+ // or there is error while it is calculated. We will skip the download hash
+ // check in that case.
+ if (hash.empty())
+ return;
+
+ scoped_refptr<DownloadSBClient> sb_client =
+ new DownloadSBClient(item->id(),
+ item->url_chain(),
+ item->referrer_url(),
+ profile_->GetPrefs()->GetBoolean(
+ prefs::kSafeBrowsingEnabled));
+ sb_client->CheckDownloadHash(
+ hash,
+ NewCallback(this, &ChromeDownloadManagerDelegate::CheckDownloadHashDone));
+#endif
+}
+
void ChromeDownloadManagerDelegate::AddItemToPersistentStore(
DownloadItem* item) {
download_history_->AddEntry(item,
@@ -511,3 +533,14 @@ void ChromeDownloadManagerDelegate::OnItemAddedToPersistentStore(
db_handle = download_history_->GetNextFakeDbHandle();
download_manager_->OnItemAddedToPersistentStore(download_id, db_handle);
}
+
+// TODO(noelutz): This function currently works as a callback place holder.
+// Once we decide the hash check is reliable, we could move the
+// MaybeCompleteDownload in OnAllDataSaved to this function.
+void ChromeDownloadManagerDelegate::CheckDownloadHashDone(
+ int32 download_id,
+ bool is_dangerous_hash) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DVLOG(1) << "CheckDownloadHashDone, download_id: " << download_id
+ << " is dangerous_hash: " << is_dangerous_hash;
+}
diff --git a/chrome/browser/download/chrome_download_manager_delegate.h b/chrome/browser/download/chrome_download_manager_delegate.h
index 3942c06..d371fb4 100644
--- a/chrome/browser/download/chrome_download_manager_delegate.h
+++ b/chrome/browser/download/chrome_download_manager_delegate.h
@@ -61,6 +61,8 @@ class ChromeDownloadManagerDelegate
virtual bool ShouldOpenDownload(DownloadItem* item) OVERRIDE;
virtual bool ShouldCompleteDownload(DownloadItem* item) OVERRIDE;
virtual bool GenerateFileHash() OVERRIDE;
+ virtual void OnResponseCompleted(DownloadItem* item,
+ const std::string& hash) OVERRIDE;
virtual void AddItemToPersistentStore(DownloadItem* item) OVERRIDE;
virtual void UpdateItemInPersistentStore(DownloadItem* item) OVERRIDE;
virtual void UpdatePathForItemInPersistentStore(
@@ -121,6 +123,10 @@ class ChromeDownloadManagerDelegate
// Callback from history system.
void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle);
+ // Callback function after download file hash is checked with safebrowsing
+ // service.
+ void CheckDownloadHashDone(int32 download_id, bool is_dangerous_hash);
+
Profile* profile_;
scoped_refptr<DownloadManager> download_manager_;
scoped_ptr<DownloadPrefs> download_prefs_;
diff --git a/content/browser/download/download_manager.cc b/content/browser/download/download_manager.cc
index 7657502..394de5e 100644
--- a/content/browser/download/download_manager.cc
+++ b/content/browser/download/download_manager.cc
@@ -364,6 +364,8 @@ void DownloadManager::OnResponseCompleted(int32 download_id,
DownloadItem* download = active_downloads_[download_id];
download->OnAllDataSaved(size);
+ delegate_->OnResponseCompleted(download, hash);
+
MaybeCompleteDownload(download);
}
diff --git a/content/browser/download/download_manager.h b/content/browser/download/download_manager.h
index 994db82..524eb2b 100644
--- a/content/browser/download/download_manager.h
+++ b/content/browser/download/download_manager.h
@@ -295,11 +295,6 @@ class DownloadManager
void ContinueDownloadWithPath(DownloadItem* download,
const FilePath& chosen_file);
- // All data has been downloaded.
- // |hash| is sha256 hash for the downloaded file. It is empty when the hash
- // is not available.
- void OnAllDataSaved(int32 download_id, int64 size, const std::string& hash);
-
// Retrieves the download from the |download_id|.
// Returns NULL if the download is not active.
DownloadItem* GetActiveDownload(int32 download_id);
diff --git a/content/browser/download/download_manager_delegate.h b/content/browser/download/download_manager_delegate.h
index 0a9fb87..1094bd1 100644
--- a/content/browser/download/download_manager_delegate.h
+++ b/content/browser/download/download_manager_delegate.h
@@ -59,6 +59,11 @@ class DownloadManagerDelegate {
// Returns true if we need to generate a binary hash for downloads.
virtual bool GenerateFileHash() = 0;
+ // Informs the delegate that given download has finishd downloading, and gives
+ // it the hash (if it chose to compute it from GenerateFileHash()).
+ virtual void OnResponseCompleted(DownloadItem* item,
+ const std::string& hash) = 0;
+
// Notifies the delegate that a new download item is created. The
// DownloadManager waits for the delegate to add information about this
// download to its persistent store. When the delegate is done, it calls
diff --git a/content/browser/download/mock_download_manager_delegate.cc b/content/browser/download/mock_download_manager_delegate.cc
index 7d39190..e5b8b66 100644
--- a/content/browser/download/mock_download_manager_delegate.cc
+++ b/content/browser/download/mock_download_manager_delegate.cc
@@ -48,6 +48,10 @@ bool MockDownloadManagerDelegate::GenerateFileHash() {
return false;
}
+void MockDownloadManagerDelegate::OnResponseCompleted(DownloadItem* item,
+ const std::string& hash) {
+}
+
void MockDownloadManagerDelegate::AddItemToPersistentStore(DownloadItem* item) {
}
diff --git a/content/browser/download/mock_download_manager_delegate.h b/content/browser/download/mock_download_manager_delegate.h
index 8cbe852..fc3f8f2 100644
--- a/content/browser/download/mock_download_manager_delegate.h
+++ b/content/browser/download/mock_download_manager_delegate.h
@@ -24,6 +24,8 @@ class MockDownloadManagerDelegate : public DownloadManagerDelegate {
virtual bool ShouldOpenDownload(DownloadItem* item) OVERRIDE;
virtual bool ShouldCompleteDownload(DownloadItem* item) OVERRIDE;
virtual bool GenerateFileHash() OVERRIDE;
+ virtual void OnResponseCompleted(DownloadItem* item,
+ const std::string& hash) OVERRIDE;
virtual void AddItemToPersistentStore(DownloadItem* item) OVERRIDE;
virtual void UpdateItemInPersistentStore(DownloadItem* item) OVERRIDE;
virtual void UpdatePathForItemInPersistentStore(