| 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/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 // The default URL prefix where browser fetches chunk updates, hashes, | 40 // The default URL prefix where browser fetches chunk updates, hashes, |
| 41 // and reports safe browsing hits. | 41 // and reports safe browsing hits. |
| 42 const char* const kSbDefaultInfoURLPrefix = | 42 const char* const kSbDefaultInfoURLPrefix = |
| 43 "http://safebrowsing.clients.google.com/safebrowsing"; | 43 "http://safebrowsing.clients.google.com/safebrowsing"; |
| 44 | 44 |
| 45 // The default URL prefix where browser fetches MAC client key and reports | 45 // The default URL prefix where browser fetches MAC client key and reports |
| 46 // malware details. | 46 // malware details. |
| 47 const char* const kSbDefaultMacKeyURLPrefix = | 47 const char* const kSbDefaultMacKeyURLPrefix = |
| 48 "https://sb-ssl.google.com/safebrowsing"; | 48 "https://sb-ssl.google.com/safebrowsing"; |
| 49 | 49 |
| 50 // TODO(lzheng): Replace this with Profile* ProfileManager::GetDefaultProfile(). |
| 50 Profile* GetDefaultProfile() { | 51 Profile* GetDefaultProfile() { |
| 51 FilePath user_data_dir; | 52 FilePath user_data_dir; |
| 52 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 53 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 53 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 54 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 54 return profile_manager->GetDefaultProfile(user_data_dir); | 55 return profile_manager->GetDefaultProfile(user_data_dir); |
| 55 } | 56 } |
| 56 | 57 |
| 57 // Records disposition information about the check. |hit| should be | 58 // Records disposition information about the check. |hit| should be |
| 58 // |true| if there were any prefix hits in |full_hashes|. | 59 // |true| if there were any prefix hits in |full_hashes|. |
| 59 void RecordGetHashCheckStatus( | 60 void RecordGetHashCheckStatus( |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 BrowserThread::IO, FROM_HERE, | 148 BrowserThread::IO, FROM_HERE, |
| 148 NewRunnableMethod(this, &SafeBrowsingService::OnIOShutdown)); | 149 NewRunnableMethod(this, &SafeBrowsingService::OnIOShutdown)); |
| 149 } | 150 } |
| 150 | 151 |
| 151 bool SafeBrowsingService::CanCheckUrl(const GURL& url) const { | 152 bool SafeBrowsingService::CanCheckUrl(const GURL& url) const { |
| 152 return url.SchemeIs(chrome::kFtpScheme) || | 153 return url.SchemeIs(chrome::kFtpScheme) || |
| 153 url.SchemeIs(chrome::kHttpScheme) || | 154 url.SchemeIs(chrome::kHttpScheme) || |
| 154 url.SchemeIs(chrome::kHttpsScheme); | 155 url.SchemeIs(chrome::kHttpsScheme); |
| 155 } | 156 } |
| 156 | 157 |
| 158 // Only report SafeBrowsing related stats when UMA is enabled and |
| 159 // safe browsing is enabled. |
| 160 bool SafeBrowsingService::CanReportStats() const { |
| 161 const MetricsService* metrics = g_browser_process->metrics_service(); |
| 162 const PrefService* pref_service = GetDefaultProfile()->GetPrefs(); |
| 163 return metrics && metrics->reporting_active() && |
| 164 pref_service && pref_service->GetBoolean(prefs::kSafeBrowsingEnabled); |
| 165 } |
| 166 |
| 167 // Binhash verification is only enabled for UMA users for now. |
| 168 bool SafeBrowsingService::DownloadBinHashNeeded() const { |
| 169 return enable_download_protection_ && CanReportStats(); |
| 170 } |
| 171 |
| 157 void SafeBrowsingService::CheckDownloadUrlDone( | 172 void SafeBrowsingService::CheckDownloadUrlDone( |
| 158 SafeBrowsingCheck* check, UrlCheckResult result) { | 173 SafeBrowsingCheck* check, UrlCheckResult result) { |
| 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 160 DCHECK(enable_download_protection_); | 175 DCHECK(enable_download_protection_); |
| 161 VLOG(1) << "CheckDownloadUrlDone: " << result; | 176 VLOG(1) << "CheckDownloadUrlDone: " << result; |
| 162 | 177 |
| 163 if (checks_.find(check) == checks_.end() || !check->client) | 178 if (checks_.find(check) == checks_.end() || !check->client) |
| 164 return; | 179 return; |
| 165 check->client->OnSafeBrowsingResult(check->url, result); | 180 check->client->OnSafeBrowsingResult(check->url, result); |
| 166 checks_.erase(check); | 181 checks_.erase(check); |
| (...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 // checkbox on the blocking page. | 980 // checkbox on the blocking page. |
| 966 void SafeBrowsingService::ReportMalwareDetails( | 981 void SafeBrowsingService::ReportMalwareDetails( |
| 967 scoped_refptr<MalwareDetails> details) { | 982 scoped_refptr<MalwareDetails> details) { |
| 968 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 983 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 969 scoped_ptr<const std::string> serialized(details->GetSerializedReport()); | 984 scoped_ptr<const std::string> serialized(details->GetSerializedReport()); |
| 970 if (!serialized->empty()) { | 985 if (!serialized->empty()) { |
| 971 DVLOG(1) << "Sending serialized malware details."; | 986 DVLOG(1) << "Sending serialized malware details."; |
| 972 protocol_manager_->ReportMalwareDetails(*serialized); | 987 protocol_manager_->ReportMalwareDetails(*serialized); |
| 973 } | 988 } |
| 974 } | 989 } |
| OLD | NEW |