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

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

Issue 2926473002: Mac Archive Type Sniffing (Closed)
Patch Set: avoiding multiple asynchronous calls in tester for mac Created 3 years, 5 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 #include "net/base/url_util.h" 67 #include "net/base/url_util.h"
68 #include "net/cert/x509_cert_types.h" 68 #include "net/cert/x509_cert_types.h"
69 #include "net/cert/x509_certificate.h" 69 #include "net/cert/x509_certificate.h"
70 #include "net/http/http_status_code.h" 70 #include "net/http/http_status_code.h"
71 #include "net/traffic_annotation/network_traffic_annotation.h" 71 #include "net/traffic_annotation/network_traffic_annotation.h"
72 #include "net/url_request/url_fetcher.h" 72 #include "net/url_request/url_fetcher.h"
73 #include "net/url_request/url_fetcher_delegate.h" 73 #include "net/url_request/url_fetcher_delegate.h"
74 #include "net/url_request/url_request_status.h" 74 #include "net/url_request/url_request_status.h"
75 75
76 #if defined(OS_MACOSX) 76 #if defined(OS_MACOSX)
77 #include "chrome/browser/safe_browsing/disk_image_type_sniffer_mac.h"
77 #include "chrome/browser/safe_browsing/sandboxed_dmg_analyzer_mac.h" 78 #include "chrome/browser/safe_browsing/sandboxed_dmg_analyzer_mac.h"
78 #endif 79 #endif
79 80
80 using content::BrowserThread; 81 using content::BrowserThread;
81 namespace safe_browsing { 82 namespace safe_browsing {
82 83
83 namespace { 84 namespace {
84 85
85 const int64_t kDownloadRequestTimeoutMs = 7000; 86 const int64_t kDownloadRequestTimeoutMs = 7000;
86 // We sample 1% of whitelisted downloads to still send out download pings. 87 // We sample 1% of whitelisted downloads to still send out download pings.
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 FILE_PATH_LITERAL(".sparsebundle")) || 462 FILE_PATH_LITERAL(".sparsebundle")) ||
462 item_->GetTargetFilePath().MatchesExtension( 463 item_->GetTargetFilePath().MatchesExtension(
463 FILE_PATH_LITERAL(".sparseimage")) || 464 FILE_PATH_LITERAL(".sparseimage")) ||
464 item_->GetTargetFilePath().MatchesExtension( 465 item_->GetTargetFilePath().MatchesExtension(
465 FILE_PATH_LITERAL(".toast")) || 466 FILE_PATH_LITERAL(".toast")) ||
466 item_->GetTargetFilePath().MatchesExtension( 467 item_->GetTargetFilePath().MatchesExtension(
467 FILE_PATH_LITERAL(".udif"))) { 468 FILE_PATH_LITERAL(".udif"))) {
468 StartExtractDmgFeatures(); 469 StartExtractDmgFeatures();
469 #endif 470 #endif
470 } else { 471 } else {
472 #if defined(OS_MACOSX)
473 // Checks for existence of "koly" signature even if file doesn't have
474 // archive-type extension, then calls ExtractFileOrDmgFeatures() with
475 // result.
476 BrowserThread::PostTaskAndReplyWithResult(
477 BrowserThread::FILE, FROM_HERE,
478 base::Bind(DiskImageTypeSnifferMac::IsAppleDiskImage,
479 item_->GetTargetFilePath()),
480 base::Bind(&CheckClientDownloadRequest::ExtractFileOrDmgFeatures,
481 this));
482 #else
471 StartExtractFileFeatures(); 483 StartExtractFileFeatures();
484 #endif
472 } 485 }
473 } 486 }
474 487
475 // Start a timeout to cancel the request if it takes too long. 488 // Start a timeout to cancel the request if it takes too long.
476 // This should only be called after we have finished accessing the file. 489 // This should only be called after we have finished accessing the file.
477 void StartTimeout() { 490 void StartTimeout() {
478 DCHECK_CURRENTLY_ON(BrowserThread::UI); 491 DCHECK_CURRENTLY_ON(BrowserThread::UI);
479 if (!service_) { 492 if (!service_) {
480 // Request has already been cancelled. 493 // Request has already been cancelled.
481 return; 494 return;
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 DCHECK_CURRENTLY_ON(BrowserThread::UI); 782 DCHECK_CURRENTLY_ON(BrowserThread::UI);
770 DCHECK(item_); 783 DCHECK(item_);
771 dmg_analyzer_ = new SandboxedDMGAnalyzer( 784 dmg_analyzer_ = new SandboxedDMGAnalyzer(
772 item_->GetFullPath(), 785 item_->GetFullPath(),
773 base::Bind(&CheckClientDownloadRequest::OnDmgAnalysisFinished, 786 base::Bind(&CheckClientDownloadRequest::OnDmgAnalysisFinished,
774 weakptr_factory_.GetWeakPtr())); 787 weakptr_factory_.GetWeakPtr()));
775 dmg_analyzer_->Start(); 788 dmg_analyzer_->Start();
776 dmg_analysis_start_time_ = base::TimeTicks::Now(); 789 dmg_analysis_start_time_ = base::TimeTicks::Now();
777 } 790 }
778 791
792 // Extracts DMG features if file has 'koly' signature, otherwise extracts
793 // regular file features.
794 void ExtractFileOrDmgFeatures(bool download_file_has_koly_signature) {
795 DCHECK_CURRENTLY_ON(BrowserThread::UI);
796 UMA_HISTOGRAM_BOOLEAN(
797 "SBClientDownload."
798 "DownloadFileWithoutDiskImageExtensionHasKolySignature",
799 download_file_has_koly_signature);
800 // Returns if DownloadItem was destroyed during parsing of file metadata.
801 if (item_ == nullptr)
802 return;
803 if (download_file_has_koly_signature)
804 StartExtractDmgFeatures();
805 else
806 StartExtractFileFeatures();
807 }
808
779 void OnDmgAnalysisFinished(const ArchiveAnalyzerResults& results) { 809 void OnDmgAnalysisFinished(const ArchiveAnalyzerResults& results) {
780 DCHECK_CURRENTLY_ON(BrowserThread::UI); 810 DCHECK_CURRENTLY_ON(BrowserThread::UI);
781 DCHECK_EQ(ClientDownloadRequest::MAC_EXECUTABLE, type_); 811 DCHECK_EQ(ClientDownloadRequest::MAC_EXECUTABLE, type_);
782 if (!service_) 812 if (!service_)
783 return; 813 return;
784 814
785 // Even if !results.success, some of the DMG may have been parsed. 815 // Even if !results.success, some of the DMG may have been parsed.
786 archive_is_valid_ = 816 archive_is_valid_ =
787 (results.success ? ArchiveValid::VALID : ArchiveValid::INVALID); 817 (results.success ? ArchiveValid::VALID : ArchiveValid::INVALID);
788 archived_executable_ = results.has_executable; 818 archived_executable_ = results.has_executable;
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1982 out_request->mutable_referrer_chain()); 2012 out_request->mutable_referrer_chain());
1983 UMA_HISTOGRAM_COUNTS_100( 2013 UMA_HISTOGRAM_COUNTS_100(
1984 "SafeBrowsing.ReferrerURLChainSize.PPAPIDownloadAttribution", 2014 "SafeBrowsing.ReferrerURLChainSize.PPAPIDownloadAttribution",
1985 out_request->referrer_chain_size()); 2015 out_request->referrer_chain_size());
1986 UMA_HISTOGRAM_ENUMERATION( 2016 UMA_HISTOGRAM_ENUMERATION(
1987 "SafeBrowsing.ReferrerAttributionResult.PPAPIDownloadAttribution", result, 2017 "SafeBrowsing.ReferrerAttributionResult.PPAPIDownloadAttribution", result,
1988 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); 2018 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX);
1989 } 2019 }
1990 2020
1991 } // namespace safe_browsing 2021 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698