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 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_STATISTICS_ PREFS_H_ | |
6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_STATISTICS_ PREFS_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/containers/scoped_ptr_hash_map.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "base/time/time.h" | |
13 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names .h" | |
14 | |
15 class PrefService; | |
16 | |
17 namespace base { | |
18 class ListValue; | |
19 class SequencedTaskRunner; | |
20 } | |
21 | |
22 namespace data_reduction_proxy { | |
23 | |
24 // Data reduction proxy delayed pref service reduces the number calls to pref | |
25 // service by storing prefs in memory and writing to the given PrefService after | |
26 // |delay| amount of time. If |delay| is zero, the delayed pref service writes | |
27 // directly to the PrefService and does not store the prefs in memory. All | |
28 // variables should be stored and read on the UI thread. | |
bengr
2014/08/27 04:53:26
must be
megjablon
2014/08/28 20:44:07
Done.
| |
29 class DataReductionProxyStatisticsPrefs { | |
30 public: | |
31 typedef std::map<const char*, int64> DataReductionProxyPrefMap; | |
32 typedef base::ScopedPtrHashMap<const char*, base::ListValue> | |
33 DataReductionProxyListPrefMap; | |
34 | |
35 // Constructs a data reduction proxy delayed pref service object using | |
36 // |pref_service|. Writes prefs to |pref_service| after |delay| amount of time | |
bengr
2014/08/27 04:53:25
Remove "amount of time"
megjablon
2014/08/28 20:44:08
Done.
| |
37 // and stores in |pref_map_| and |list_pref_map| between writes. If |delay| is | |
bengr
2014/08/27 04:53:26
stores them in
list_pref_map_
megjablon
2014/08/28 20:44:08
Done.
| |
38 // zero, writes directly to the PrefService and does not store in the maps. | |
bengr
2014/08/27 04:53:26
Somewhere in this class add a reference to a bug a
megjablon
2014/08/28 20:44:08
I added this in profile impl where I decide the co
| |
39 DataReductionProxyStatisticsPrefs( | |
40 PrefService* pref_service, | |
41 scoped_refptr<base::SequencedTaskRunner> task_runner, | |
42 base::TimeDelta delay); | |
bengr
2014/08/27 04:53:25
const base::TimeDelta& delay
megjablon
2014/08/28 20:44:07
Done.
| |
43 virtual ~DataReductionProxyStatisticsPrefs(); | |
44 | |
45 // Loads all data_reduction_proxy::prefs into the |pref_map_| and | |
46 // |list_pref_map_|. | |
47 void Init(); | |
48 | |
49 // Gets the value of |pref| from the pref service and adds it to the | |
50 // |pref_map|. | |
51 void InitInt64Pref(const char* pref); | |
bengr
2014/08/27 04:53:26
Does this need to be public?
megjablon
2014/08/28 20:44:08
This makes it much simpler for testing purposes. O
bengr
2014/08/28 21:38:34
You can friend your tests.
| |
52 | |
53 // Gets the value of |pref| from the pref service and adds it to the | |
54 // |list_pref_map|. | |
55 void InitListPref(const char* pref); | |
bengr
2014/08/27 04:53:26
Does this need to be public?
megjablon
2014/08/28 20:44:08
See above
bengr
2014/08/28 21:38:34
See above.
| |
56 | |
57 // Gets the int64 pref at |pref_path| from the |DataReductionProxyPrefMap|. | |
58 int64 GetInt64(const char* pref_path); | |
bengr
2014/08/27 04:53:25
Can this function be const?
megjablon
2014/08/28 20:44:07
Done.
| |
59 | |
60 // Updates the pref value in the |DataReductionProxyPrefMap| map. | |
61 // The pref is later written to |pref service_|. | |
62 void SetInt64(const char* pref_path, int64 pref_value); | |
63 | |
64 // Gets the pref list at |pref_path| from the |DataReductionProxyPrefMap|. | |
65 base::ListValue* GetList(const char* pref_path); | |
66 | |
67 private: | |
68 // Writes the prefs stored in |DataReductionProxyPrefMap| and | |
69 // |DataReductionProxyListPrefMap| to |pref_service|. | |
70 void WritePrefs(); | |
71 | |
72 // Writes the stored prefs to |pref_service| and then posts another a delayed | |
73 // task to write prefs again in |kMinutesBetweenWrites|. | |
74 void WritePrefsAndPost(); | |
75 | |
76 // Copies the values at each index of |from_list| to the same index in | |
77 // |to_list|. | |
78 void TransferList(const base::ListValue& from_list, | |
79 base::ListValue* to_list); | |
80 | |
81 // Gets an int64, stored as a string, in a ListPref at the specified | |
82 // index. | |
83 int64 GetListPrefInt64Value(const base::ListValue& list_update, size_t index); | |
84 | |
85 PrefService* pref_service_; | |
86 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
87 base::WeakPtrFactory<DataReductionProxyStatisticsPrefs> weak_factory_; | |
88 base::TimeDelta delay_; | |
bengr
2014/08/27 04:53:25
can this be const?
megjablon
2014/08/28 20:44:07
Done.
| |
89 bool delayed_task_posted_; | |
90 DataReductionProxyPrefMap pref_map_; | |
91 DataReductionProxyListPrefMap list_pref_map_; | |
92 }; | |
93 | |
94 } // namespace data_reduction_proxy | |
bengr
2014/08/27 04:53:25
Add a space before //
megjablon
2014/08/28 20:44:08
Done.
| |
95 | |
96 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_STATISTI CS_PREFS_H_ | |
OLD | NEW |