Commit c1a560b6 authored by bnc's avatar bnc Committed by Commit bot

Remove NETWORK_PREDICTION_UNSET.

Since PrefService provides a consistent and convenient way to check if a user
value has ever been saved for a preference, there is no need for
NETWORK_PREDICTION_UNSET in enum chrome_browser_net::NetworkPredictionOptions.
The default value is NETWORK_PREDICTION_WIFI_ONLY, this is reported by
PrefService if there is no user setting, policy, etc.

Note that since MigrateNetworkPredictionUserPrefs was introduced in
https://codereview.chromium.org/421653006/diff/160002/chrome/browser/net/prediction_options.cc,
there is no need to check the old preference NetworkPredictionEnabled in
CanPrefetchAndPrerender* or CanPreresolveAndPreconnect*.

Also note that Chromium at no point did save NETWORK_PREDICTION_UNSET to disk,
it only used to be provided as a default option.  This guarantees that this CL
does not introduce functional change.

TODO:
 * Remove network_prediction_enabled from profile_io_data.
 * Remove PrerenderCondition classes.

As this CL will also fix UI bug https://crbug.com/404794, I prefer to land it
first, and deal with the other two clean-up items on a separate CL.

BUG=406583

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

Cr-Commit-Position: refs/heads/master@{#292613}
parent 5bc6c6bb
......@@ -12,56 +12,38 @@
#include "content/public/browser/browser_thread.h"
#include "net/base/network_change_notifier.h"
namespace chrome_browser_net {
namespace {
// Since looking up preferences and current network connection are presumably
// both cheap, we do not cache them here.
bool CanPrefetchAndPrerender(int network_prediction_options,
bool network_prediction_enabled) {
bool CanPrefetchAndPrerender(int network_prediction_options) {
switch (network_prediction_options) {
case chrome_browser_net::NETWORK_PREDICTION_ALWAYS:
case NETWORK_PREDICTION_ALWAYS:
return true;
case chrome_browser_net::NETWORK_PREDICTION_WIFI_ONLY:
return !net::NetworkChangeNotifier::IsConnectionCellular(
net::NetworkChangeNotifier::GetConnectionType());
case chrome_browser_net::NETWORK_PREDICTION_NEVER:
case NETWORK_PREDICTION_NEVER:
return false;
case chrome_browser_net::NETWORK_PREDICTION_UNSET:
return network_prediction_enabled;
default:
NOTREACHED() << "Unknown kNetworkPredictionOptions value.";
return false;
DCHECK_EQ(NETWORK_PREDICTION_WIFI_ONLY, network_prediction_options);
return !net::NetworkChangeNotifier::IsConnectionCellular(
net::NetworkChangeNotifier::GetConnectionType());
}
}
bool CanPreresolveAndPreconnect(int network_prediction_options,
bool network_prediction_enabled) {
switch (network_prediction_options) {
case chrome_browser_net::NETWORK_PREDICTION_ALWAYS:
return true;
bool CanPreresolveAndPreconnect(int network_prediction_options) {
// DNS preresolution and TCP preconnect are performed even on cellular
// networks if the user setting is WIFI_ONLY.
case chrome_browser_net::NETWORK_PREDICTION_WIFI_ONLY:
return true;
case chrome_browser_net::NETWORK_PREDICTION_NEVER:
return false;
case chrome_browser_net::NETWORK_PREDICTION_UNSET:
return network_prediction_enabled;
default:
NOTREACHED() << "Unknown kNetworkPredictionOptions value.";
return false;
}
return network_prediction_options != NETWORK_PREDICTION_NEVER;
}
} // namespace
namespace chrome_browser_net {
void RegisterPredictionOptionsProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterIntegerPref(
prefs::kNetworkPredictionOptions,
chrome_browser_net::NETWORK_PREDICTION_UNSET,
NETWORK_PREDICTION_DEFAULT,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
}
......@@ -81,8 +63,7 @@ void MigrateNetworkPredictionUserPrefs(PrefService* pref_service) {
if (network_prediction_enabled->GetAsBoolean(&value)) {
pref_service->SetInteger(
prefs::kNetworkPredictionOptions,
value ? chrome_browser_net::NETWORK_PREDICTION_WIFI_ONLY
: chrome_browser_net::NETWORK_PREDICTION_NEVER);
value ? NETWORK_PREDICTION_WIFI_ONLY : NETWORK_PREDICTION_NEVER);
}
}
......@@ -90,16 +71,14 @@ bool CanPrefetchAndPrerenderIO(ProfileIOData* profile_io_data) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
DCHECK(profile_io_data);
return CanPrefetchAndPrerender(
profile_io_data->network_prediction_options()->GetValue(),
profile_io_data->network_prediction_enabled()->GetValue());
profile_io_data->network_prediction_options()->GetValue());
}
bool CanPrefetchAndPrerenderUI(PrefService* prefs) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
DCHECK(prefs);
return CanPrefetchAndPrerender(
prefs->GetInteger(prefs::kNetworkPredictionOptions),
prefs->GetBoolean(prefs::kNetworkPredictionEnabled));
prefs->GetInteger(prefs::kNetworkPredictionOptions));
}
bool CanPredictNetworkActionsUI(PrefService* prefs) {
......@@ -110,16 +89,14 @@ bool CanPreresolveAndPreconnectIO(ProfileIOData* profile_io_data) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
DCHECK(profile_io_data);
return CanPreresolveAndPreconnect(
profile_io_data->network_prediction_options()->GetValue(),
profile_io_data->network_prediction_enabled()->GetValue());
profile_io_data->network_prediction_options()->GetValue());
}
bool CanPreresolveAndPreconnectUI(PrefService* prefs) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
DCHECK(prefs);
return CanPreresolveAndPreconnect(
prefs->GetInteger(prefs::kNetworkPredictionOptions),
prefs->GetBoolean(prefs::kNetworkPredictionEnabled));
prefs->GetInteger(prefs::kNetworkPredictionOptions));
}
} // namespace chrome_browser_net
......@@ -17,14 +17,11 @@ namespace chrome_browser_net {
// Enum describing when to allow network predictions based on connection type.
// The numerical value is stored in the prefs file, therefore the same enum
// with the same order must be used by the platform-dependent components.
// TODO(bnc): implement as per crbug.com/334602.
// NETWORK_PREDICTION_UNSET means that the old preferences,
// kNetworkPredictionEnabled and kAllowPrerender, should be observed.
enum NetworkPredictionOptions {
NETWORK_PREDICTION_ALWAYS,
NETWORK_PREDICTION_WIFI_ONLY,
NETWORK_PREDICTION_NEVER,
NETWORK_PREDICTION_UNSET,
NETWORK_PREDICTION_DEFAULT = NETWORK_PREDICTION_WIFI_ONLY,
};
void RegisterPredictionOptionsProfilePrefs(
......
......@@ -19,17 +19,6 @@ bool IsPrefetchEnabled(content::ResourceContext* resource_context) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
DCHECK(io_data);
// TODO(bnc): Remove this condition once the new
// predictive preference is used on all platforms. See crbug.com/334602.
if (io_data->network_prediction_options()->GetValue() ==
chrome_browser_net::NETWORK_PREDICTION_UNSET &&
net::NetworkChangeNotifier::IsConnectionCellular(
net::NetworkChangeNotifier::GetConnectionType())) {
return false;
}
return chrome_browser_net::CanPrefetchAndPrerenderIO(io_data) &&
!DisableForFieldTrial();
}
......
......@@ -238,8 +238,7 @@ struct PrerenderManager::NavigationRecord {
PrerenderManager::PrerenderManager(Profile* profile,
PrerenderTracker* prerender_tracker)
: enabled_(profile && profile->GetPrefs() &&
profile->GetPrefs()->GetBoolean(prefs::kNetworkPredictionEnabled)),
: enabled_(true),
profile_(profile),
prerender_tracker_(prerender_tracker),
prerender_contents_factory_(PrerenderContents::CreateFactory()),
......@@ -1862,24 +1861,9 @@ void PrerenderManager::RecordNetworkBytes(Origin origin,
bool PrerenderManager::IsEnabled() const {
DCHECK(CalledOnValidThread());
// TODO(bnc): remove conditional as per crbug.com/334602.
if (profile_ && profile_->GetPrefs() &&
profile_->GetPrefs()->GetInteger(prefs::kNetworkPredictionOptions) !=
chrome_browser_net::NETWORK_PREDICTION_UNSET) {
return chrome_browser_net::CanPrefetchAndPrerenderUI(profile_->GetPrefs());
}
// TODO(bnc): remove rest of method as per crbug.com/334602.
if (!enabled_)
return false;
for (std::list<const PrerenderCondition*>::const_iterator it =
prerender_conditions_.begin();
it != prerender_conditions_.end();
++it) {
const PrerenderCondition* condition = *it;
if (!condition->CanPrerender())
return false;
}
return true;
return chrome_browser_net::CanPrefetchAndPrerenderUI(profile_->GetPrefs());
}
void PrerenderManager::AddProfileNetworkBytesIfEnabled(int64 bytes) {
......
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