OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/net/prediction_options.h" | 5 #include "chrome/browser/net/prediction_options.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "chrome/browser/net/predictor.h" | |
10 #include "chrome/browser/profiles/profile_io_data.h" | 9 #include "chrome/browser/profiles/profile_io_data.h" |
11 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
12 #include "components/pref_registry/pref_registry_syncable.h" | 11 #include "components/pref_registry/pref_registry_syncable.h" |
13 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
14 #include "net/base/network_change_notifier.h" | |
15 | 13 |
16 namespace { | 14 namespace { |
17 | 15 |
18 // Since looking up preferences and current network connection are presumably | 16 // Since looking up preferences and current network connection are presumably |
19 // both cheap, we do not cache them here. | 17 // both cheap, we do not cache them here. |
20 bool CanPredictNetworkActions(int NetworkPredictionOptions, | 18 bool CanPredictNetworkActions(int NetworkPredictionOptions, |
21 bool NetworkPredictionEnabled) { | 19 bool NetworkPredictionEnabled) { |
22 switch (NetworkPredictionOptions) { | 20 switch (NetworkPredictionOptions) { |
23 case chrome_browser_net::NETWORK_PREDICTION_ALWAYS: | 21 case chrome_browser_net::NETWORK_PREDICTION_ALWAYS: |
24 return true; | 22 return true; |
(...skipping 15 matching lines...) Expand all Loading... |
40 namespace chrome_browser_net { | 38 namespace chrome_browser_net { |
41 | 39 |
42 void RegisterPredictionOptionsProfilePrefs( | 40 void RegisterPredictionOptionsProfilePrefs( |
43 user_prefs::PrefRegistrySyncable* registry) { | 41 user_prefs::PrefRegistrySyncable* registry) { |
44 registry->RegisterIntegerPref( | 42 registry->RegisterIntegerPref( |
45 prefs::kNetworkPredictionOptions, | 43 prefs::kNetworkPredictionOptions, |
46 chrome_browser_net::NETWORK_PREDICTION_UNSET, | 44 chrome_browser_net::NETWORK_PREDICTION_UNSET, |
47 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 45 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
48 } | 46 } |
49 | 47 |
50 bool CanPredictNetworkActionsIO(content::ResourceContext* resource_context) { | 48 bool CanPredictNetworkActionsIO(ProfileIOData* profile_io_data) { |
51 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 49 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
52 DCHECK(resource_context); | 50 DCHECK(profile_io_data); |
53 | 51 |
54 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | |
55 return CanPredictNetworkActions( | 52 return CanPredictNetworkActions( |
56 io_data->network_prediction_options()->GetValue(), | 53 profile_io_data->network_prediction_options()->GetValue(), |
57 io_data->network_prediction_enabled()->GetValue()); | 54 profile_io_data->network_prediction_enabled()->GetValue()); |
58 } | 55 } |
59 | 56 |
60 bool CanPredictNetworkActionsUI(PrefService* prefs) { | 57 bool CanPredictNetworkActionsUI(PrefService* prefs) { |
61 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 58 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
62 DCHECK(prefs); | 59 DCHECK(prefs); |
63 return CanPredictNetworkActions( | 60 return CanPredictNetworkActions( |
64 prefs->GetInteger(prefs::kNetworkPredictionOptions), | 61 prefs->GetInteger(prefs::kNetworkPredictionOptions), |
65 prefs->GetBoolean(prefs::kNetworkPredictionEnabled)); | 62 prefs->GetBoolean(prefs::kNetworkPredictionEnabled)); |
66 } | 63 } |
67 | 64 |
68 } // namespace chrome_browser_net | 65 } // namespace chrome_browser_net |
OLD | NEW |