Index: chrome/browser/safe_browsing/safe_browsing_service.cc |
=================================================================== |
--- chrome/browser/safe_browsing/safe_browsing_service.cc (revision 89656) |
+++ chrome/browser/safe_browsing/safe_browsing_service.cc (working copy) |
@@ -53,7 +53,7 @@ |
// Similar to kDownloadUrlCheckTimeoutMs, but for download hash checks. |
const int64 kDownloadHashCheckTimeoutMs = 10000; |
-// TODO(lzheng): Replace this with Profile* ProfileManager::GetDefaultProfile(). |
+// TODO(mirandac): remove GetDefaultProfile altogether. |
Profile* GetDefaultProfile() { |
FilePath user_data_dir; |
PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
@@ -190,17 +190,18 @@ |
} |
// Only report SafeBrowsing related stats when UMA is enabled and |
-// safe browsing is enabled. |
+// safe browsing is enabled. Do we really ever get here without |
+// profile's kSafeBrowsingEnabled being true?? |
bool SafeBrowsingService::CanReportStats() const { |
const MetricsService* metrics = g_browser_process->metrics_service(); |
- const PrefService* pref_service = GetDefaultProfile()->GetPrefs(); |
- return metrics && metrics->reporting_active() && |
- pref_service && pref_service->GetBoolean(prefs::kSafeBrowsingEnabled); |
+ return metrics && metrics->reporting_active(); // && |
} |
// Binhash verification is only enabled for UMA users for now. |
-bool SafeBrowsingService::DownloadBinHashNeeded() const { |
- return enable_download_protection_ && CanReportStats(); |
+bool SafeBrowsingService::DownloadBinHashNeeded( |
+ bool safe_browsing_enabled) const { |
+ return enable_download_protection_ && safe_browsing_enabled && |
+ CanReportStats(); |
} |
bool SafeBrowsingService::CheckDownloadUrl(const std::vector<GURL>& url_chain, |
@@ -855,9 +856,9 @@ |
local_state->GetString(prefs::kSafeBrowsingWrappedKey); |
} |
- // We will issue network fetches using the default profile's request context. |
+ // We will issue network fetches using the system request context. |
scoped_refptr<net::URLRequestContextGetter> request_context_getter( |
- GetDefaultProfile()->GetRequestContext()); |
+ g_browser_process->system_request_context()); |
CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
enable_download_protection_ = |
@@ -982,13 +983,13 @@ |
} |
// The tab might have been closed. |
- TabContents* wc = |
+ TabContents* tab_contents = |
tab_util::GetTabContentsByID(resource.render_process_host_id, |
resource.render_view_id); |
- if (!wc) { |
+ if (!tab_contents) { |
// The tab is gone and we did not have a chance at showing the interstitial. |
- // Just act as "Don't Proceed" was chosen. |
+ // Just act as if "Don't Proceed" were chosen. |
std::vector<UnsafeResource> resources; |
resources.push_back(resource); |
BrowserThread::PostTask( |
@@ -998,10 +999,14 @@ |
return; |
} |
- if (resource.threat_type != SafeBrowsingService::SAFE && CanReportStats()) { |
- GURL page_url = wc->GetURL(); |
+ const PrefService* pref_service = tab_contents->profile()->GetPrefs(); |
+ if (resource.threat_type != SafeBrowsingService::SAFE && |
+ CanReportStats() && |
+ pref_service && |
+ pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)) { |
+ GURL page_url = tab_contents->GetURL(); |
GURL referrer_url; |
- NavigationEntry* entry = wc->controller().GetActiveEntry(); |
+ NavigationEntry* entry = tab_contents->controller().GetActiveEntry(); |
if (entry) |
referrer_url = entry->referrer(); |
@@ -1019,7 +1024,8 @@ |
} |
ReportSafeBrowsingHit(resource.url, page_url, referrer_url, |
resource.is_subresource, resource.threat_type, |
- std::string() /* post_data */); |
+ std::string() /* post_data */, |
+ true /* safe browsing enabled */ ); |
} |
SafeBrowsingBlockingPage::ShowBlockingPage(this, resource); |
@@ -1027,15 +1033,17 @@ |
// A safebrowsing hit is sent after a blocking page for malware/phishing |
// or after the warning dialog for download urls, only for UMA users. |
+// pass in knowledge of can we report stats... |
void SafeBrowsingService::ReportSafeBrowsingHit( |
const GURL& malicious_url, |
const GURL& page_url, |
const GURL& referrer_url, |
bool is_subresource, |
SafeBrowsingService::UrlCheckResult threat_type, |
- const std::string& post_data) { |
+ const std::string& post_data, |
+ bool safe_browsing_enabled) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- if (!CanReportStats()) |
+ if (!(CanReportStats() && safe_browsing_enabled)) |
return; |
BrowserThread::PostTask( |