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

Unified Diff: chrome/browser/safe_browsing/download_protection_service.cc

Issue 8438012: Parse the download server response. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove DCHECK bug Created 9 years, 1 month 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/safe_browsing/download_protection_service.cc
diff --git a/chrome/browser/safe_browsing/download_protection_service.cc b/chrome/browser/safe_browsing/download_protection_service.cc
index afb797dde920be29e8f6d63643e4ee06224dfd4d..ce10f137fcff2cf52b7fa54408f52bc43352c596 100644
--- a/chrome/browser/safe_browsing/download_protection_service.cc
+++ b/chrome/browser/safe_browsing/download_protection_service.cc
@@ -186,26 +186,27 @@ class DownloadProtectionService::CheckClientDownloadRequest
<< info_.download_url_chain.back() << ": success="
<< source->GetStatus().is_success() << " response_code="
<< source->GetResponseCode();
- DownloadCheckResultReason reason = REASON_MAX;
- reason = REASON_SERVER_PING_FAILED;
+ DownloadCheckResultReason reason = REASON_SERVER_PING_FAILED;
+ DownloadCheckResult result = SAFE;
if (source->GetStatus().is_success() &&
RC_REQUEST_OK == source->GetResponseCode()) {
+ ClientDownloadResponse response;
std::string data;
- source->GetResponseAsString(&data);
- if (data.size() > 0) {
- // For now no matter what we'll always say the download is safe.
- // TODO(noelutz): Parse the response body to see exactly what's going
- // on.
+ bool got_data = source->GetResponseAsString(&data);
+ DCHECK(got_data);
+ if (!response.ParseFromString(data)) {
reason = REASON_INVALID_RESPONSE_PROTO;
+ } else if (response.verdict() == ClientDownloadResponse::DANGEROUS) {
+ reason = REASON_DOWNLOAD_DANGEROUS;
+ result = DANGEROUS;
+ } else {
+ reason = REASON_DOWNLOAD_SAFE;
}
}
-
- if (reason != REASON_MAX) {
- RecordStats(reason);
- }
// We don't need the fetcher anymore.
fetcher_.reset();
- FinishRequest(SAFE);
+ RecordStats(reason);
+ FinishRequest(result);
}
private:

Powered by Google App Engine
This is Rietveld 408576698