OLD | NEW |
---|---|
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" |
(...skipping 16 matching lines...) Expand all Loading... | |
27 case chrome_browser_net::NETWORK_PREDICTION_NEVER: | 27 case chrome_browser_net::NETWORK_PREDICTION_NEVER: |
28 return false; | 28 return false; |
29 case chrome_browser_net::NETWORK_PREDICTION_UNSET: | 29 case chrome_browser_net::NETWORK_PREDICTION_UNSET: |
30 return NetworkPredictionEnabled; | 30 return NetworkPredictionEnabled; |
31 default: | 31 default: |
32 NOTREACHED() << "Unknown kNetworkPredictionOptions value."; | 32 NOTREACHED() << "Unknown kNetworkPredictionOptions value."; |
33 return false; | 33 return false; |
34 } | 34 } |
35 } | 35 } |
36 | 36 |
37 bool CanPreconnect(int NetworkPredictionOptions, | |
38 bool NetworkPredictionEnabled) { | |
mmenke
2014/08/08 16:05:42
These should be named network_prediction_options a
Bence
2014/08/08 20:10:03
Done.
| |
39 switch (NetworkPredictionOptions) { | |
40 case chrome_browser_net::NETWORK_PREDICTION_ALWAYS: | |
41 return true; | |
42 // We allow TCP preconnect and DNS preresolution even on cellular networks | |
43 // if the user setting is WIFI_ONLY. | |
mmenke
2014/08/08 16:05:42
nit: Shouldn't use we in comments, since it's amb
Bence
2014/08/08 20:10:03
Done.
| |
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 NetworkPredictionEnabled; | |
50 default: | |
51 NOTREACHED() << "Unknown kNetworkPredictionOptions value."; | |
52 return false; | |
53 } | |
54 } | |
55 | |
37 } // namespace | 56 } // namespace |
38 | 57 |
39 namespace chrome_browser_net { | 58 namespace chrome_browser_net { |
40 | 59 |
41 void RegisterPredictionOptionsProfilePrefs( | 60 void RegisterPredictionOptionsProfilePrefs( |
42 user_prefs::PrefRegistrySyncable* registry) { | 61 user_prefs::PrefRegistrySyncable* registry) { |
43 registry->RegisterIntegerPref( | 62 registry->RegisterIntegerPref( |
44 prefs::kNetworkPredictionOptions, | 63 prefs::kNetworkPredictionOptions, |
45 chrome_browser_net::NETWORK_PREDICTION_UNSET, | 64 chrome_browser_net::NETWORK_PREDICTION_UNSET, |
46 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 65 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
47 } | 66 } |
48 | 67 |
49 bool CanPredictNetworkActionsIO(ProfileIOData* profile_io_data) { | 68 bool CanPredictNetworkActionsIO(ProfileIOData* profile_io_data) { |
50 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 69 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
51 DCHECK(profile_io_data); | 70 DCHECK(profile_io_data); |
52 | 71 |
53 return CanPredictNetworkActions( | 72 return CanPredictNetworkActions( |
54 profile_io_data->network_prediction_options()->GetValue(), | 73 profile_io_data->network_prediction_options()->GetValue(), |
55 profile_io_data->network_prediction_enabled()->GetValue()); | 74 profile_io_data->network_prediction_enabled()->GetValue()); |
56 } | 75 } |
57 | 76 |
58 bool CanPredictNetworkActionsUI(PrefService* prefs) { | 77 bool CanPredictNetworkActionsUI(PrefService* prefs) { |
59 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 78 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
60 DCHECK(prefs); | 79 DCHECK(prefs); |
61 return CanPredictNetworkActions( | 80 return CanPredictNetworkActions( |
62 prefs->GetInteger(prefs::kNetworkPredictionOptions), | 81 prefs->GetInteger(prefs::kNetworkPredictionOptions), |
63 prefs->GetBoolean(prefs::kNetworkPredictionEnabled)); | 82 prefs->GetBoolean(prefs::kNetworkPredictionEnabled)); |
64 } | 83 } |
65 | 84 |
85 bool CanPreconnectIO(ProfileIOData* profile_io_data) { | |
86 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
87 DCHECK(profile_io_data); | |
88 | |
mmenke
2014/08/08 16:05:42
optional nit: The two IO thread functions have bl
Bence
2014/08/08 20:10:03
Done.
| |
89 return CanPreconnect( | |
90 profile_io_data->network_prediction_options()->GetValue(), | |
91 profile_io_data->network_prediction_enabled()->GetValue()); | |
92 } | |
93 | |
94 bool CanPreconnectUI(PrefService* prefs) { | |
95 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
96 DCHECK(prefs); | |
97 return CanPreconnect(prefs->GetInteger(prefs::kNetworkPredictionOptions), | |
98 prefs->GetBoolean(prefs::kNetworkPredictionEnabled)); | |
99 } | |
100 | |
66 } // namespace chrome_browser_net | 101 } // namespace chrome_browser_net |
OLD | NEW |