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 "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h"
6 
7 #include <memory>
8 
9 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
10 #include "components/pref_registry/pref_registry_syncable.h"
11 #include "components/prefs/pref_registry_simple.h"
12 #include "components/prefs/pref_service.h"
13 #include "components/prefs/scoped_user_pref_update.h"
14 
15 namespace data_reduction_proxy {
16 
17 // Make sure any changes here that have the potential to impact android_webview
18 // are reflected in RegisterSimpleProfilePrefs.
RegisterSyncableProfilePrefs(user_prefs::PrefRegistrySyncable * registry)19 void RegisterSyncableProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
20   registry->RegisterBooleanPref(prefs::kDataSaverEnabled, false);
21   registry->RegisterBooleanPref(prefs::kDataReductionProxyWasEnabledBefore,
22                                 false);
23 
24   registry->RegisterInt64Pref(prefs::kDataReductionProxyLastEnabledTime, 0L);
25 
26   registry->RegisterBooleanPref(prefs::kDataUsageReportingEnabled, false);
27 
28   registry->RegisterInt64Pref(prefs::kHttpReceivedContentLength, 0);
29   registry->RegisterInt64Pref(prefs::kHttpOriginalContentLength, 0);
30 
31   registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength);
32 
33   registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength);
34 
35   registry->RegisterInt64Pref(prefs::kDailyHttpContentLengthLastUpdateDate, 0L);
36   registry->RegisterStringPref(prefs::kDataReductionProxyConfig, std::string());
37   registry->RegisterInt64Pref(prefs::kDataReductionProxyLastConfigRetrievalTime,
38                               0L);
39 
40   registry->RegisterIntegerPref(prefs::kThisWeekNumber, false);
41   registry->RegisterDictionaryPref(
42       prefs::kThisWeekServicesDownstreamBackgroundKB, PrefRegistry::LOSSY_PREF);
43   registry->RegisterDictionaryPref(
44       prefs::kThisWeekServicesDownstreamForegroundKB, PrefRegistry::LOSSY_PREF);
45   registry->RegisterDictionaryPref(
46       prefs::kLastWeekServicesDownstreamBackgroundKB, PrefRegistry::LOSSY_PREF);
47   registry->RegisterDictionaryPref(
48       prefs::kLastWeekServicesDownstreamForegroundKB, PrefRegistry::LOSSY_PREF);
49   registry->RegisterDictionaryPref(
50       prefs::kThisWeekUserTrafficContentTypeDownstreamKB,
51       PrefRegistry::LOSSY_PREF);
52   registry->RegisterDictionaryPref(
53       prefs::kLastWeekUserTrafficContentTypeDownstreamKB,
54       PrefRegistry::LOSSY_PREF);
55 }
56 
RegisterSimpleProfilePrefs(PrefRegistrySimple * registry)57 void RegisterSimpleProfilePrefs(PrefRegistrySimple* registry) {
58   registry->RegisterBooleanPref(
59       prefs::kDataReductionProxyWasEnabledBefore, false);
60 
61   registry->RegisterBooleanPref(prefs::kDataUsageReportingEnabled, false);
62   RegisterPrefs(registry);
63 }
64 
65 // Add any new data reduction proxy prefs to the |pref_map_| or the
66 // |list_pref_map_| in Init() of DataReductionProxyCompressionStats.
RegisterPrefs(PrefRegistrySimple * registry)67 void RegisterPrefs(PrefRegistrySimple* registry) {
68   registry->RegisterStringPref(prefs::kDataReductionProxy, std::string());
69   registry->RegisterInt64Pref(prefs::kDataReductionProxyLastEnabledTime, 0L);
70   registry->RegisterInt64Pref(prefs::kHttpReceivedContentLength, 0);
71   registry->RegisterInt64Pref(
72       prefs::kHttpOriginalContentLength, 0);
73   registry->RegisterListPref(
74       prefs::kDailyHttpOriginalContentLength);
75   registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength);
76   registry->RegisterInt64Pref(
77       prefs::kDailyHttpContentLengthLastUpdateDate, 0L);
78   registry->RegisterStringPref(prefs::kDataReductionProxyConfig, std::string());
79   registry->RegisterInt64Pref(prefs::kDataReductionProxyLastConfigRetrievalTime,
80                               0L);
81 
82   registry->RegisterIntegerPref(prefs::kThisWeekNumber, false);
83   registry->RegisterDictionaryPref(
84       prefs::kThisWeekServicesDownstreamBackgroundKB, PrefRegistry::LOSSY_PREF);
85   registry->RegisterDictionaryPref(
86       prefs::kThisWeekServicesDownstreamForegroundKB, PrefRegistry::LOSSY_PREF);
87   registry->RegisterDictionaryPref(
88       prefs::kLastWeekServicesDownstreamBackgroundKB, PrefRegistry::LOSSY_PREF);
89   registry->RegisterDictionaryPref(
90       prefs::kLastWeekServicesDownstreamForegroundKB, PrefRegistry::LOSSY_PREF);
91   registry->RegisterDictionaryPref(
92       prefs::kThisWeekUserTrafficContentTypeDownstreamKB,
93       PrefRegistry::LOSSY_PREF);
94   registry->RegisterDictionaryPref(
95       prefs::kLastWeekUserTrafficContentTypeDownstreamKB,
96       PrefRegistry::LOSSY_PREF);
97 }
98 
99 }  // namespace data_reduction_proxy
100