Chromium Code Reviews| Index: chrome/browser/safe_browsing/safe_browsing_service.cc |
| =================================================================== |
| --- chrome/browser/safe_browsing/safe_browsing_service.cc (revision 90024) |
| +++ chrome/browser/safe_browsing/safe_browsing_service.cc (working copy) |
| @@ -14,7 +14,7 @@ |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/metrics/metrics_service.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| -#include "chrome/browser/profiles/profile_manager.h" |
| +#include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/safe_browsing/malware_details.h" |
| #include "chrome/browser/safe_browsing/protocol_manager.h" |
| #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
| @@ -53,14 +53,6 @@ |
| // Similar to kDownloadUrlCheckTimeoutMs, but for download hash checks. |
| const int64 kDownloadHashCheckTimeoutMs = 10000; |
| -// TODO(lzheng): Replace this with Profile* ProfileManager::GetDefaultProfile(). |
| -Profile* GetDefaultProfile() { |
| - FilePath user_data_dir; |
| - PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| - ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| - return profile_manager->GetDefaultProfile(user_data_dir); |
| -} |
| - |
| // Records disposition information about the check. |hit| should be |
| // |true| if there were any prefix hits in |full_hashes|. |
| void RecordGetHashCheckStatus( |
| @@ -171,10 +163,9 @@ |
| } |
| void SafeBrowsingService::Initialize() { |
| - // Get the profile's preference for SafeBrowsing. |
| - PrefService* pref_service = GetDefaultProfile()->GetPrefs(); |
| - if (pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)) |
| - Start(); |
| + // Always initialize the safe browsing service. Each profile will decide |
| + // whether to use it based on per-user preferences. |
| + Start(); |
|
Joao da Silva
2011/06/24 14:32:04
I guess the SafeBrowsingService should only run as
Miranda Callahan
2011/07/07 17:35:50
Feel free to give it a try! :-)
|
| } |
| void SafeBrowsingService::ShutDown() { |
| @@ -189,18 +180,18 @@ |
| url.SchemeIs(chrome::kHttpsScheme); |
| } |
| -// Only report SafeBrowsing related stats when UMA is enabled and |
| -// safe browsing is enabled. |
| +// Only report SafeBrowsing related stats when UMA is enabled. User must also |
| +// ensure that safe browsing is enabled from the calling profile. |
| 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 +846,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 +973,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 +989,11 @@ |
| return; |
| } |
| - if (resource.threat_type != SafeBrowsingService::SAFE && CanReportStats()) { |
| - GURL page_url = wc->GetURL(); |
| + if (resource.threat_type != SafeBrowsingService::SAFE && |
| + CanReportStats()) { |
| + 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 +1011,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); |
| @@ -1033,7 +1026,8 @@ |
| 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) { |
|
mattm
2011/06/23 21:40:40
Doesn't need this arg anymore.
Miranda Callahan
2011/07/07 17:35:50
Done.
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| if (!CanReportStats()) |
| return; |