OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/net/prediction_options.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/prefs/pref_service.h" |
| 9 #include "chrome/browser/net/predictor.h" |
| 10 #include "chrome/browser/profiles/profile_io_data.h" |
| 11 #include "chrome/common/pref_names.h" |
| 12 #include "components/pref_registry/pref_registry_syncable.h" |
| 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "net/base/network_change_notifier.h" |
| 15 |
| 16 namespace { |
| 17 |
| 18 // Since looking up preferences and current network connection are presumably |
| 19 // both cheap, we do not cache them here. |
| 20 bool CanPredictNetworkActions(int NetworkPredictionOptions, |
| 21 bool NetworkPredictionEnabled) { |
| 22 switch (NetworkPredictionOptions) { |
| 23 case chrome_browser_net::NETWORK_PREDICTION_ALWAYS: |
| 24 return true; |
| 25 case chrome_browser_net::NETWORK_PREDICTION_WIFI_ONLY: |
| 26 return !net::NetworkChangeNotifier::IsConnectionCellular( |
| 27 net::NetworkChangeNotifier::GetConnectionType()); |
| 28 case chrome_browser_net::NETWORK_PREDICTION_NEVER: |
| 29 return false; |
| 30 case chrome_browser_net::NETWORK_PREDICTION_UNSET: |
| 31 return NetworkPredictionEnabled; |
| 32 default: |
| 33 NOTREACHED() << "Unknown kNetworkPredictionOptions value."; |
| 34 return false; |
| 35 } |
| 36 } |
| 37 |
| 38 } // namespace |
| 39 |
| 40 namespace chrome_browser_net { |
| 41 |
| 42 void RegisterPredictionOptionsProfilePrefs( |
| 43 user_prefs::PrefRegistrySyncable* registry) { |
| 44 registry->RegisterIntegerPref( |
| 45 prefs::kNetworkPredictionOptions, |
| 46 chrome_browser_net::NETWORK_PREDICTION_UNSET, |
| 47 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 48 } |
| 49 |
| 50 bool CanPredictNetworkActionsIO(content::ResourceContext* resource_context) { |
| 51 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 52 DCHECK(resource_context); |
| 53 |
| 54 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
| 55 return CanPredictNetworkActions( |
| 56 io_data->network_prediction_options()->GetValue(), |
| 57 io_data->network_prediction_enabled()->GetValue()); |
| 58 } |
| 59 |
| 60 bool CanPredictNetworkActionsUI(PrefService* prefs) { |
| 61 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 62 DCHECK(prefs); |
| 63 return CanPredictNetworkActions( |
| 64 prefs->GetInteger(prefs::kNetworkPredictionOptions), |
| 65 prefs->GetBoolean(prefs::kNetworkPredictionEnabled)); |
| 66 } |
| 67 |
| 68 } // namespace chrome_browser_net |
OLD | NEW |