| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1288 bool url_was_whitelisted = | 1288 bool url_was_whitelisted = |
| 1289 requestor_url.is_valid() && database_manager && | 1289 requestor_url.is_valid() && database_manager && |
| 1290 database_manager->MatchDownloadWhitelistUrl(requestor_url); | 1290 database_manager->MatchDownloadWhitelistUrl(requestor_url); |
| 1291 BrowserThread::PostTask( | 1291 BrowserThread::PostTask( |
| 1292 BrowserThread::UI, FROM_HERE, | 1292 BrowserThread::UI, FROM_HERE, |
| 1293 base::Bind(&PPAPIDownloadRequest::WhitelistCheckComplete, | 1293 base::Bind(&PPAPIDownloadRequest::WhitelistCheckComplete, |
| 1294 download_request, url_was_whitelisted)); | 1294 download_request, url_was_whitelisted)); |
| 1295 } | 1295 } |
| 1296 | 1296 |
| 1297 void WhitelistCheckComplete(bool was_on_whitelist) { | 1297 void WhitelistCheckComplete(bool was_on_whitelist) { |
| 1298 DVLOG(2) << __FUNCTION__ << " was_on_whitelist:" << was_on_whitelist; | 1298 DVLOG(2) << __func__ << " was_on_whitelist:" << was_on_whitelist; |
| 1299 if (was_on_whitelist) { | 1299 if (was_on_whitelist) { |
| 1300 RecordCountOfWhitelistedDownload(URL_WHITELIST); | 1300 RecordCountOfWhitelistedDownload(URL_WHITELIST); |
| 1301 if (!ShouldSampleWhitelistedDownload()) { | 1301 if (!ShouldSampleWhitelistedDownload()) { |
| 1302 Finish(RequestOutcome::WHITELIST_HIT, SAFE); | 1302 Finish(RequestOutcome::WHITELIST_HIT, SAFE); |
| 1303 return; | 1303 return; |
| 1304 } | 1304 } |
| 1305 sample_url_whitelist_ = true; | 1305 sample_url_whitelist_ = true; |
| 1306 } else { | 1306 } else { |
| 1307 RecordCountOfWhitelistedDownload(NO_WHITELIST_MATCH); | 1307 RecordCountOfWhitelistedDownload(NO_WHITELIST_MATCH); |
| 1308 } | 1308 } |
| 1309 | 1309 |
| 1310 // Not on whitelist, so we are going to check with the SafeBrowsing | 1310 // Not on whitelist, so we are going to check with the SafeBrowsing |
| 1311 // backend. | 1311 // backend. |
| 1312 SendRequest(); | 1312 SendRequest(); |
| 1313 } | 1313 } |
| 1314 | 1314 |
| 1315 void SendRequest() { | 1315 void SendRequest() { |
| 1316 DVLOG(2) << __FUNCTION__; | 1316 DVLOG(2) << __func__; |
| 1317 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1317 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1318 | 1318 |
| 1319 ClientDownloadRequest request; | 1319 ClientDownloadRequest request; |
| 1320 request.set_download_type(ClientDownloadRequest::PPAPI_SAVE_REQUEST); | 1320 request.set_download_type(ClientDownloadRequest::PPAPI_SAVE_REQUEST); |
| 1321 ClientDownloadRequest::Resource* resource = request.add_resources(); | 1321 ClientDownloadRequest::Resource* resource = request.add_resources(); |
| 1322 resource->set_type(ClientDownloadRequest::PPAPI_DOCUMENT); | 1322 resource->set_type(ClientDownloadRequest::PPAPI_DOCUMENT); |
| 1323 resource->set_url(requestor_url_.spec()); | 1323 resource->set_url(requestor_url_.spec()); |
| 1324 request.set_url(requestor_url_.spec()); | 1324 request.set_url(requestor_url_.spec()); |
| 1325 request.set_file_basename(supported_path_.BaseName().AsUTF8Unsafe()); | 1325 request.set_file_basename(supported_path_.BaseName().AsUTF8Unsafe()); |
| 1326 request.set_length(0); | 1326 request.set_length(0); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1377 if (response.ParseFromString(response_body)) { | 1377 if (response.ParseFromString(response_body)) { |
| 1378 Finish(RequestOutcome::SUCCEEDED, | 1378 Finish(RequestOutcome::SUCCEEDED, |
| 1379 DownloadCheckResultFromClientDownloadResponse(response.verdict())); | 1379 DownloadCheckResultFromClientDownloadResponse(response.verdict())); |
| 1380 } else { | 1380 } else { |
| 1381 Finish(RequestOutcome::RESPONSE_MALFORMED, UNKNOWN); | 1381 Finish(RequestOutcome::RESPONSE_MALFORMED, UNKNOWN); |
| 1382 } | 1382 } |
| 1383 } | 1383 } |
| 1384 | 1384 |
| 1385 void OnRequestTimedOut() { | 1385 void OnRequestTimedOut() { |
| 1386 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1386 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1387 DVLOG(2) << __FUNCTION__; | 1387 DVLOG(2) << __func__; |
| 1388 Finish(RequestOutcome::TIMEDOUT, UNKNOWN); | 1388 Finish(RequestOutcome::TIMEDOUT, UNKNOWN); |
| 1389 } | 1389 } |
| 1390 | 1390 |
| 1391 void Finish(RequestOutcome reason, DownloadCheckResult response) { | 1391 void Finish(RequestOutcome reason, DownloadCheckResult response) { |
| 1392 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1392 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1393 DVLOG(2) << __FUNCTION__ << " response: " << response; | 1393 DVLOG(2) << __func__ << " response: " << response; |
| 1394 UMA_HISTOGRAM_SPARSE_SLOWLY( | 1394 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 1395 "SBClientDownload.base::RunLoop()DownloadRequest.RequestOutcome", | 1395 "SBClientDownload.base::RunLoop()DownloadRequest.RequestOutcome", |
| 1396 static_cast<int>(reason)); | 1396 static_cast<int>(reason)); |
| 1397 UMA_HISTOGRAM_SPARSE_SLOWLY( | 1397 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 1398 "SBClientDownload.base::RunLoop()DownloadRequest.Result", response); | 1398 "SBClientDownload.base::RunLoop()DownloadRequest.Result", response); |
| 1399 UMA_HISTOGRAM_TIMES( | 1399 UMA_HISTOGRAM_TIMES( |
| 1400 "SBClientDownload.base::RunLoop()DownloadRequest.RequestDuration", | 1400 "SBClientDownload.base::RunLoop()DownloadRequest.RequestDuration", |
| 1401 start_time_ - base::TimeTicks::Now()); | 1401 start_time_ - base::TimeTicks::Now()); |
| 1402 if (!callback_.is_null()) | 1402 if (!callback_.is_null()) |
| 1403 base::ResetAndReturn(&callback_).Run(response); | 1403 base::ResetAndReturn(&callback_).Run(response); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1589 item, target_path, &reason, &type) && | 1589 item, target_path, &reason, &type) && |
| 1590 (ClientDownloadRequest::CHROME_EXTENSION != type)); | 1590 (ClientDownloadRequest::CHROME_EXTENSION != type)); |
| 1591 } | 1591 } |
| 1592 | 1592 |
| 1593 void DownloadProtectionService::CheckPPAPIDownloadRequest( | 1593 void DownloadProtectionService::CheckPPAPIDownloadRequest( |
| 1594 const GURL& requestor_url, | 1594 const GURL& requestor_url, |
| 1595 const base::FilePath& default_file_path, | 1595 const base::FilePath& default_file_path, |
| 1596 const std::vector<base::FilePath::StringType>& alternate_extensions, | 1596 const std::vector<base::FilePath::StringType>& alternate_extensions, |
| 1597 Profile* profile, | 1597 Profile* profile, |
| 1598 const CheckDownloadCallback& callback) { | 1598 const CheckDownloadCallback& callback) { |
| 1599 DVLOG(1) << __FUNCTION__ << " url:" << requestor_url | 1599 DVLOG(1) << __func__ << " url:" << requestor_url |
| 1600 << " default_file_path:" << default_file_path.value(); | 1600 << " default_file_path:" << default_file_path.value(); |
| 1601 std::unique_ptr<PPAPIDownloadRequest> request(new PPAPIDownloadRequest( | 1601 std::unique_ptr<PPAPIDownloadRequest> request(new PPAPIDownloadRequest( |
| 1602 requestor_url, default_file_path, alternate_extensions, profile, callback, | 1602 requestor_url, default_file_path, alternate_extensions, profile, callback, |
| 1603 this, database_manager_)); | 1603 this, database_manager_)); |
| 1604 PPAPIDownloadRequest* request_copy = request.get(); | 1604 PPAPIDownloadRequest* request_copy = request.get(); |
| 1605 auto insertion_result = ppapi_download_requests_.insert( | 1605 auto insertion_result = ppapi_download_requests_.insert( |
| 1606 std::make_pair(request_copy, std::move(request))); | 1606 std::make_pair(request_copy, std::move(request))); |
| 1607 DCHECK(insertion_result.second); | 1607 DCHECK(insertion_result.second); |
| 1608 insertion_result.first->second->Start(); | 1608 insertion_result.first->second->Start(); |
| 1609 } | 1609 } |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1759 GURL DownloadProtectionService::GetDownloadRequestUrl() { | 1759 GURL DownloadProtectionService::GetDownloadRequestUrl() { |
| 1760 GURL url(kDownloadRequestUrl); | 1760 GURL url(kDownloadRequestUrl); |
| 1761 std::string api_key = google_apis::GetAPIKey(); | 1761 std::string api_key = google_apis::GetAPIKey(); |
| 1762 if (!api_key.empty()) | 1762 if (!api_key.empty()) |
| 1763 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 1763 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
| 1764 | 1764 |
| 1765 return url; | 1765 return url; |
| 1766 } | 1766 } |
| 1767 | 1767 |
| 1768 } // namespace safe_browsing | 1768 } // namespace safe_browsing |
| OLD | NEW |