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

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

Issue 15881012: Implement safebrowsing download feedback service, enabled for dev & canary only. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 6 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) 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"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/sequenced_task_runner_helpers.h" 13 #include "base/sequenced_task_runner_helpers.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
18 #include "base/threading/sequenced_worker_pool.h" 18 #include "base/threading/sequenced_worker_pool.h"
19 #include "base/time.h" 19 #include "base/time.h"
20 #include "chrome/browser/safe_browsing/download_feedback_service.h"
20 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 21 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
21 #include "chrome/browser/safe_browsing/sandboxed_zip_analyzer.h" 22 #include "chrome/browser/safe_browsing/sandboxed_zip_analyzer.h"
22 #include "chrome/browser/safe_browsing/signature_util.h" 23 #include "chrome/browser/safe_browsing/signature_util.h"
23 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_list.h" 25 #include "chrome/browser/ui/browser_list.h"
25 #include "chrome/common/safe_browsing/csd.pb.h" 26 #include "chrome/common/safe_browsing/csd.pb.h"
26 #include "chrome/common/safe_browsing/download_protection_util.h" 27 #include "chrome/common/safe_browsing/download_protection_util.h"
27 #include "chrome/common/safe_browsing/zip_analyzer.h" 28 #include "chrome/common/safe_browsing/zip_analyzer.h"
28 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
29 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 reason = REASON_DOWNLOAD_UNCOMMON; 415 reason = REASON_DOWNLOAD_UNCOMMON;
415 result = UNCOMMON; 416 result = UNCOMMON;
416 } else if (response.verdict() == ClientDownloadResponse::DANGEROUS_HOST) { 417 } else if (response.verdict() == ClientDownloadResponse::DANGEROUS_HOST) {
417 reason = REASON_DOWNLOAD_DANGEROUS_HOST; 418 reason = REASON_DOWNLOAD_DANGEROUS_HOST;
418 result = DANGEROUS_HOST; 419 result = DANGEROUS_HOST;
419 } else { 420 } else {
420 LOG(DFATAL) << "Unknown download response verdict: " 421 LOG(DFATAL) << "Unknown download response verdict: "
421 << response.verdict(); 422 << response.verdict();
422 reason = REASON_INVALID_RESPONSE_VERDICT; 423 reason = REASON_INVALID_RESPONSE_VERDICT;
423 } 424 }
425 DownloadFeedbackService::MaybeStorePingsForDownload(
426 result, item_, client_download_request_data_, data);
424 } 427 }
425 // We don't need the fetcher anymore. 428 // We don't need the fetcher anymore.
426 fetcher_.reset(); 429 fetcher_.reset();
427 UMA_HISTOGRAM_TIMES("SBClientDownload.DownloadRequestDuration", 430 UMA_HISTOGRAM_TIMES("SBClientDownload.DownloadRequestDuration",
428 base::TimeTicks::Now() - start_time_); 431 base::TimeTicks::Now() - start_time_);
429 FinishRequest(result, reason); 432 FinishRequest(result, reason);
430 } 433 }
431 434
432 static bool IsSupportedDownload(const content::DownloadItem& item, 435 static bool IsSupportedDownload(const content::DownloadItem& item,
433 const base::FilePath& target_path, 436 const base::FilePath& target_path,
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 } else { 632 } else {
630 resource->set_type(ClientDownloadRequest::DOWNLOAD_REDIRECT); 633 resource->set_type(ClientDownloadRequest::DOWNLOAD_REDIRECT);
631 } 634 }
632 // TODO(noelutz): fill out the remote IP addresses. 635 // TODO(noelutz): fill out the remote IP addresses.
633 } 636 }
634 request.set_user_initiated(item_->HasUserGesture()); 637 request.set_user_initiated(item_->HasUserGesture());
635 request.set_file_basename( 638 request.set_file_basename(
636 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe()); 639 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe());
637 request.set_download_type(type_); 640 request.set_download_type(type_);
638 request.mutable_signature()->CopyFrom(signature_info_); 641 request.mutable_signature()->CopyFrom(signature_info_);
639 std::string request_data; 642 if (!request.SerializeToString(&client_download_request_data_)) {
640 if (!request.SerializeToString(&request_data)) {
641 FinishRequest(SAFE, REASON_INVALID_REQUEST_PROTO); 643 FinishRequest(SAFE, REASON_INVALID_REQUEST_PROTO);
642 return; 644 return;
643 } 645 }
644 646
645 VLOG(2) << "Sending a request for URL: " 647 VLOG(2) << "Sending a request for URL: "
646 << item_->GetUrlChain().back(); 648 << item_->GetUrlChain().back();
647 fetcher_.reset(net::URLFetcher::Create(0 /* ID used for testing */, 649 fetcher_.reset(net::URLFetcher::Create(0 /* ID used for testing */,
648 GURL(GetDownloadRequestUrl()), 650 GURL(GetDownloadRequestUrl()),
649 net::URLFetcher::POST, 651 net::URLFetcher::POST,
650 this)); 652 this));
651 fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE); 653 fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE);
652 fetcher_->SetAutomaticallyRetryOn5xx(false); // Don't retry on error. 654 fetcher_->SetAutomaticallyRetryOn5xx(false); // Don't retry on error.
653 fetcher_->SetRequestContext(service_->request_context_getter_.get()); 655 fetcher_->SetRequestContext(service_->request_context_getter_.get());
654 fetcher_->SetUploadData("application/octet-stream", request_data); 656 fetcher_->SetUploadData("application/octet-stream",
657 client_download_request_data_);
655 fetcher_->Start(); 658 fetcher_->Start();
656 } 659 }
657 660
658 void PostFinishTask(DownloadCheckResult result, 661 void PostFinishTask(DownloadCheckResult result,
659 DownloadCheckResultReason reason) { 662 DownloadCheckResultReason reason) {
660 BrowserThread::PostTask( 663 BrowserThread::PostTask(
661 BrowserThread::UI, 664 BrowserThread::UI,
662 FROM_HERE, 665 FROM_HERE,
663 base::Bind(&CheckClientDownloadRequest::FinishRequest, this, result, 666 base::Bind(&CheckClientDownloadRequest::FinishRequest, this, result,
664 reason)); 667 reason));
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 // Will be NULL if the request has been canceled. 750 // Will be NULL if the request has been canceled.
748 DownloadProtectionService* service_; 751 DownloadProtectionService* service_;
749 scoped_refptr<SignatureUtil> signature_util_; 752 scoped_refptr<SignatureUtil> signature_util_;
750 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; 753 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_;
751 const bool pingback_enabled_; 754 const bool pingback_enabled_;
752 scoped_ptr<net::URLFetcher> fetcher_; 755 scoped_ptr<net::URLFetcher> fetcher_;
753 scoped_refptr<SandboxedZipAnalyzer> analyzer_; 756 scoped_refptr<SandboxedZipAnalyzer> analyzer_;
754 base::TimeTicks zip_analysis_start_time_; 757 base::TimeTicks zip_analysis_start_time_;
755 bool finished_; 758 bool finished_;
756 ClientDownloadRequest::DownloadType type_; 759 ClientDownloadRequest::DownloadType type_;
760 std::string client_download_request_data_;
757 base::WeakPtrFactory<CheckClientDownloadRequest> weakptr_factory_; 761 base::WeakPtrFactory<CheckClientDownloadRequest> weakptr_factory_;
758 base::TimeTicks start_time_; // Used for stats. 762 base::TimeTicks start_time_; // Used for stats.
759 763
760 DISALLOW_COPY_AND_ASSIGN(CheckClientDownloadRequest); 764 DISALLOW_COPY_AND_ASSIGN(CheckClientDownloadRequest);
761 }; 765 };
762 766
763 DownloadProtectionService::DownloadProtectionService( 767 DownloadProtectionService::DownloadProtectionService(
764 SafeBrowsingService* sb_service, 768 SafeBrowsingService* sb_service,
765 net::URLRequestContextGetter* request_context_getter) 769 net::URLRequestContextGetter* request_context_getter)
766 : request_context_getter_(request_context_getter), 770 : request_context_getter_(request_context_getter),
767 enabled_(false), 771 enabled_(false),
768 signature_util_(new SignatureUtil()), 772 signature_util_(new SignatureUtil()),
769 download_request_timeout_ms_(kDownloadRequestTimeoutMs) { 773 download_request_timeout_ms_(kDownloadRequestTimeoutMs),
774 feedback_service_(new DownloadFeedbackService(
775 request_context_getter, BrowserThread::GetBlockingPool())) {
770 776
771 if (sb_service) { 777 if (sb_service) {
772 ui_manager_ = sb_service->ui_manager(); 778 ui_manager_ = sb_service->ui_manager();
773 database_manager_ = sb_service->database_manager(); 779 database_manager_ = sb_service->database_manager();
774 } 780 }
775 } 781 }
776 782
777 DownloadProtectionService::~DownloadProtectionService() { 783 DownloadProtectionService::~DownloadProtectionService() {
778 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 784 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
779 CancelPendingRequests(); 785 CancelPendingRequests();
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 std::string url = kDownloadRequestUrl; 952 std::string url = kDownloadRequestUrl;
947 std::string api_key = google_apis::GetAPIKey(); 953 std::string api_key = google_apis::GetAPIKey();
948 if (!api_key.empty()) { 954 if (!api_key.empty()) {
949 base::StringAppendF(&url, "?key=%s", 955 base::StringAppendF(&url, "?key=%s",
950 net::EscapeQueryParamValue(api_key, true).c_str()); 956 net::EscapeQueryParamValue(api_key, true).c_str());
951 } 957 }
952 return url; 958 return url;
953 } 959 }
954 960
955 } // namespace safe_browsing 961 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698