Commit 387f633d authored by tanviraumi's avatar tanviraumi Committed by Commit bot

Check if precaching is allowed for the current browser context before

measuring any precache-related metrics.

BUG=309216

Review URL: https://codereview.chromium.org/514353002

Cr-Commit-Position: refs/heads/master@{#292677}
parent 67fa5e94
......@@ -217,8 +217,8 @@ void RecordPrecacheStatsOnUIThread(const GURL& url,
precache::PrecacheManager* precache_manager =
precache::PrecacheManagerFactory::GetForBrowserContext(profile);
if (!precache_manager) {
// This could be NULL if the profile is off the record.
if (!precache_manager || !precache_manager->IsPrecachingAllowed()) {
// |precache_manager| could be NULL if the profile is off the record.
return;
}
......
include_rules = [
"+components/data_reduction_proxy/common",
"+components/keyed_service",
"+components/user_prefs",
"+content/public/browser",
"+net/base",
]
......
......@@ -9,10 +9,13 @@
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/metrics/field_trial.h"
#include "base/prefs/pref_service.h"
#include "base/time/time.h"
#include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names.h"
#include "components/precache/core/precache_database.h"
#include "components/precache/core/precache_switches.h"
#include "components/precache/core/url_list_provider.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/network_change_notifier.h"
......@@ -50,6 +53,16 @@ bool PrecacheManager::IsPrecachingEnabled() {
CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePrecache);
}
bool PrecacheManager::IsPrecachingAllowed() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
#if defined(SPDY_PROXY_AUTH_ORIGIN)
return user_prefs::UserPrefs::Get(browser_context_)->GetBoolean(
data_reduction_proxy::prefs::kDataReductionProxyEnabled);
#else
return false;
#endif
}
void PrecacheManager::StartPrecaching(
const PrecacheCompletionCallback& precache_completion_callback,
URLListProvider* url_list_provider) {
......
......@@ -49,6 +49,9 @@ class PrecacheManager : public KeyedService,
// command line flag. This method can be called on any thread.
static bool IsPrecachingEnabled();
// Returns true if precaching is allowed for the browser context.
bool IsPrecachingAllowed();
// Starts precaching resources that the user is predicted to fetch in the
// future. If precaching is already currently in progress, then this method
// does nothing. The |precache_completion_callback| will be run when
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment