Chromium Code Reviews| Index: chrome/browser/net/prediction_helper.cc |
| diff --git a/chrome/browser/net/prediction_helper.cc b/chrome/browser/net/prediction_helper.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..86f2c16072ac7661c03d56ce38ccbf3e48db68bb |
| --- /dev/null |
| +++ b/chrome/browser/net/prediction_helper.cc |
| @@ -0,0 +1,66 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/net/prediction_helper.h" |
| + |
| +#include "base/prefs/pref_service.h" |
| +#include "chrome/browser/net/predictor.h" |
| +#include "chrome/browser/profiles/profile_io_data.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "components/pref_registry/pref_registry_syncable.h" |
| +#include "net/base/network_change_notifier.h" |
| + |
| +namespace { |
| + |
| +bool CanPredictNetworkActions(int AllowNetworkPrediction, |
| + bool NetworkPredictionEnabled) { |
| + switch (AllowNetworkPrediction) { |
| + case chrome_browser_net::Predictor::NETWORK_PREDICTION_ALWAYS: |
| + return true; |
| + case chrome_browser_net::Predictor::NETWORK_PREDICTION_WIFI_ONLY: |
| + return !net::NetworkChangeNotifier::IsConnectionCellular( |
| + net::NetworkChangeNotifier::GetConnectionType()); |
| + case chrome_browser_net::Predictor::NETWORK_PREDICTION_NEVER: |
| + return false; |
| + case chrome_browser_net::Predictor::NETWORK_PREDICTION_UNSET: |
| + return NetworkPredictionEnabled; |
| + default: |
| + // Unknown kAllowNetworkPrediction value, this should not happen. |
| + DCHECK(false); |
| + return false; |
|
jkarlin
2014/06/26 16:28:52
DCHECK(false) with:
NOTREACHED() << "Unknown kAllo
Bence
2014/06/26 20:02:06
Done.
|
| + } |
| +} |
| + |
| +} // anonymous namespace |
| + |
| +namespace chrome_browser_net { |
| + |
| +void RegisterPredictionHelperProfilePrefs( |
| + user_prefs::PrefRegistrySyncable* registry) { |
| + registry->RegisterIntegerPref( |
| + prefs::kAllowNetworkPrediction, |
| + chrome_browser_net::Predictor::NETWORK_PREDICTION_UNSET, |
| + user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| +} |
| + |
| +// To be executed on the IO thread only. |
| +bool CanPredictNetworkActionsIO(content::ResourceContext* resource_context) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| + ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
| + if (io_data == NULL) |
| + return false; |
| + return CanPredictNetworkActions( |
| + io_data->allow_network_prediction()->GetValue(), |
| + io_data->network_prediction_enabled()->GetValue()); |
| +} |
| + |
| +// To be executed on the UI thread only. |
| +bool CanPredictNetworkActionsUI(PrefService* prefs) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + return CanPredictNetworkActions( |
| + prefs->GetInteger(prefs::kAllowNetworkPrediction), |
| + prefs->GetBoolean(prefs::kNetworkPredictionEnabled)); |
| +} |
| + |
| +} // namespace chrome_browser_net |