Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_statistics_prefs.h

Issue 473723002: Update data reduction proxy statistics prefs less often on desktop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tooManyWritesPatch
Patch Set: Fixing net internals bandwidth page Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/macros.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/time/time.h"
14 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names .h"
15
16 class PrefService;
17
18 namespace base {
19 class ListValue;
20 class SequencedTaskRunner;
21 }
22
23 namespace data_reduction_proxy {
24
25 // Data reduction proxy delayed pref service reduces the number calls to pref
26 // service by storing prefs in memory and writing to the given PrefService after
27 // |delay| amount of time. If |delay| is zero, the delayed pref service writes
28 // directly to the PrefService and does not store the prefs in memory. All
29 // variables must be stored and read on the UI thread.
30 class DataReductionProxyStatisticsPrefs {
31 public:
32 typedef std::map<const char*, int64> DataReductionProxyPrefMap;
33 typedef base::ScopedPtrHashMap<const char*, base::ListValue>
34 DataReductionProxyListPrefMap;
mmenke 2014/09/15 15:11:02 These should be in the private section, since they
megjablon 2014/09/15 18:19:24 Done.
35
36 // Constructs a data reduction proxy delayed pref service object using
37 // |pref_service|. Writes prefs to |pref_service| after |delay|
38 // and stores them in |pref_map_| and |list_pref_map| between writes.
39 // If |delay| is zero, writes directly to the PrefService and does not store
40 // in the maps.
41 DataReductionProxyStatisticsPrefs(
42 PrefService* pref_service,
43 scoped_refptr<base::SequencedTaskRunner> task_runner,
44 const base::TimeDelta& delay);
45 virtual ~DataReductionProxyStatisticsPrefs();
mmenke 2014/09/15 15:11:02 virtual not needed, since nothing inherits from th
megjablon 2014/09/15 18:19:23 Done.
46
47 // Loads all data_reduction_proxy::prefs into the |pref_map_| and
48 // |list_pref_map_|.
49 void Init();
50
51 // Gets the int64 pref at |pref_path| from the |DataReductionProxyPrefMap|.
52 int64 GetInt64(const char* pref_path);
53
54 // Updates the pref value in the |DataReductionProxyPrefMap| map.
55 // The pref is later written to |pref service_|.
56 void SetInt64(const char* pref_path, int64 pref_value);
57
58 // Gets the pref list at |pref_path| from the |DataReductionProxyPrefMap|.
59 base::ListValue* GetList(const char* pref_path);
60
61 // Writes the prefs stored in |DataReductionProxyPrefMap| and
62 // |DataReductionProxyListPrefMap| to |pref_service|.
63 void WritePrefs();
64
65 private:
66 // Gets the value of |pref| from the pref service and adds it to the
67 // |pref_map|.
68 void InitInt64Pref(const char* pref);
69
70 // Gets the value of |pref| from the pref service and adds it to the
71 // |list_pref_map|.
72 void InitListPref(const char* pref);
73
74 // Writes the stored prefs to |pref_service| and then posts another a delayed
75 // task to write prefs again in |kMinutesBetweenWrites|.
76 void WritePrefsAndPost();
77
78 // Copies the values at each index of |from_list| to the same index in
79 // |to_list|.
80 void TransferList(const base::ListValue& from_list,
81 base::ListValue* to_list);
82
83 // Gets an int64, stored as a string, in a ListPref at the specified
84 // index.
85 int64 GetListPrefInt64Value(const base::ListValue& list_update, size_t index);
86
87 PrefService* pref_service_;
88 scoped_refptr<base::SequencedTaskRunner> task_runner_;
mmenke 2014/09/15 15:11:02 Should include ref_counted.h for this.
megjablon 2014/09/15 18:19:23 Done.
89 base::WeakPtrFactory<DataReductionProxyStatisticsPrefs> weak_factory_;
90 const base::TimeDelta delay_;
91 bool delayed_task_posted_;
92 DataReductionProxyPrefMap pref_map_;
93 DataReductionProxyListPrefMap list_pref_map_;
94
95 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyStatisticsPrefs);
96 };
97
98 } // namespace data_reduction_proxy
99
100 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_STATISTI CS_PREFS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698