OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/safe_browsing_service.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 if (!resource.is_subresource && | 1028 if (!resource.is_subresource && |
1029 !resource.original_url.is_empty() && | 1029 !resource.original_url.is_empty() && |
1030 resource.original_url != resource.url) { | 1030 resource.original_url != resource.url) { |
1031 referrer_url = page_url; | 1031 referrer_url = page_url; |
1032 page_url = resource.original_url; | 1032 page_url = resource.original_url; |
1033 } | 1033 } |
1034 ReportSafeBrowsingHit(resource.url, page_url, referrer_url, | 1034 ReportSafeBrowsingHit(resource.url, page_url, referrer_url, |
1035 resource.is_subresource, resource.threat_type, | 1035 resource.is_subresource, resource.threat_type, |
1036 std::string() /* post_data */); | 1036 std::string() /* post_data */); |
1037 } | 1037 } |
1038 | 1038 if (resource.threat_type != SafeBrowsingService::SAFE) { |
| 1039 FOR_EACH_OBSERVER(Observer, observer_list_, OnSafeBrowsingHit(resource)); |
| 1040 } |
1039 SafeBrowsingBlockingPage::ShowBlockingPage(this, resource); | 1041 SafeBrowsingBlockingPage::ShowBlockingPage(this, resource); |
1040 } | 1042 } |
1041 | 1043 |
1042 // A safebrowsing hit is sent after a blocking page for malware/phishing | 1044 // A safebrowsing hit is sent after a blocking page for malware/phishing |
1043 // or after the warning dialog for download urls, only for UMA users. | 1045 // or after the warning dialog for download urls, only for UMA users. |
1044 void SafeBrowsingService::ReportSafeBrowsingHit( | 1046 void SafeBrowsingService::ReportSafeBrowsingHit( |
1045 const GURL& malicious_url, | 1047 const GURL& malicious_url, |
1046 const GURL& page_url, | 1048 const GURL& page_url, |
1047 const GURL& referrer_url, | 1049 const GURL& referrer_url, |
1048 bool is_subresource, | 1050 bool is_subresource, |
1049 SafeBrowsingService::UrlCheckResult threat_type, | 1051 SafeBrowsingService::UrlCheckResult threat_type, |
1050 const std::string& post_data) { | 1052 const std::string& post_data) { |
1051 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1053 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1052 if (!CanReportStats()) | 1054 if (!CanReportStats()) |
1053 return; | 1055 return; |
1054 | 1056 |
1055 BrowserThread::PostTask( | 1057 BrowserThread::PostTask( |
1056 BrowserThread::IO, FROM_HERE, | 1058 BrowserThread::IO, FROM_HERE, |
1057 NewRunnableMethod( | 1059 NewRunnableMethod( |
1058 this, | 1060 this, |
1059 &SafeBrowsingService::ReportSafeBrowsingHitOnIOThread, | 1061 &SafeBrowsingService::ReportSafeBrowsingHitOnIOThread, |
1060 malicious_url, | 1062 malicious_url, |
1061 page_url, | 1063 page_url, |
1062 referrer_url, | 1064 referrer_url, |
1063 is_subresource, | 1065 is_subresource, |
1064 threat_type, | 1066 threat_type, |
1065 post_data)); | 1067 post_data)); |
1066 } | 1068 } |
1067 | 1069 |
| 1070 void SafeBrowsingService::AddObserver(Observer* observer) { |
| 1071 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1072 observer_list_.AddObserver(observer); |
| 1073 } |
| 1074 |
| 1075 void SafeBrowsingService::RemoveObserver(Observer* observer) { |
| 1076 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1077 observer_list_.RemoveObserver(observer); |
| 1078 } |
| 1079 |
1068 void SafeBrowsingService::ReportSafeBrowsingHitOnIOThread( | 1080 void SafeBrowsingService::ReportSafeBrowsingHitOnIOThread( |
1069 const GURL& malicious_url, | 1081 const GURL& malicious_url, |
1070 const GURL& page_url, | 1082 const GURL& page_url, |
1071 const GURL& referrer_url, | 1083 const GURL& referrer_url, |
1072 bool is_subresource, | 1084 bool is_subresource, |
1073 SafeBrowsingService::UrlCheckResult threat_type, | 1085 SafeBrowsingService::UrlCheckResult threat_type, |
1074 const std::string& post_data) { | 1086 const std::string& post_data) { |
1075 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1087 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1076 if (!enabled_) | 1088 if (!enabled_) |
1077 return; | 1089 return; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1304 enable = true; | 1316 enable = true; |
1305 break; | 1317 break; |
1306 } | 1318 } |
1307 } | 1319 } |
1308 | 1320 |
1309 if (enable) | 1321 if (enable) |
1310 Start(); | 1322 Start(); |
1311 else | 1323 else |
1312 ShutDown(); | 1324 ShutDown(); |
1313 } | 1325 } |
OLD | NEW |