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 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1012 if (!resource.is_subresource && | 1012 if (!resource.is_subresource && |
1013 !resource.original_url.is_empty() && | 1013 !resource.original_url.is_empty() && |
1014 resource.original_url != resource.url) { | 1014 resource.original_url != resource.url) { |
1015 referrer_url = page_url; | 1015 referrer_url = page_url; |
1016 page_url = resource.original_url; | 1016 page_url = resource.original_url; |
1017 } | 1017 } |
1018 ReportSafeBrowsingHit(resource.url, page_url, referrer_url, | 1018 ReportSafeBrowsingHit(resource.url, page_url, referrer_url, |
1019 resource.is_subresource, resource.threat_type, | 1019 resource.is_subresource, resource.threat_type, |
1020 std::string() /* post_data */); | 1020 std::string() /* post_data */); |
1021 } | 1021 } |
1022 | 1022 if (resource.threat_type != SafeBrowsingService::SAFE) { |
1023 FOR_EACH_OBSERVER(Observer, observer_list_, OnSafeBrowsingHit(resource)); | |
1024 } | |
1023 SafeBrowsingBlockingPage::ShowBlockingPage(this, resource); | 1025 SafeBrowsingBlockingPage::ShowBlockingPage(this, resource); |
1024 } | 1026 } |
1025 | 1027 |
1026 // A safebrowsing hit is sent after a blocking page for malware/phishing | 1028 // A safebrowsing hit is sent after a blocking page for malware/phishing |
1027 // or after the warning dialog for download urls, only for UMA users. | 1029 // or after the warning dialog for download urls, only for UMA users. |
1028 void SafeBrowsingService::ReportSafeBrowsingHit( | 1030 void SafeBrowsingService::ReportSafeBrowsingHit( |
1029 const GURL& malicious_url, | 1031 const GURL& malicious_url, |
1030 const GURL& page_url, | 1032 const GURL& page_url, |
1031 const GURL& referrer_url, | 1033 const GURL& referrer_url, |
1032 bool is_subresource, | 1034 bool is_subresource, |
1033 SafeBrowsingService::UrlCheckResult threat_type, | 1035 SafeBrowsingService::UrlCheckResult threat_type, |
1034 const std::string& post_data) { | 1036 const std::string& post_data) { |
1035 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1037 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1036 if (!CanReportStats()) | 1038 if (!CanReportStats()) |
1037 return; | 1039 return; |
1038 | 1040 |
1039 BrowserThread::PostTask( | 1041 BrowserThread::PostTask( |
1040 BrowserThread::IO, FROM_HERE, | 1042 BrowserThread::IO, FROM_HERE, |
1041 NewRunnableMethod( | 1043 NewRunnableMethod( |
1042 this, | 1044 this, |
1043 &SafeBrowsingService::ReportSafeBrowsingHitOnIOThread, | 1045 &SafeBrowsingService::ReportSafeBrowsingHitOnIOThread, |
1044 malicious_url, | 1046 malicious_url, |
1045 page_url, | 1047 page_url, |
1046 referrer_url, | 1048 referrer_url, |
1047 is_subresource, | 1049 is_subresource, |
1048 threat_type, | 1050 threat_type, |
1049 post_data)); | 1051 post_data)); |
1050 } | 1052 } |
1051 | 1053 |
1054 void SafeBrowsingService::AddObserver(Observer* observer) { | |
mattm
2011/07/19 21:25:55
Add thread DCHECKS?
noelutz
2011/07/19 22:28:08
Done.
| |
1055 observer_list_.AddObserver(observer); | |
1056 } | |
1057 | |
1058 void SafeBrowsingService::RemoveObserver(Observer* observer) { | |
1059 observer_list_.RemoveObserver(observer); | |
1060 } | |
1061 | |
1052 void SafeBrowsingService::ReportSafeBrowsingHitOnIOThread( | 1062 void SafeBrowsingService::ReportSafeBrowsingHitOnIOThread( |
1053 const GURL& malicious_url, | 1063 const GURL& malicious_url, |
1054 const GURL& page_url, | 1064 const GURL& page_url, |
1055 const GURL& referrer_url, | 1065 const GURL& referrer_url, |
1056 bool is_subresource, | 1066 bool is_subresource, |
1057 SafeBrowsingService::UrlCheckResult threat_type, | 1067 SafeBrowsingService::UrlCheckResult threat_type, |
1058 const std::string& post_data) { | 1068 const std::string& post_data) { |
1059 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1069 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1060 if (!enabled_) | 1070 if (!enabled_) |
1061 return; | 1071 return; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1226 (entry.result == CLIENT_SIDE_PHISHING_URL && | 1236 (entry.result == CLIENT_SIDE_PHISHING_URL && |
1227 resource.threat_type == URL_PHISHING)) && | 1237 resource.threat_type == URL_PHISHING)) && |
1228 entry.domain == | 1238 entry.domain == |
1229 net::RegistryControlledDomainService::GetDomainAndRegistry( | 1239 net::RegistryControlledDomainService::GetDomainAndRegistry( |
1230 resource.url)) { | 1240 resource.url)) { |
1231 return true; | 1241 return true; |
1232 } | 1242 } |
1233 } | 1243 } |
1234 return false; | 1244 return false; |
1235 } | 1245 } |
OLD | NEW |