OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 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_helper.h" | |
6 | |
7 #include "base/prefs/pref_service.h" | |
8 #include "chrome/browser/net/predictor.h" | |
9 #include "chrome/browser/profiles/profile_io_data.h" | |
10 #include "chrome/common/pref_names.h" | |
11 #include "components/pref_registry/pref_registry_syncable.h" | |
12 #include "net/base/network_change_notifier.h" | |
13 | |
14 namespace { | |
15 | |
16 bool CanPredictNetworkActions(int AllowNetworkPrediction, | |
17 bool NetworkPredictionEnabled) { | |
18 switch (AllowNetworkPrediction) { | |
19 case chrome_browser_net::Predictor::NETWORK_PREDICTION_ALWAYS: | |
20 return true; | |
21 case chrome_browser_net::Predictor::NETWORK_PREDICTION_WIFI_ONLY: | |
22 return !net::NetworkChangeNotifier::IsConnectionCellular( | |
23 net::NetworkChangeNotifier::GetConnectionType()); | |
24 case chrome_browser_net::Predictor::NETWORK_PREDICTION_NEVER: | |
25 return false; | |
26 case chrome_browser_net::Predictor::NETWORK_PREDICTION_UNSET: | |
27 return NetworkPredictionEnabled; | |
28 default: | |
29 // Unknown kAllowNetworkPrediction value, this should not happen. | |
30 DCHECK(false); | |
31 return false; | |
jkarlin
2014/06/26 16:28:52
DCHECK(false) with:
NOTREACHED() << "Unknown kAllo
Bence
2014/06/26 20:02:06
Done.
| |
32 } | |
33 } | |
34 | |
35 } // anonymous namespace | |
36 | |
37 namespace chrome_browser_net { | |
38 | |
39 void RegisterPredictionHelperProfilePrefs( | |
40 user_prefs::PrefRegistrySyncable* registry) { | |
41 registry->RegisterIntegerPref( | |
42 prefs::kAllowNetworkPrediction, | |
43 chrome_browser_net::Predictor::NETWORK_PREDICTION_UNSET, | |
44 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | |
45 } | |
46 | |
47 // To be executed on the IO thread only. | |
48 bool CanPredictNetworkActionsIO(content::ResourceContext* resource_context) { | |
49 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
50 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | |
51 if (io_data == NULL) | |
52 return false; | |
53 return CanPredictNetworkActions( | |
54 io_data->allow_network_prediction()->GetValue(), | |
55 io_data->network_prediction_enabled()->GetValue()); | |
56 } | |
57 | |
58 // To be executed on the UI thread only. | |
59 bool CanPredictNetworkActionsUI(PrefService* prefs) { | |
60 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
61 return CanPredictNetworkActions( | |
62 prefs->GetInteger(prefs::kAllowNetworkPrediction), | |
63 prefs->GetBoolean(prefs::kNetworkPredictionEnabled)); | |
64 } | |
65 | |
66 } // namespace chrome_browser_net | |
OLD | NEW |