Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: chrome/browser/net/prediction_options.cc

Issue 516443002: Remove NETWORK_PREDICTION_UNSET. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nest namespaces. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/net/prediction_options.h ('k') | chrome/browser/prefetch/prefetch.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/net/prediction_options.h" 5 #include "chrome/browser/net/prediction_options.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile_io_data.h" 9 #include "chrome/browser/profiles/profile_io_data.h"
10 #include "chrome/common/pref_names.h" 10 #include "chrome/common/pref_names.h"
11 #include "components/pref_registry/pref_registry_syncable.h" 11 #include "components/pref_registry/pref_registry_syncable.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "net/base/network_change_notifier.h" 13 #include "net/base/network_change_notifier.h"
14 14
15 namespace chrome_browser_net {
16
15 namespace { 17 namespace {
16 18
17 // Since looking up preferences and current network connection are presumably 19 // Since looking up preferences and current network connection are presumably
18 // both cheap, we do not cache them here. 20 // both cheap, we do not cache them here.
19 bool CanPrefetchAndPrerender(int network_prediction_options, 21 bool CanPrefetchAndPrerender(int network_prediction_options) {
20 bool network_prediction_enabled) {
21 switch (network_prediction_options) { 22 switch (network_prediction_options) {
22 case chrome_browser_net::NETWORK_PREDICTION_ALWAYS: 23 case NETWORK_PREDICTION_ALWAYS:
23 return true; 24 return true;
24 case chrome_browser_net::NETWORK_PREDICTION_WIFI_ONLY: 25 case NETWORK_PREDICTION_NEVER:
26 return false;
27 default:
mmenke 2014/08/28 17:03:37 Optional: Maybe DCHECK_EQ(NETWORK_PREDICTION_WIFI
Bence 2014/08/29 13:22:42 Done.
25 return !net::NetworkChangeNotifier::IsConnectionCellular( 28 return !net::NetworkChangeNotifier::IsConnectionCellular(
26 net::NetworkChangeNotifier::GetConnectionType()); 29 net::NetworkChangeNotifier::GetConnectionType());
27 case chrome_browser_net::NETWORK_PREDICTION_NEVER:
28 return false;
29 case chrome_browser_net::NETWORK_PREDICTION_UNSET:
30 return network_prediction_enabled;
31 default:
32 NOTREACHED() << "Unknown kNetworkPredictionOptions value.";
33 return false;
34 } 30 }
35 } 31 }
36 32
37 bool CanPreresolveAndPreconnect(int network_prediction_options, 33 bool CanPreresolveAndPreconnect(int network_prediction_options) {
38 bool network_prediction_enabled) { 34 // DNS preresolution and TCP preconnect are performed even on cellular
39 switch (network_prediction_options) { 35 // networks if the user setting is WIFI_ONLY.
40 case chrome_browser_net::NETWORK_PREDICTION_ALWAYS: 36 return network_prediction_options != NETWORK_PREDICTION_NEVER;
41 return true;
42 // DNS preresolution and TCP preconnect are performed even on cellular
43 // networks if the user setting is WIFI_ONLY.
44 case chrome_browser_net::NETWORK_PREDICTION_WIFI_ONLY:
45 return true;
46 case chrome_browser_net::NETWORK_PREDICTION_NEVER:
47 return false;
48 case chrome_browser_net::NETWORK_PREDICTION_UNSET:
49 return network_prediction_enabled;
50 default:
51 NOTREACHED() << "Unknown kNetworkPredictionOptions value.";
52 return false;
53 }
54 } 37 }
55 38
56 } // namespace 39 } // namespace
57 40
58 namespace chrome_browser_net {
59
60 void RegisterPredictionOptionsProfilePrefs( 41 void RegisterPredictionOptionsProfilePrefs(
61 user_prefs::PrefRegistrySyncable* registry) { 42 user_prefs::PrefRegistrySyncable* registry) {
62 registry->RegisterIntegerPref( 43 registry->RegisterIntegerPref(
63 prefs::kNetworkPredictionOptions, 44 prefs::kNetworkPredictionOptions,
64 chrome_browser_net::NETWORK_PREDICTION_UNSET, 45 NETWORK_PREDICTION_DEFAULT,
65 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 46 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
66 } 47 }
67 48
68 void MigrateNetworkPredictionUserPrefs(PrefService* pref_service) { 49 void MigrateNetworkPredictionUserPrefs(PrefService* pref_service) {
69 // Nothing to do if the user or this migration code has already set the new 50 // Nothing to do if the user or this migration code has already set the new
70 // preference. 51 // preference.
71 if (pref_service->GetUserPrefValue(prefs::kNetworkPredictionOptions)) 52 if (pref_service->GetUserPrefValue(prefs::kNetworkPredictionOptions))
72 return; 53 return;
73 54
74 // Nothing to do if the user has not set the old preference. 55 // Nothing to do if the user has not set the old preference.
75 const base::Value* network_prediction_enabled = 56 const base::Value* network_prediction_enabled =
76 pref_service->GetUserPrefValue(prefs::kNetworkPredictionEnabled); 57 pref_service->GetUserPrefValue(prefs::kNetworkPredictionEnabled);
77 if (!network_prediction_enabled) 58 if (!network_prediction_enabled)
78 return; 59 return;
79 60
80 bool value = false; 61 bool value = false;
81 if (network_prediction_enabled->GetAsBoolean(&value)) { 62 if (network_prediction_enabled->GetAsBoolean(&value)) {
82 pref_service->SetInteger( 63 pref_service->SetInteger(
83 prefs::kNetworkPredictionOptions, 64 prefs::kNetworkPredictionOptions,
84 value ? chrome_browser_net::NETWORK_PREDICTION_WIFI_ONLY 65 value ? NETWORK_PREDICTION_WIFI_ONLY : NETWORK_PREDICTION_NEVER);
85 : chrome_browser_net::NETWORK_PREDICTION_NEVER);
86 } 66 }
87 } 67 }
88 68
89 bool CanPrefetchAndPrerenderIO(ProfileIOData* profile_io_data) { 69 bool CanPrefetchAndPrerenderIO(ProfileIOData* profile_io_data) {
90 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 70 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
91 DCHECK(profile_io_data); 71 DCHECK(profile_io_data);
92 return CanPrefetchAndPrerender( 72 return CanPrefetchAndPrerender(
93 profile_io_data->network_prediction_options()->GetValue(), 73 profile_io_data->network_prediction_options()->GetValue());
94 profile_io_data->network_prediction_enabled()->GetValue());
95 } 74 }
96 75
97 bool CanPrefetchAndPrerenderUI(PrefService* prefs) { 76 bool CanPrefetchAndPrerenderUI(PrefService* prefs) {
98 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 77 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
99 DCHECK(prefs); 78 DCHECK(prefs);
100 return CanPrefetchAndPrerender( 79 return CanPrefetchAndPrerender(
101 prefs->GetInteger(prefs::kNetworkPredictionOptions), 80 prefs->GetInteger(prefs::kNetworkPredictionOptions));
102 prefs->GetBoolean(prefs::kNetworkPredictionEnabled));
103 } 81 }
104 82
105 bool CanPredictNetworkActionsUI(PrefService* prefs) { 83 bool CanPredictNetworkActionsUI(PrefService* prefs) {
106 return CanPrefetchAndPrerenderUI(prefs); 84 return CanPrefetchAndPrerenderUI(prefs);
107 } 85 }
108 86
109 bool CanPreresolveAndPreconnectIO(ProfileIOData* profile_io_data) { 87 bool CanPreresolveAndPreconnectIO(ProfileIOData* profile_io_data) {
110 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 88 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
111 DCHECK(profile_io_data); 89 DCHECK(profile_io_data);
112 return CanPreresolveAndPreconnect( 90 return CanPreresolveAndPreconnect(
113 profile_io_data->network_prediction_options()->GetValue(), 91 profile_io_data->network_prediction_options()->GetValue());
114 profile_io_data->network_prediction_enabled()->GetValue());
115 } 92 }
116 93
117 bool CanPreresolveAndPreconnectUI(PrefService* prefs) { 94 bool CanPreresolveAndPreconnectUI(PrefService* prefs) {
118 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 95 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
119 DCHECK(prefs); 96 DCHECK(prefs);
120 return CanPreresolveAndPreconnect( 97 return CanPreresolveAndPreconnect(
121 prefs->GetInteger(prefs::kNetworkPredictionOptions), 98 prefs->GetInteger(prefs::kNetworkPredictionOptions));
122 prefs->GetBoolean(prefs::kNetworkPredictionEnabled));
123 } 99 }
124 100
125 } // namespace chrome_browser_net 101 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/prediction_options.h ('k') | chrome/browser/prefetch/prefetch.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698