| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 namespace { | 50 namespace { |
| 51 static const int64 kDownloadRequestTimeoutMs = 7000; | 51 static const int64 kDownloadRequestTimeoutMs = 7000; |
| 52 } // namespace | 52 } // namespace |
| 53 | 53 |
| 54 namespace safe_browsing { | 54 namespace safe_browsing { |
| 55 | 55 |
| 56 const char DownloadProtectionService::kDownloadRequestUrl[] = | 56 const char DownloadProtectionService::kDownloadRequestUrl[] = |
| 57 "https://sb-ssl.google.com/safebrowsing/clientreport/download"; | 57 "https://sb-ssl.google.com/safebrowsing/clientreport/download"; |
| 58 | 58 |
| 59 namespace { | 59 namespace { |
| 60 ClientDownloadRequest::DownloadType GetDownloadType( | |
| 61 const base::FilePath& file) { | |
| 62 DCHECK(download_protection_util::IsBinaryFile(file)); | |
| 63 if (file.MatchesExtension(FILE_PATH_LITERAL(".apk"))) | |
| 64 return ClientDownloadRequest::ANDROID_APK; | |
| 65 else if (file.MatchesExtension(FILE_PATH_LITERAL(".crx"))) | |
| 66 return ClientDownloadRequest::CHROME_EXTENSION; | |
| 67 // For zip files, we use the ZIPPED_EXECUTABLE type since we will only send | |
| 68 // the pingback if we find an executable inside the zip archive. | |
| 69 else if (file.MatchesExtension(FILE_PATH_LITERAL(".zip"))) | |
| 70 return ClientDownloadRequest::ZIPPED_EXECUTABLE; | |
| 71 return ClientDownloadRequest::WIN_EXECUTABLE; | |
| 72 } | |
| 73 | |
| 74 // List of extensions for which we track some UMA stats. | 60 // List of extensions for which we track some UMA stats. |
| 75 enum MaliciousExtensionType { | 61 enum MaliciousExtensionType { |
| 76 EXTENSION_EXE, | 62 EXTENSION_EXE, |
| 77 EXTENSION_MSI, | 63 EXTENSION_MSI, |
| 78 EXTENSION_CAB, | 64 EXTENSION_CAB, |
| 79 EXTENSION_SYS, | 65 EXTENSION_SYS, |
| 80 EXTENSION_SCR, | 66 EXTENSION_SCR, |
| 81 EXTENSION_DRV, | 67 EXTENSION_DRV, |
| 82 EXTENSION_BAT, | 68 EXTENSION_BAT, |
| 83 EXTENSION_ZIP, | 69 EXTENSION_ZIP, |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 const GURL& final_url = item.GetUrlChain().back(); | 457 const GURL& final_url = item.GetUrlChain().back(); |
| 472 if (!final_url.is_valid() || final_url.is_empty() || | 458 if (!final_url.is_valid() || final_url.is_empty() || |
| 473 !final_url.IsStandard() || final_url.SchemeIsFile()) { | 459 !final_url.IsStandard() || final_url.SchemeIsFile()) { |
| 474 *reason = REASON_INVALID_URL; | 460 *reason = REASON_INVALID_URL; |
| 475 return false; | 461 return false; |
| 476 } | 462 } |
| 477 if (!download_protection_util::IsBinaryFile(target_path)) { | 463 if (!download_protection_util::IsBinaryFile(target_path)) { |
| 478 *reason = REASON_NOT_BINARY_FILE; | 464 *reason = REASON_NOT_BINARY_FILE; |
| 479 return false; | 465 return false; |
| 480 } | 466 } |
| 481 *type = GetDownloadType(target_path); | 467 *type = download_protection_util::GetDownloadType(target_path); |
| 482 return true; | 468 return true; |
| 483 } | 469 } |
| 484 | 470 |
| 485 private: | 471 private: |
| 486 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 472 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
| 487 friend class base::DeleteHelper<CheckClientDownloadRequest>; | 473 friend class base::DeleteHelper<CheckClientDownloadRequest>; |
| 488 | 474 |
| 489 virtual ~CheckClientDownloadRequest() { | 475 virtual ~CheckClientDownloadRequest() { |
| 490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 491 DCHECK(item_ == NULL); | 477 DCHECK(item_ == NULL); |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1060 GURL DownloadProtectionService::GetDownloadRequestUrl() { | 1046 GURL DownloadProtectionService::GetDownloadRequestUrl() { |
| 1061 GURL url(kDownloadRequestUrl); | 1047 GURL url(kDownloadRequestUrl); |
| 1062 std::string api_key = google_apis::GetAPIKey(); | 1048 std::string api_key = google_apis::GetAPIKey(); |
| 1063 if (!api_key.empty()) | 1049 if (!api_key.empty()) |
| 1064 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 1050 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
| 1065 | 1051 |
| 1066 return url; | 1052 return url; |
| 1067 } | 1053 } |
| 1068 | 1054 |
| 1069 } // namespace safe_browsing | 1055 } // namespace safe_browsing |
| OLD | NEW |