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 "net/base/network_change_notifier.h" | |
14 | |
15 namespace { | |
16 | |
17 bool CanPredictNetworkActions(int NetworkPredictionOptions, | |
18 bool NetworkPredictionEnabled) { | |
19 switch (NetworkPredictionOptions) { | |
20 case chrome_browser_net::NETWORK_PREDICTION_ALWAYS: | |
21 return true; | |
22 case chrome_browser_net::NETWORK_PREDICTION_WIFI_ONLY: | |
23 return !net::NetworkChangeNotifier::IsConnectionCellular( | |
24 net::NetworkChangeNotifier::GetConnectionType()); | |
25 case chrome_browser_net::NETWORK_PREDICTION_NEVER: | |
26 return false; | |
27 case chrome_browser_net::NETWORK_PREDICTION_UNSET: | |
28 return NetworkPredictionEnabled; | |
29 default: | |
30 NOTREACHED() << "Unknown kNetworkPredictionOptions value."; | |
31 return false; | |
32 } | |
33 } | |
34 | |
35 } // namespace | |
36 | |
37 namespace chrome_browser_net { | |
38 | |
39 void RegisterPredictionOptionsProfilePrefs( | |
40 user_prefs::PrefRegistrySyncable* registry) { | |
41 registry->RegisterIntegerPref( | |
42 prefs::kNetworkPredictionOptions, | |
43 chrome_browser_net::NETWORK_PREDICTION_UNSET, | |
44 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | |
45 } | |
46 | |
47 bool CanPredictNetworkActionsIO(content::ResourceContext* resource_context) { | |
48 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.
| |
49 DCHECK(resource_context); | |
50 | |
51 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | |
52 return CanPredictNetworkActions( | |
53 io_data->network_prediction_options()->GetValue(), | |
54 io_data->network_prediction_enabled()->GetValue()); | |
55 } | |
56 | |
57 bool CanPredictNetworkActionsUI(PrefService* prefs) { | |
58 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
59 DCHECK(prefs); | |
60 return CanPredictNetworkActions( | |
61 prefs->GetInteger(prefs::kNetworkPredictionOptions), | |
62 prefs->GetBoolean(prefs::kNetworkPredictionEnabled)); | |
63 } | |
64 | |
65 } // namespace chrome_browser_net | |
OLD | NEW |