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

Side by Side Diff: chrome/browser/safe_browsing/download_protection_service.cc

Issue 8375039: Create a content::UrlFetcher interface that lives in content/public/common and convert users to i... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review comments Created 9 years, 2 months 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 this, enabled)); 49 this, enabled));
50 } 50 }
51 51
52 void DownloadProtectionService::SetEnabledOnIOThread(bool enabled) { 52 void DownloadProtectionService::SetEnabledOnIOThread(bool enabled) {
53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
54 if (enabled == enabled_) { 54 if (enabled == enabled_) {
55 return; 55 return;
56 } 56 }
57 enabled_ = enabled; 57 enabled_ = enabled;
58 if (!enabled_) { 58 if (!enabled_) {
59 for (std::map<const URLFetcher*, CheckDownloadCallback>::iterator it = 59 for (DownloadRequests::iterator it = download_requests_.begin();
60 download_requests_.begin();
61 it != download_requests_.end(); ++it) { 60 it != download_requests_.end(); ++it) {
62 it->second.Run(SAFE); 61 it->second.Run(SAFE);
63 } 62 }
64 STLDeleteContainerPairFirstPointers(download_requests_.begin(), 63 STLDeleteContainerPairFirstPointers(download_requests_.begin(),
65 download_requests_.end()); 64 download_requests_.end());
66 download_requests_.clear(); 65 download_requests_.clear();
67 } 66 }
68 } 67 }
69 68
70 void DownloadProtectionService::OnURLFetchComplete(const URLFetcher* source) { 69 void DownloadProtectionService::OnURLFetchComplete(
70 const content::URLFetcher* source) {
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
72 scoped_ptr<const URLFetcher> s(source); // will delete the URLFetcher object. 72 scoped_ptr<const content::URLFetcher> s(source);
73 if (download_requests_.find(source) != download_requests_.end()) { 73 if (download_requests_.find(source) != download_requests_.end()) {
74 CheckDownloadCallback callback = download_requests_[source]; 74 CheckDownloadCallback callback = download_requests_[source];
75 download_requests_.erase(source); 75 download_requests_.erase(source);
76 if (!enabled_) { 76 if (!enabled_) {
77 // SafeBrowsing got disabled. We can't do anything. Note: the request 77 // SafeBrowsing got disabled. We can't do anything. Note: the request
78 // object will be deleted. 78 // object will be deleted.
79 RecordStats(REASON_SB_DISABLED); 79 RecordStats(REASON_SB_DISABLED);
80 return; 80 return;
81 } 81 }
82 DownloadCheckResultReason reason = REASON_MAX; 82 DownloadCheckResultReason reason = REASON_MAX;
83 reason = REASON_SERVER_PING_FAILED; 83 reason = REASON_SERVER_PING_FAILED;
84 if (source->status().is_success() && 84 if (source->GetStatus().is_success() &&
85 RC_REQUEST_OK == source->response_code()) { 85 RC_REQUEST_OK == source->GetResponseCode()) {
86 std::string data; 86 std::string data;
87 source->GetResponseAsString(&data); 87 source->GetResponseAsString(&data);
88 if (data.size() > 0) { 88 if (data.size() > 0) {
89 // For now no matter what we'll always say the download is safe. 89 // For now no matter what we'll always say the download is safe.
90 // TODO(noelutz): Parse the response body to see exactly what's going 90 // TODO(noelutz): Parse the response body to see exactly what's going
91 // on. 91 // on.
92 reason = REASON_INVALID_RESPONSE_PROTO; 92 reason = REASON_INVALID_RESPONSE_PROTO;
93 } 93 }
94 } 94 }
95 BrowserThread::PostTask( 95 BrowserThread::PostTask(
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 base::Bind(&DownloadProtectionService::EndCheckClientDownload, 180 base::Bind(&DownloadProtectionService::EndCheckClientDownload,
181 this, SAFE, reason, callback)); 181 this, SAFE, reason, callback));
182 return; 182 return;
183 } 183 }
184 184
185 URLFetcher* fetcher = URLFetcher::Create(0 /* ID used for testing */, 185 URLFetcher* fetcher = URLFetcher::Create(0 /* ID used for testing */,
186 GURL(kDownloadRequestUrl), 186 GURL(kDownloadRequestUrl),
187 URLFetcher::POST, 187 URLFetcher::POST,
188 this); 188 this);
189 download_requests_[fetcher] = callback; 189 download_requests_[fetcher] = callback;
190 fetcher->set_load_flags(net::LOAD_DISABLE_CACHE); 190 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE);
191 fetcher->set_request_context(request_context_getter_.get()); 191 fetcher->SetRequestContext(request_context_getter_.get());
192 fetcher->set_upload_data("application/octet-stream", request_data); 192 fetcher->SetUploadData("application/octet-stream", request_data);
193 fetcher->Start(); 193 fetcher->Start();
194 } 194 }
195 195
196 void DownloadProtectionService::EndCheckClientDownload( 196 void DownloadProtectionService::EndCheckClientDownload(
197 DownloadCheckResult result, 197 DownloadCheckResult result,
198 DownloadCheckResultReason reason, 198 DownloadCheckResultReason reason,
199 const CheckDownloadCallback& callback) { 199 const CheckDownloadCallback& callback) {
200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
201 RecordStats(reason); 201 RecordStats(reason);
202 callback.Run(result); 202 callback.Run(result);
203 } 203 }
204 204
205 void DownloadProtectionService::RecordStats(DownloadCheckResultReason reason) { 205 void DownloadProtectionService::RecordStats(DownloadCheckResultReason reason) {
206 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", 206 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats",
207 reason, 207 reason,
208 REASON_MAX); 208 REASON_MAX);
209 } 209 }
210 } // namespace safe_browsing 210 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/download_protection_service.h ('k') | chrome/browser/safe_browsing/malware_details_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698