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 "components/data_reduction_proxy/browser/data_reduction_proxy_prefs.h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_prefs.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_registry_simple.h" | 7 #include "base/prefs/pref_registry_simple.h" |
| 8 #include "base/prefs/pref_service.h" | |
| 9 #include "base/prefs/scoped_user_pref_update.h" | |
| 8 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names .h" | 10 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names .h" |
| 9 #include "components/pref_registry/pref_registry_syncable.h" | 11 #include "components/pref_registry/pref_registry_syncable.h" |
| 10 | 12 |
| 13 namespace { | |
| 14 | |
| 15 void CopyList(const char* pref_path, PrefService* src, PrefService* dest) { | |
|
marq (ping after 24h)
2014/10/15 08:29:35
Rename to CopyPrefList for clarity.
bengr
2014/10/15 22:52:51
Done.
| |
| 16 ListPrefUpdate update(dest, pref_path); | |
|
marq (ping after 24h)
2014/10/15 08:29:35
What happens if |pref_path| doesn't have a list va
bengr
2014/10/15 22:52:51
Done.
| |
| 17 scoped_ptr<base::ListValue> src_list(src->GetList(pref_path)->DeepCopy()); | |
| 18 update->Swap(src_list.get()); | |
|
mmenke
2014/10/15 15:49:34
Shouldn't we also be deleting the old values? Or
bengr
2014/10/15 22:52:51
Done.
| |
| 19 } | |
| 20 | |
| 21 } | |
|
mmenke
2014/10/15 15:49:34
nit:
} // namespace
bengr
2014/10/15 22:52:51
Done.
| |
| 22 | |
| 11 namespace data_reduction_proxy { | 23 namespace data_reduction_proxy { |
| 12 | 24 |
| 13 // Make sure any changes here that have the potential to impact android_webview | 25 // Make sure any changes here that have the potential to impact android_webview |
| 14 // are reflected in RegisterSimpleProfilePrefs. | 26 // are reflected in RegisterSimpleProfilePrefs. |
| 15 void RegisterSyncableProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { | 27 void RegisterSyncableProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { |
| 16 registry->RegisterBooleanPref( | 28 registry->RegisterBooleanPref( |
| 17 data_reduction_proxy::prefs::kDataReductionProxyEnabled, | 29 prefs::kDataReductionProxyEnabled, |
| 18 false, | 30 false, |
| 19 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 31 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 20 registry->RegisterBooleanPref( | 32 registry->RegisterBooleanPref( |
| 21 data_reduction_proxy::prefs::kDataReductionProxyAltEnabled, | 33 prefs::kDataReductionProxyAltEnabled, |
| 22 false, | 34 false, |
| 23 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 35 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 24 registry->RegisterBooleanPref( | 36 registry->RegisterBooleanPref( |
| 25 data_reduction_proxy::prefs::kDataReductionProxyWasEnabledBefore, | 37 prefs::kDataReductionProxyWasEnabledBefore, |
| 26 false, | 38 false, |
| 27 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 39 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 40 | |
| 41 registry->RegisterInt64Pref( | |
| 42 prefs::kHttpReceivedContentLength, | |
| 43 0, | |
| 44 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 45 registry->RegisterInt64Pref( | |
| 46 prefs::kHttpOriginalContentLength, | |
| 47 0, | |
| 48 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 49 | |
| 50 registry->RegisterBooleanPref( | |
| 51 prefs::kStatisticsPrefsMigrated, | |
| 52 false, | |
| 53 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 54 registry->RegisterListPref( | |
| 55 prefs::kDailyHttpOriginalContentLength, | |
| 56 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 57 registry->RegisterListPref( | |
| 58 prefs::kDailyHttpReceivedContentLength, | |
| 59 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 60 registry->RegisterListPref( | |
| 61 prefs::kDailyOriginalContentLengthWithDataReductionProxyEnabled, | |
| 62 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 63 registry->RegisterListPref( | |
| 64 prefs::kDailyContentLengthWithDataReductionProxyEnabled, | |
| 65 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 66 registry->RegisterListPref( | |
| 67 prefs::kDailyContentLengthHttpsWithDataReductionProxyEnabled, | |
| 68 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 69 registry->RegisterListPref( | |
| 70 prefs::kDailyContentLengthShortBypassWithDataReductionProxyEnabled, | |
| 71 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 72 registry->RegisterListPref( | |
| 73 prefs::kDailyContentLengthLongBypassWithDataReductionProxyEnabled, | |
| 74 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 75 registry->RegisterListPref( | |
| 76 prefs::kDailyContentLengthUnknownWithDataReductionProxyEnabled, | |
| 77 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 78 registry->RegisterListPref( | |
| 79 prefs::kDailyOriginalContentLengthViaDataReductionProxy, | |
| 80 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 81 registry->RegisterListPref( | |
| 82 prefs::kDailyContentLengthViaDataReductionProxy, | |
| 83 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 84 registry->RegisterInt64Pref( | |
| 85 prefs::kDailyHttpContentLengthLastUpdateDate, | |
| 86 0L, | |
| 87 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 28 } | 88 } |
| 29 | 89 |
| 30 void RegisterSimpleProfilePrefs(PrefRegistrySimple* registry) { | 90 void RegisterSimpleProfilePrefs(PrefRegistrySimple* registry) { |
| 31 registry->RegisterBooleanPref( | 91 registry->RegisterBooleanPref( |
| 32 data_reduction_proxy::prefs::kDataReductionProxyEnabled, false); | 92 prefs::kDataReductionProxyEnabled, false); |
| 33 registry->RegisterBooleanPref( | 93 registry->RegisterBooleanPref( |
| 34 data_reduction_proxy::prefs::kDataReductionProxyAltEnabled, false); | 94 prefs::kDataReductionProxyAltEnabled, false); |
| 35 registry->RegisterBooleanPref( | 95 registry->RegisterBooleanPref( |
| 36 data_reduction_proxy::prefs::kDataReductionProxyWasEnabledBefore, false); | 96 prefs::kDataReductionProxyWasEnabledBefore, false); |
| 97 | |
| 98 registry->RegisterBooleanPref( | |
| 99 prefs::kStatisticsPrefsMigrated, false); | |
| 100 RegisterPrefs(registry); | |
| 37 } | 101 } |
| 38 | 102 |
| 39 // Add any new data reduction proxy prefs to the |pref_map_| or the | 103 // Add any new data reduction proxy prefs to the |pref_map_| or the |
| 40 // |list_pref_map_| in Init() of DataReductionProxyStatisticsPrefs. | 104 // |list_pref_map_| in Init() of DataReductionProxyStatisticsPrefs. |
| 41 void RegisterPrefs(PrefRegistrySimple* registry) { | 105 void RegisterPrefs(PrefRegistrySimple* registry) { |
| 42 registry->RegisterInt64Pref( | 106 registry->RegisterInt64Pref( |
| 43 prefs::kHttpReceivedContentLength, 0); | 107 prefs::kHttpReceivedContentLength, 0); |
| 44 registry->RegisterInt64Pref( | 108 registry->RegisterInt64Pref( |
| 45 prefs::kHttpOriginalContentLength, 0); | 109 prefs::kHttpOriginalContentLength, 0); |
| 46 registry->RegisterListPref( | 110 registry->RegisterListPref( |
| 47 prefs::kDailyHttpOriginalContentLength); | 111 prefs::kDailyHttpOriginalContentLength); |
| 48 registry->RegisterListPref( | 112 registry->RegisterListPref( |
| 49 prefs::kDailyHttpReceivedContentLength); | 113 prefs::kDailyHttpReceivedContentLength); |
| 50 registry->RegisterListPref( | 114 registry->RegisterListPref( |
| 51 prefs::kDailyOriginalContentLengthWithDataReductionProxyEnabled); | 115 prefs::kDailyOriginalContentLengthWithDataReductionProxyEnabled); |
| 52 registry->RegisterListPref( | 116 registry->RegisterListPref( |
| 53 prefs::kDailyContentLengthWithDataReductionProxyEnabled); | 117 prefs::kDailyContentLengthWithDataReductionProxyEnabled); |
| 54 registry->RegisterListPref( | 118 registry->RegisterListPref( |
| 55 prefs::kDailyContentLengthHttpsWithDataReductionProxyEnabled); | 119 prefs::kDailyContentLengthHttpsWithDataReductionProxyEnabled); |
| 56 registry->RegisterListPref( | 120 registry->RegisterListPref( |
| 57 prefs::kDailyContentLengthShortBypassWithDataReductionProxyEnabled); | 121 prefs::kDailyContentLengthShortBypassWithDataReductionProxyEnabled); |
| 58 registry->RegisterListPref( | 122 registry->RegisterListPref( |
| 59 prefs::kDailyContentLengthLongBypassWithDataReductionProxyEnabled); | 123 prefs::kDailyContentLengthLongBypassWithDataReductionProxyEnabled); |
| 60 registry->RegisterListPref( | 124 registry->RegisterListPref( |
| 61 prefs::kDailyContentLengthUnknownWithDataReductionProxyEnabled); | 125 prefs::kDailyContentLengthUnknownWithDataReductionProxyEnabled); |
| 62 registry->RegisterListPref( | 126 registry->RegisterListPref( |
| 63 prefs::kDailyOriginalContentLengthViaDataReductionProxy); | 127 prefs::kDailyOriginalContentLengthViaDataReductionProxy); |
| 64 registry->RegisterListPref( | 128 registry->RegisterListPref( |
| 65 prefs::kDailyContentLengthViaDataReductionProxy); | 129 prefs::kDailyContentLengthViaDataReductionProxy); |
|
mmenke
2014/10/15 15:49:34
Should we still register all these prefs?
| |
| 66 registry->RegisterInt64Pref( | 130 registry->RegisterInt64Pref( |
| 67 prefs::kDailyHttpContentLengthLastUpdateDate, 0L); | 131 prefs::kDailyHttpContentLengthLastUpdateDate, 0L); |
| 68 } | 132 } |
| 69 | 133 |
| 134 void MigrateStatisticsPrefs(PrefService* local_state_prefs, | |
| 135 PrefService* profile_prefs) { | |
| 136 if (profile_prefs->GetBoolean(prefs::kStatisticsPrefsMigrated)) | |
| 137 return; | |
| 138 profile_prefs->SetInt64( | |
| 139 prefs::kHttpReceivedContentLength, | |
| 140 local_state_prefs->GetInt64(prefs::kHttpReceivedContentLength)); | |
| 141 profile_prefs->SetInt64( | |
| 142 prefs::kHttpOriginalContentLength, | |
| 143 local_state_prefs->GetInt64(prefs::kHttpOriginalContentLength)); | |
| 144 CopyList(prefs::kDailyHttpOriginalContentLength, | |
| 145 local_state_prefs, profile_prefs); | |
| 146 CopyList(prefs::kDailyHttpReceivedContentLength, | |
| 147 local_state_prefs, profile_prefs); | |
| 148 CopyList(prefs::kDailyOriginalContentLengthWithDataReductionProxyEnabled, | |
| 149 local_state_prefs, profile_prefs); | |
| 150 CopyList(prefs::kDailyContentLengthWithDataReductionProxyEnabled, | |
| 151 local_state_prefs, profile_prefs); | |
| 152 CopyList(prefs::kDailyContentLengthHttpsWithDataReductionProxyEnabled, | |
| 153 local_state_prefs, profile_prefs); | |
| 154 CopyList(prefs::kDailyContentLengthShortBypassWithDataReductionProxyEnabled, | |
| 155 local_state_prefs, profile_prefs); | |
| 156 CopyList(prefs::kDailyContentLengthLongBypassWithDataReductionProxyEnabled, | |
| 157 local_state_prefs, profile_prefs); | |
| 158 CopyList(prefs::kDailyContentLengthUnknownWithDataReductionProxyEnabled, | |
| 159 local_state_prefs, profile_prefs); | |
| 160 CopyList(prefs::kDailyOriginalContentLengthViaDataReductionProxy, | |
| 161 local_state_prefs, profile_prefs); | |
| 162 CopyList(prefs::kDailyContentLengthViaDataReductionProxy, | |
| 163 local_state_prefs, profile_prefs); | |
| 164 profile_prefs->SetInt64( | |
| 165 prefs::kDailyHttpContentLengthLastUpdateDate, | |
| 166 local_state_prefs->GetInt64( | |
| 167 prefs::kDailyHttpContentLengthLastUpdateDate)); | |
| 168 profile_prefs->SetBoolean(prefs::kStatisticsPrefsMigrated, true); | |
| 169 } | |
| 170 | |
| 70 } // namespace data_reduction_proxy | 171 } // namespace data_reduction_proxy |
| OLD | NEW |