| 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" |
| 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/metrics/sparse_histogram.h" | 13 #include "base/metrics/sparse_histogram.h" |
| 14 #include "base/sequenced_task_runner_helpers.h" | 14 #include "base/sequenced_task_runner_helpers.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/task/cancelable_task_tracker.h" |
| 19 #include "base/threading/sequenced_worker_pool.h" | 20 #include "base/threading/sequenced_worker_pool.h" |
| 20 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 21 #include "chrome/browser/history/history_service.h" | 22 #include "chrome/browser/history/history_service.h" |
| 22 #include "chrome/browser/history/history_service_factory.h" | 23 #include "chrome/browser/history/history_service_factory.h" |
| 23 #include "chrome/browser/safe_browsing/binary_feature_extractor.h" | 24 #include "chrome/browser/safe_browsing/binary_feature_extractor.h" |
| 24 #include "chrome/browser/safe_browsing/download_feedback_service.h" | 25 #include "chrome/browser/safe_browsing/download_feedback_service.h" |
| 25 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 26 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 26 #include "chrome/browser/safe_browsing/sandboxed_zip_analyzer.h" | 27 #include "chrome/browser/safe_browsing/sandboxed_zip_analyzer.h" |
| 27 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
| 28 #include "chrome/browser/ui/browser_list.h" | 29 #include "chrome/browser/ui/browser_list.h" |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 Profile* profile = Profile::FromBrowserContext(item_->GetBrowserContext()); | 639 Profile* profile = Profile::FromBrowserContext(item_->GetBrowserContext()); |
| 639 HistoryService* history = | 640 HistoryService* history = |
| 640 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); | 641 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); |
| 641 if (!history) { | 642 if (!history) { |
| 642 SendRequest(); | 643 SendRequest(); |
| 643 return; | 644 return; |
| 644 } | 645 } |
| 645 | 646 |
| 646 history->QueryRedirectsTo( | 647 history->QueryRedirectsTo( |
| 647 tab_url_, | 648 tab_url_, |
| 648 &request_consumer_, | |
| 649 base::Bind(&CheckClientDownloadRequest::OnGotTabRedirects, | 649 base::Bind(&CheckClientDownloadRequest::OnGotTabRedirects, |
| 650 base::Unretained(this))); | 650 base::Unretained(this), |
| 651 tab_url_), |
| 652 &request_tracker_); |
| 651 } | 653 } |
| 652 | 654 |
| 653 void OnGotTabRedirects(HistoryService::Handle handle, | 655 void OnGotTabRedirects(const GURL& url, |
| 654 GURL url, | 656 const history::RedirectList* redirect_list) { |
| 655 bool success, | |
| 656 history::RedirectList* redirect_list) { | |
| 657 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 657 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 658 DCHECK_EQ(url, tab_url_); | 658 DCHECK_EQ(url, tab_url_); |
| 659 | 659 |
| 660 if (success && redirect_list->size() > 0) { | 660 if (!redirect_list->empty()) { |
| 661 for (history::RedirectList::reverse_iterator i = redirect_list->rbegin(); | 661 tab_redirects_.insert( |
| 662 i != redirect_list->rend(); | 662 tab_redirects_.end(), redirect_list->rbegin(), redirect_list->rend()); |
| 663 ++i) { | |
| 664 tab_redirects_.push_back(*i); | |
| 665 } | |
| 666 } | 663 } |
| 667 | 664 |
| 668 SendRequest(); | 665 SendRequest(); |
| 669 } | 666 } |
| 670 | 667 |
| 671 void SendRequest() { | 668 void SendRequest() { |
| 672 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 669 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 673 | 670 |
| 674 // This is our last chance to check whether the request has been canceled | 671 // This is our last chance to check whether the request has been canceled |
| 675 // before sending it. | 672 // before sending it. |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 DownloadProtectionService* service_; | 855 DownloadProtectionService* service_; |
| 859 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor_; | 856 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor_; |
| 860 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; | 857 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; |
| 861 const bool pingback_enabled_; | 858 const bool pingback_enabled_; |
| 862 scoped_ptr<net::URLFetcher> fetcher_; | 859 scoped_ptr<net::URLFetcher> fetcher_; |
| 863 scoped_refptr<SandboxedZipAnalyzer> analyzer_; | 860 scoped_refptr<SandboxedZipAnalyzer> analyzer_; |
| 864 base::TimeTicks zip_analysis_start_time_; | 861 base::TimeTicks zip_analysis_start_time_; |
| 865 bool finished_; | 862 bool finished_; |
| 866 ClientDownloadRequest::DownloadType type_; | 863 ClientDownloadRequest::DownloadType type_; |
| 867 std::string client_download_request_data_; | 864 std::string client_download_request_data_; |
| 868 CancelableRequestConsumer request_consumer_; // For HistoryService lookup. | 865 base::CancelableTaskTracker request_tracker_; // For HistoryService lookup. |
| 869 base::WeakPtrFactory<CheckClientDownloadRequest> weakptr_factory_; | 866 base::WeakPtrFactory<CheckClientDownloadRequest> weakptr_factory_; |
| 870 base::TimeTicks start_time_; // Used for stats. | 867 base::TimeTicks start_time_; // Used for stats. |
| 871 base::TimeTicks timeout_start_time_; | 868 base::TimeTicks timeout_start_time_; |
| 872 base::TimeTicks request_start_time_; | 869 base::TimeTicks request_start_time_; |
| 873 | 870 |
| 874 DISALLOW_COPY_AND_ASSIGN(CheckClientDownloadRequest); | 871 DISALLOW_COPY_AND_ASSIGN(CheckClientDownloadRequest); |
| 875 }; | 872 }; |
| 876 | 873 |
| 877 DownloadProtectionService::DownloadProtectionService( | 874 DownloadProtectionService::DownloadProtectionService( |
| 878 SafeBrowsingService* sb_service, | 875 SafeBrowsingService* sb_service, |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 GURL DownloadProtectionService::GetDownloadRequestUrl() { | 1060 GURL DownloadProtectionService::GetDownloadRequestUrl() { |
| 1064 GURL url(kDownloadRequestUrl); | 1061 GURL url(kDownloadRequestUrl); |
| 1065 std::string api_key = google_apis::GetAPIKey(); | 1062 std::string api_key = google_apis::GetAPIKey(); |
| 1066 if (!api_key.empty()) | 1063 if (!api_key.empty()) |
| 1067 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 1064 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
| 1068 | 1065 |
| 1069 return url; | 1066 return url; |
| 1070 } | 1067 } |
| 1071 | 1068 |
| 1072 } // namespace safe_browsing | 1069 } // namespace safe_browsing |
| OLD | NEW |