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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/safe_browsing/download_protection_service.h" 5 #include "chrome/browser/safe_browsing/download_protection_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 124 }
125 125
126 // From the content::URLFetcherDelegate interface. 126 // From the content::URLFetcherDelegate interface.
127 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE { 127 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE {
128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
129 DCHECK_EQ(source, fetcher_.get()); 129 DCHECK_EQ(source, fetcher_.get());
130 VLOG(2) << "Received a response for URL: " 130 VLOG(2) << "Received a response for URL: "
131 << info_.download_url_chain.back() << ": success=" 131 << info_.download_url_chain.back() << ": success="
132 << source->GetStatus().is_success() << " response_code=" 132 << source->GetStatus().is_success() << " response_code="
133 << source->GetResponseCode(); 133 << source->GetResponseCode();
134 DownloadCheckResultReason reason = REASON_MAX; 134 DownloadCheckResultReason reason = REASON_SERVER_PING_FAILED;
135 reason = REASON_SERVER_PING_FAILED; 135 DownloadCheckResult result = SAFE;
136 if (source->GetStatus().is_success() && 136 if (source->GetStatus().is_success() &&
137 RC_REQUEST_OK == source->GetResponseCode()) { 137 RC_REQUEST_OK == source->GetResponseCode()) {
138 ClientDownloadResponse response;
138 std::string data; 139 std::string data;
139 source->GetResponseAsString(&data); 140 DCHECK(source->GetResponseAsString(&data));
140 if (data.size() > 0) { 141 if (!response.ParseFromString(data)) {
141 // For now no matter what we'll always say the download is safe.
142 // TODO(noelutz): Parse the response body to see exactly what's going
143 // on.
144 reason = REASON_INVALID_RESPONSE_PROTO; 142 reason = REASON_INVALID_RESPONSE_PROTO;
143 } else if (response.verdict() == ClientDownloadResponse::MALICIOUS) {
144 reason = REASON_DOWNLOAD_MALICIOUS;
145 result = MALICIOUS;
146 } else {
147 reason = REASON_DOWNLOAD_SAFE;
145 } 148 }
146 } 149 }
147
148 if (reason != REASON_MAX) {
149 RecordStats(reason);
150 }
151 // We don't need the fetcher anymore. 150 // We don't need the fetcher anymore.
152 fetcher_.reset(); 151 fetcher_.reset();
153 FinishRequest(SAFE); 152 RecordStats(reason);
153 FinishRequest(result);
154 } 154 }
155 155
156 private: 156 private:
157 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; 157 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>;
158 friend class DeleteTask<CheckClientDownloadRequest>; 158 friend class DeleteTask<CheckClientDownloadRequest>;
159 159
160 virtual ~CheckClientDownloadRequest() { 160 virtual ~CheckClientDownloadRequest() {
161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
162 } 162 }
163 163
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 void DownloadProtectionService::RequestFinished( 347 void DownloadProtectionService::RequestFinished(
348 CheckClientDownloadRequest* request) { 348 CheckClientDownloadRequest* request) {
349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
350 std::set<scoped_refptr<CheckClientDownloadRequest> >::iterator it = 350 std::set<scoped_refptr<CheckClientDownloadRequest> >::iterator it =
351 download_requests_.find(request); 351 download_requests_.find(request);
352 DCHECK(it != download_requests_.end()); 352 DCHECK(it != download_requests_.end());
353 download_requests_.erase(*it); 353 download_requests_.erase(*it);
354 } 354 }
355 355
356 } // namespace safe_browsing 356 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698