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

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: 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 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 179 }
180 180
181 // From the content::URLFetcherDelegate interface. 181 // From the content::URLFetcherDelegate interface.
182 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE { 182 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE {
183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
184 DCHECK_EQ(source, fetcher_.get()); 184 DCHECK_EQ(source, fetcher_.get());
185 VLOG(2) << "Received a response for URL: " 185 VLOG(2) << "Received a response for URL: "
186 << info_.download_url_chain.back() << ": success=" 186 << info_.download_url_chain.back() << ": success="
187 << source->GetStatus().is_success() << " response_code=" 187 << source->GetStatus().is_success() << " response_code="
188 << source->GetResponseCode(); 188 << source->GetResponseCode();
189 DownloadCheckResultReason reason = REASON_MAX; 189 DownloadCheckResultReason reason = REASON_SERVER_PING_FAILED;
190 reason = REASON_SERVER_PING_FAILED; 190 DownloadCheckResult result = SAFE;
191 if (source->GetStatus().is_success() && 191 if (source->GetStatus().is_success() &&
192 RC_REQUEST_OK == source->GetResponseCode()) { 192 RC_REQUEST_OK == source->GetResponseCode()) {
193 ClientDownloadResponse response;
193 std::string data; 194 std::string data;
194 source->GetResponseAsString(&data); 195 bool got_data = source->GetResponseAsString(&data);
195 if (data.size() > 0) { 196 DCHECK(got_data);
196 // For now no matter what we'll always say the download is safe. 197 if (!response.ParseFromString(data)) {
197 // TODO(noelutz): Parse the response body to see exactly what's going
198 // on.
199 reason = REASON_INVALID_RESPONSE_PROTO; 198 reason = REASON_INVALID_RESPONSE_PROTO;
199 } else if (response.verdict() == ClientDownloadResponse::DANGEROUS) {
200 reason = REASON_DOWNLOAD_DANGEROUS;
201 result = DANGEROUS;
202 } else {
203 reason = REASON_DOWNLOAD_SAFE;
200 } 204 }
201 } 205 }
202
203 if (reason != REASON_MAX) {
204 RecordStats(reason);
205 }
206 // We don't need the fetcher anymore. 206 // We don't need the fetcher anymore.
207 fetcher_.reset(); 207 fetcher_.reset();
208 FinishRequest(SAFE); 208 RecordStats(reason);
209 FinishRequest(result);
209 } 210 }
210 211
211 private: 212 private:
212 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; 213 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>;
213 friend class DeleteTask<CheckClientDownloadRequest>; 214 friend class DeleteTask<CheckClientDownloadRequest>;
214 215
215 virtual ~CheckClientDownloadRequest() { 216 virtual ~CheckClientDownloadRequest() {
216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
217 } 218 }
218 219
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 void DownloadProtectionService::RequestFinished( 403 void DownloadProtectionService::RequestFinished(
403 CheckClientDownloadRequest* request) { 404 CheckClientDownloadRequest* request) {
404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 405 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
405 std::set<scoped_refptr<CheckClientDownloadRequest> >::iterator it = 406 std::set<scoped_refptr<CheckClientDownloadRequest> >::iterator it =
406 download_requests_.find(request); 407 download_requests_.find(request);
407 DCHECK(it != download_requests_.end()); 408 DCHECK(it != download_requests_.end());
408 download_requests_.erase(*it); 409 download_requests_.erase(*it);
409 } 410 }
410 411
411 } // namespace safe_browsing 412 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698