OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/singleton.h" | 10 #include "base/singleton.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/browser_thread.h" | 13 #include "chrome/browser/browser_thread.h" |
14 #include "chrome/browser/metrics/metrics_service.h" | 14 #include "chrome/browser/metrics/metrics_service.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/profile_manager.h" | 16 #include "chrome/browser/profile_manager.h" |
| 17 #include "chrome/browser/safe_browsing/malware_details.h" |
17 #include "chrome/browser/safe_browsing/protocol_manager.h" | 18 #include "chrome/browser/safe_browsing/protocol_manager.h" |
18 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 19 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
19 #include "chrome/browser/safe_browsing/safe_browsing_database.h" | 20 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
20 #include "chrome/browser/tab_contents/tab_util.h" | 21 #include "chrome/browser/tab_contents/tab_util.h" |
21 #include "chrome/browser/tab_contents/tab_contents.h" | 22 #include "chrome/browser/tab_contents/tab_contents.h" |
22 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
23 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
24 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/net/url_request_context_getter.h" | 26 #include "chrome/common/net/url_request_context_getter.h" |
26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
27 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
28 #include "net/base/registry_controlled_domain.h" | 29 #include "net/base/registry_controlled_domain.h" |
29 | 30 |
30 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
31 #include "chrome/installer/util/browser_distribution.h" | 32 #include "chrome/installer/util/browser_distribution.h" |
32 #endif | 33 #endif |
33 | 34 |
34 using base::Time; | 35 using base::Time; |
35 using base::TimeDelta; | 36 using base::TimeDelta; |
36 | 37 |
37 // The default URL prefix where browser fetches chunk updates, hashes, | 38 // The default URL prefix where browser fetches chunk updates, hashes, |
38 // and reports malware. | 39 // and reports safe browsing hits. |
39 static const char* const kSbDefaultInfoURLPrefix = | 40 static const char* const kSbDefaultInfoURLPrefix = |
40 "http://safebrowsing.clients.google.com/safebrowsing"; | 41 "http://safebrowsing.clients.google.com/safebrowsing"; |
41 | 42 |
42 // The default URL prefix where browser fetches MAC client key. | 43 // The default URL prefix where browser fetches MAC client key and reports |
| 44 // malware details. |
43 static const char* const kSbDefaultMacKeyURLPrefix = | 45 static const char* const kSbDefaultMacKeyURLPrefix = |
44 "https://sb-ssl.google.com/safebrowsing"; | 46 "https://sb-ssl.google.com/safebrowsing"; |
45 | 47 |
46 static Profile* GetDefaultProfile() { | 48 static Profile* GetDefaultProfile() { |
47 FilePath user_data_dir; | 49 FilePath user_data_dir; |
48 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 50 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
49 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 51 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
50 return profile_manager->GetDefaultProfile(user_data_dir); | 52 return profile_manager->GetDefaultProfile(user_data_dir); |
51 } | 53 } |
52 | 54 |
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 resource.url, | 837 resource.url, |
836 page_url, | 838 page_url, |
837 referrer_url, | 839 referrer_url, |
838 is_subresource, | 840 is_subresource, |
839 resource.threat_type)); | 841 resource.threat_type)); |
840 } | 842 } |
841 | 843 |
842 SafeBrowsingBlockingPage::ShowBlockingPage(this, resource); | 844 SafeBrowsingBlockingPage::ShowBlockingPage(this, resource); |
843 } | 845 } |
844 | 846 |
| 847 // A safebrowsing hit is sent right after we create a blocking page, |
| 848 // only for UMA users. |
845 void SafeBrowsingService::ReportSafeBrowsingHit( | 849 void SafeBrowsingService::ReportSafeBrowsingHit( |
846 const GURL& malicious_url, | 850 const GURL& malicious_url, |
847 const GURL& page_url, | 851 const GURL& page_url, |
848 const GURL& referrer_url, | 852 const GURL& referrer_url, |
849 bool is_subresource, | 853 bool is_subresource, |
850 SafeBrowsingService::UrlCheckResult threat_type) { | 854 SafeBrowsingService::UrlCheckResult threat_type) { |
851 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 855 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
852 if (!enabled_) | 856 if (!enabled_) |
853 return; | 857 return; |
854 | 858 |
855 DVLOG(1) << "ReportSafeBrowsingHit: " << malicious_url << " " << page_url | 859 DVLOG(1) << "ReportSafeBrowsingHit: " << malicious_url << " " << page_url |
856 << " " << referrer_url << " " << is_subresource << " " | 860 << " " << referrer_url << " " << is_subresource << " " |
857 << threat_type; | 861 << threat_type; |
858 protocol_manager_->ReportSafeBrowsingHit(malicious_url, page_url, | 862 protocol_manager_->ReportSafeBrowsingHit(malicious_url, page_url, |
859 referrer_url, is_subresource, | 863 referrer_url, is_subresource, |
860 threat_type); | 864 threat_type); |
861 } | 865 } |
| 866 |
| 867 // A MalwareDetails report is sent after the blocking page is going |
| 868 // away, at which point we see if the user had opted-in using the |
| 869 // checkbox on the blocking page. |
| 870 void SafeBrowsingService::ReportMalwareDetails( |
| 871 scoped_refptr<MalwareDetails> details) { |
| 872 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 873 scoped_ptr<const std::string> serialized(details->GetSerializedReport()); |
| 874 if (!serialized->empty()) { |
| 875 DVLOG(1) << "Sending serialized malware details."; |
| 876 protocol_manager_->ReportMalwareDetails(*serialized); |
| 877 } |
| 878 } |
OLD | NEW |