BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / net / prediction_options.cc
blob40abb5abbadf0948e1add54b4f81a72648a2f895
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/net/prediction_options.h"
7 #include "base/logging.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile_io_data.h"
10 #include "chrome/common/pref_names.h"
11 #include "components/pref_registry/pref_registry_syncable.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "net/base/network_change_notifier.h"
15 namespace chrome_browser_net {
17 namespace {
19 // Since looking up preferences and current network connection are presumably
20 // both cheap, we do not cache them here.
21 bool CanPrefetchAndPrerender(int network_prediction_options) {
22 switch (network_prediction_options) {
23 case NETWORK_PREDICTION_ALWAYS:
24 return true;
25 case NETWORK_PREDICTION_NEVER:
26 return false;
27 default:
28 DCHECK_EQ(NETWORK_PREDICTION_WIFI_ONLY, network_prediction_options);
29 return !net::NetworkChangeNotifier::IsConnectionCellular(
30 net::NetworkChangeNotifier::GetConnectionType());
34 bool CanPreresolveAndPreconnect(int network_prediction_options) {
35 // DNS preresolution and TCP preconnect are performed even on cellular
36 // networks if the user setting is WIFI_ONLY.
37 return network_prediction_options != NETWORK_PREDICTION_NEVER;
40 } // namespace
42 void RegisterPredictionOptionsProfilePrefs(
43 user_prefs::PrefRegistrySyncable* registry) {
44 registry->RegisterIntegerPref(
45 prefs::kNetworkPredictionOptions,
46 NETWORK_PREDICTION_DEFAULT,
47 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
50 bool CanPrefetchAndPrerenderIO(ProfileIOData* profile_io_data) {
51 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
52 DCHECK(profile_io_data);
53 return CanPrefetchAndPrerender(
54 profile_io_data->network_prediction_options()->GetValue());
57 bool CanPrefetchAndPrerenderUI(PrefService* prefs) {
58 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
59 DCHECK(prefs);
60 return CanPrefetchAndPrerender(
61 prefs->GetInteger(prefs::kNetworkPredictionOptions));
64 bool CanPreresolveAndPreconnectIO(ProfileIOData* profile_io_data) {
65 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
66 DCHECK(profile_io_data);
67 return CanPreresolveAndPreconnect(
68 profile_io_data->network_prediction_options()->GetValue());
71 bool CanPreresolveAndPreconnectUI(PrefService* prefs) {
72 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
73 DCHECK(prefs);
74 return CanPreresolveAndPreconnect(
75 prefs->GetInteger(prefs::kNetworkPredictionOptions));
78 } // namespace chrome_browser_net