Chromium Code Reviews| 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/profiles/profile_io_data.h" | 9 #include "chrome/browser/profiles/profile_io_data.h" |
| 10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 namespace chrome_browser_net { | 39 namespace chrome_browser_net { |
| 40 | 40 |
| 41 void RegisterPredictionOptionsProfilePrefs( | 41 void RegisterPredictionOptionsProfilePrefs( |
| 42 user_prefs::PrefRegistrySyncable* registry) { | 42 user_prefs::PrefRegistrySyncable* registry) { |
| 43 registry->RegisterIntegerPref( | 43 registry->RegisterIntegerPref( |
| 44 prefs::kNetworkPredictionOptions, | 44 prefs::kNetworkPredictionOptions, |
| 45 chrome_browser_net::NETWORK_PREDICTION_UNSET, | 45 chrome_browser_net::NETWORK_PREDICTION_UNSET, |
| 46 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 46 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void MigrateNetworkPredictionUserPrefs(PrefService* pref_service) { | |
| 50 const PrefService::Preference* network_prediction_options = | |
| 51 pref_service->FindPreference(prefs::kNetworkPredictionOptions); | |
| 52 DCHECK(network_prediction_options); | |
| 53 | |
| 54 // Nothing to do if the user or this migration code has already set the new | |
| 55 // preference. | |
| 56 if (network_prediction_options->HasUserSetting()) | |
|
Bernhard Bauer
2014/08/07 08:32:17
You could directly use pref_service->IsUserModifia
bartfab (slow)
2014/08/07 12:17:06
HasUserSetting() and IsUserModifiablePreference()
Bernhard Bauer
2014/08/07 12:24:12
Urr, I meant pref_service->GetUserPrefValue().
Bence
2014/08/07 13:50:01
Done.
| |
| 57 return; | |
| 58 | |
| 59 const PrefService::Preference* network_prediction_enabled = | |
| 60 pref_service->FindPreference(prefs::kNetworkPredictionEnabled); | |
| 61 DCHECK(network_prediction_enabled); | |
| 62 | |
| 63 // Nothing to do if the user has not set the old preference. | |
| 64 if (!network_prediction_enabled->HasUserSetting()) | |
| 65 return; | |
| 66 | |
| 67 bool value; | |
|
battre
2014/08/07 07:56:52
please initialize.
Bence
2014/08/07 13:50:01
Done.
| |
| 68 if (network_prediction_enabled->GetUserValue()->GetAsBoolean(&value)) { | |
| 69 pref_service->SetInteger( | |
| 70 prefs::kNetworkPredictionOptions, | |
| 71 value ? chrome_browser_net::NETWORK_PREDICTION_WIFI_ONLY | |
| 72 : chrome_browser_net::NETWORK_PREDICTION_NEVER); | |
| 73 } | |
| 74 } | |
| 75 | |
| 49 bool CanPredictNetworkActionsIO(ProfileIOData* profile_io_data) { | 76 bool CanPredictNetworkActionsIO(ProfileIOData* profile_io_data) { |
| 50 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 77 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 51 DCHECK(profile_io_data); | 78 DCHECK(profile_io_data); |
| 52 | 79 |
| 53 return CanPredictNetworkActions( | 80 return CanPredictNetworkActions( |
| 54 profile_io_data->network_prediction_options()->GetValue(), | 81 profile_io_data->network_prediction_options()->GetValue(), |
| 55 profile_io_data->network_prediction_enabled()->GetValue()); | 82 profile_io_data->network_prediction_enabled()->GetValue()); |
| 56 } | 83 } |
| 57 | 84 |
| 58 bool CanPredictNetworkActionsUI(PrefService* prefs) { | 85 bool CanPredictNetworkActionsUI(PrefService* prefs) { |
| 59 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 86 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 60 DCHECK(prefs); | 87 DCHECK(prefs); |
| 61 return CanPredictNetworkActions( | 88 return CanPredictNetworkActions( |
| 62 prefs->GetInteger(prefs::kNetworkPredictionOptions), | 89 prefs->GetInteger(prefs::kNetworkPredictionOptions), |
| 63 prefs->GetBoolean(prefs::kNetworkPredictionEnabled)); | 90 prefs->GetBoolean(prefs::kNetworkPredictionEnabled)); |
| 64 } | 91 } |
| 65 | 92 |
| 66 } // namespace chrome_browser_net | 93 } // namespace chrome_browser_net |
| OLD | NEW |