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

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

Issue 1979153002: Use FileTypePolicies for is_archive and is_supported classifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@split_by_platform
Patch Set: Fix comment, per asanka's review Created 4 years, 7 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
OLDNEW
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 25 matching lines...) Expand all
36 #include "chrome/browser/safe_browsing/download_feedback_service.h" 36 #include "chrome/browser/safe_browsing/download_feedback_service.h"
37 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 37 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
38 #include "chrome/browser/safe_browsing/sandboxed_zip_analyzer.h" 38 #include "chrome/browser/safe_browsing/sandboxed_zip_analyzer.h"
39 #include "chrome/browser/ui/browser.h" 39 #include "chrome/browser/ui/browser.h"
40 #include "chrome/browser/ui/browser_list.h" 40 #include "chrome/browser/ui/browser_list.h"
41 #include "chrome/common/chrome_switches.h" 41 #include "chrome/common/chrome_switches.h"
42 #include "chrome/common/pref_names.h" 42 #include "chrome/common/pref_names.h"
43 #include "chrome/common/safe_browsing/binary_feature_extractor.h" 43 #include "chrome/common/safe_browsing/binary_feature_extractor.h"
44 #include "chrome/common/safe_browsing/csd.pb.h" 44 #include "chrome/common/safe_browsing/csd.pb.h"
45 #include "chrome/common/safe_browsing/download_protection_util.h" 45 #include "chrome/common/safe_browsing/download_protection_util.h"
46 #include "chrome/common/safe_browsing/file_type_policies.h"
46 #include "chrome/common/safe_browsing/zip_analyzer_results.h" 47 #include "chrome/common/safe_browsing/zip_analyzer_results.h"
47 #include "chrome/common/url_constants.h" 48 #include "chrome/common/url_constants.h"
48 #include "components/google/core/browser/google_util.h" 49 #include "components/google/core/browser/google_util.h"
49 #include "components/history/core/browser/history_service.h" 50 #include "components/history/core/browser/history_service.h"
50 #include "components/prefs/pref_service.h" 51 #include "components/prefs/pref_service.h"
51 #include "content/public/browser/browser_thread.h" 52 #include "content/public/browser/browser_thread.h"
52 #include "content/public/browser/download_item.h" 53 #include "content/public/browser/download_item.h"
53 #include "content/public/browser/page_navigator.h" 54 #include "content/public/browser/page_navigator.h"
54 #include "crypto/sha2.h" 55 #include "crypto/sha2.h"
55 #include "google_apis/google_api_keys.h" 56 #include "google_apis/google_api_keys.h"
(...skipping 21 matching lines...) Expand all
77 78
78 namespace safe_browsing { 79 namespace safe_browsing {
79 80
80 const char DownloadProtectionService::kDownloadRequestUrl[] = 81 const char DownloadProtectionService::kDownloadRequestUrl[] =
81 "https://sb-ssl.google.com/safebrowsing/clientreport/download"; 82 "https://sb-ssl.google.com/safebrowsing/clientreport/download";
82 83
83 namespace { 84 namespace {
84 void RecordFileExtensionType(const base::FilePath& file) { 85 void RecordFileExtensionType(const base::FilePath& file) {
85 UMA_HISTOGRAM_SPARSE_SLOWLY( 86 UMA_HISTOGRAM_SPARSE_SLOWLY(
86 "SBClientDownload.DownloadExtensions", 87 "SBClientDownload.DownloadExtensions",
87 download_protection_util::GetSBClientDownloadExtensionValueForUMA(file)); 88 FileTypePolicies::GetInstance()->UmaValueForFile(file));
88 } 89 }
89 90
90 void RecordArchivedArchiveFileExtensionType(const base::FilePath& file_name) { 91 void RecordArchivedArchiveFileExtensionType(const base::FilePath& file) {
91 UMA_HISTOGRAM_SPARSE_SLOWLY( 92 UMA_HISTOGRAM_SPARSE_SLOWLY(
92 "SBClientDownload.ArchivedArchiveExtensions", 93 "SBClientDownload.ArchivedArchiveExtensions",
93 download_protection_util::GetSBClientDownloadExtensionValueForUMA( 94 FileTypePolicies::GetInstance()->UmaValueForFile(file));
94 file_name));
95 } 95 }
96 96
97 // Enumerate for histogramming purposes. 97 // Enumerate for histogramming purposes.
98 // DO NOT CHANGE THE ORDERING OF THESE VALUES (different histogram data will 98 // DO NOT CHANGE THE ORDERING OF THESE VALUES (different histogram data will
99 // be mixed together based on their values). 99 // be mixed together based on their values).
100 enum SBStatsType { 100 enum SBStatsType {
101 DOWNLOAD_URL_CHECKS_TOTAL, 101 DOWNLOAD_URL_CHECKS_TOTAL,
102 DOWNLOAD_URL_CHECKS_CANCELED, 102 DOWNLOAD_URL_CHECKS_CANCELED,
103 DOWNLOAD_URL_CHECKS_MALWARE, 103 DOWNLOAD_URL_CHECKS_MALWARE,
104 104
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 ClientDownloadRequest::DownloadType* type) { 509 ClientDownloadRequest::DownloadType* type) {
510 if (item.GetUrlChain().empty()) { 510 if (item.GetUrlChain().empty()) {
511 *reason = REASON_EMPTY_URL_CHAIN; 511 *reason = REASON_EMPTY_URL_CHAIN;
512 return false; 512 return false;
513 } 513 }
514 const GURL& final_url = item.GetUrlChain().back(); 514 const GURL& final_url = item.GetUrlChain().back();
515 if (!final_url.is_valid() || final_url.is_empty()) { 515 if (!final_url.is_valid() || final_url.is_empty()) {
516 *reason = REASON_INVALID_URL; 516 *reason = REASON_INVALID_URL;
517 return false; 517 return false;
518 } 518 }
519 if (!download_protection_util::IsSupportedBinaryFile(target_path)) { 519 if (!FileTypePolicies::GetInstance()->IsCheckedBinaryFile(target_path)) {
520 *reason = REASON_NOT_BINARY_FILE; 520 *reason = REASON_NOT_BINARY_FILE;
521 return false; 521 return false;
522 } 522 }
523 if ((!final_url.IsStandard() && !final_url.SchemeIsBlob() && 523 if ((!final_url.IsStandard() && !final_url.SchemeIsBlob() &&
524 !final_url.SchemeIs(url::kDataScheme)) || 524 !final_url.SchemeIs(url::kDataScheme)) ||
525 final_url.SchemeIsFile()) { 525 final_url.SchemeIsFile()) {
526 *reason = REASON_UNSUPPORTED_URL_SCHEME; 526 *reason = REASON_UNSUPPORTED_URL_SCHEME;
527 return false; 527 return false;
528 } 528 }
529 *type = download_protection_util::GetDownloadType(target_path); 529 *type = download_protection_util::GetDownloadType(target_path);
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 692
693 // Even if !results.success, some of the DMG may have been parsed. 693 // Even if !results.success, some of the DMG may have been parsed.
694 archive_is_valid_ = 694 archive_is_valid_ =
695 (results.success ? ArchiveValid::VALID : ArchiveValid::INVALID); 695 (results.success ? ArchiveValid::VALID : ArchiveValid::INVALID);
696 archived_executable_ = results.has_executable; 696 archived_executable_ = results.has_executable;
697 archived_binary_.CopyFrom(results.archived_binary); 697 archived_binary_.CopyFrom(results.archived_binary);
698 DVLOG(1) << "DMG analysis has finished for " << item_->GetFullPath().value() 698 DVLOG(1) << "DMG analysis has finished for " << item_->GetFullPath().value()
699 << ", has_executable=" << results.has_executable 699 << ", has_executable=" << results.has_executable
700 << ", success=" << results.success; 700 << ", success=" << results.success;
701 701
702 int uma_file_type = 702 int64_t uma_file_type = FileTypePolicies::GetInstance()->UmaValueForFile(
703 download_protection_util::GetSBClientDownloadExtensionValueForUMA( 703 item_->GetTargetFilePath());
704 item_->GetTargetFilePath());
705 704
706 if (results.success) { 705 if (results.success) {
707 UMA_HISTOGRAM_SPARSE_SLOWLY("SBClientDownload.DmgFileSuccessByType", 706 UMA_HISTOGRAM_SPARSE_SLOWLY("SBClientDownload.DmgFileSuccessByType",
708 uma_file_type); 707 uma_file_type);
709 } else { 708 } else {
710 UMA_HISTOGRAM_SPARSE_SLOWLY("SBClientDownload.DmgFileFailureByType", 709 UMA_HISTOGRAM_SPARSE_SLOWLY("SBClientDownload.DmgFileFailureByType",
711 uma_file_type); 710 uma_file_type);
712 } 711 }
713 712
714 if (archived_executable_) { 713 if (archived_executable_) {
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 GURL DownloadProtectionService::GetDownloadRequestUrl() { 1334 GURL DownloadProtectionService::GetDownloadRequestUrl() {
1336 GURL url(kDownloadRequestUrl); 1335 GURL url(kDownloadRequestUrl);
1337 std::string api_key = google_apis::GetAPIKey(); 1336 std::string api_key = google_apis::GetAPIKey();
1338 if (!api_key.empty()) 1337 if (!api_key.empty())
1339 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); 1338 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true));
1340 1339
1341 return url; 1340 return url;
1342 } 1341 }
1343 1342
1344 } // namespace safe_browsing 1343 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698