Chromium Code Reviews| Index: chrome/browser/net/prediction_options.cc |
| diff --git a/chrome/browser/net/prediction_options.cc b/chrome/browser/net/prediction_options.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bdbc6ca61a4542a4b9cbd3493c3a4796867c8ce4 |
| --- /dev/null |
| +++ b/chrome/browser/net/prediction_options.cc |
| @@ -0,0 +1,65 @@ |
| +// Copyright 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_options.h" |
| + |
| +#include "base/logging.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 NetworkPredictionOptions, |
| + bool NetworkPredictionEnabled) { |
| + switch (NetworkPredictionOptions) { |
| + case chrome_browser_net::NETWORK_PREDICTION_ALWAYS: |
| + return true; |
| + case chrome_browser_net::NETWORK_PREDICTION_WIFI_ONLY: |
| + return !net::NetworkChangeNotifier::IsConnectionCellular( |
| + net::NetworkChangeNotifier::GetConnectionType()); |
| + case chrome_browser_net::NETWORK_PREDICTION_NEVER: |
| + return false; |
| + case chrome_browser_net::NETWORK_PREDICTION_UNSET: |
| + return NetworkPredictionEnabled; |
| + default: |
| + NOTREACHED() << "Unknown kNetworkPredictionOptions value."; |
| + return false; |
| + } |
| +} |
| + |
| +} // namespace |
| + |
| +namespace chrome_browser_net { |
| + |
| +void RegisterPredictionOptionsProfilePrefs( |
| + user_prefs::PrefRegistrySyncable* registry) { |
| + registry->RegisterIntegerPref( |
| + prefs::kNetworkPredictionOptions, |
| + chrome_browser_net::NETWORK_PREDICTION_UNSET, |
| + user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| +} |
| + |
| +bool CanPredictNetworkActionsIO(content::ResourceContext* resource_context) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
|
mmenke
2014/06/27 18:52:05
include browser_thread.h
Bence
2014/06/27 19:10:24
Done.
|
| + DCHECK(resource_context); |
| + |
| + ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
| + return CanPredictNetworkActions( |
| + io_data->network_prediction_options()->GetValue(), |
| + io_data->network_prediction_enabled()->GetValue()); |
| +} |
| + |
| +bool CanPredictNetworkActionsUI(PrefService* prefs) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + DCHECK(prefs); |
| + return CanPredictNetworkActions( |
| + prefs->GetInteger(prefs::kNetworkPredictionOptions), |
| + prefs->GetBoolean(prefs::kNetworkPredictionEnabled)); |
| +} |
| + |
| +} // namespace chrome_browser_net |