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

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 BUILD.gn and includes 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/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 must be stored and read on the UI thread.
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|
37 // and stores them in |pref_map_| and |list_pref_map| between writes.
38 // If |delay| is zero, writes directly to the PrefService and does not store
39 // in the maps.
40 DataReductionProxyStatisticsPrefs(
41 PrefService* pref_service,
42 scoped_refptr<base::SequencedTaskRunner> task_runner,
43 const base::TimeDelta& delay);
44 virtual ~DataReductionProxyStatisticsPrefs();
45
46 // Loads all data_reduction_proxy::prefs into the |pref_map_| and
47 // |list_pref_map_|.
48 void Init();
49
50 // Gets the int64 pref at |pref_path| from the |DataReductionProxyPrefMap|.
51 int64 GetInt64(const char* pref_path);
52
53 // Updates the pref value in the |DataReductionProxyPrefMap| map.
54 // The pref is later written to |pref service_|.
55 void SetInt64(const char* pref_path, int64 pref_value);
56
57 // Gets the pref list at |pref_path| from the |DataReductionProxyPrefMap|.
58 base::ListValue* GetList(const char* pref_path);
59
60 private:
61 // Gets the value of |pref| from the pref service and adds it to the
62 // |pref_map|.
63 void InitInt64Pref(const char* pref);
64
65 // Gets the value of |pref| from the pref service and adds it to the
66 // |list_pref_map|.
67 void InitListPref(const char* pref);
68
69 // Writes the prefs stored in |DataReductionProxyPrefMap| and
70 // |DataReductionProxyListPrefMap| to |pref_service|.
71 void WritePrefs();
72
73 // Writes the stored prefs to |pref_service| and then posts another a delayed
74 // task to write prefs again in |kMinutesBetweenWrites|.
75 void WritePrefsAndPost();
76
77 // Copies the values at each index of |from_list| to the same index in
78 // |to_list|.
79 void TransferList(const base::ListValue& from_list,
80 base::ListValue* to_list);
81
82 // Gets an int64, stored as a string, in a ListPref at the specified
83 // index.
84 int64 GetListPrefInt64Value(const base::ListValue& list_update, size_t index);
85
86 PrefService* pref_service_;
87 scoped_refptr<base::SequencedTaskRunner> task_runner_;
88 base::WeakPtrFactory<DataReductionProxyStatisticsPrefs> weak_factory_;
89 const base::TimeDelta delay_;
90 bool delayed_task_posted_;
91 DataReductionProxyPrefMap pref_map_;
92 DataReductionProxyListPrefMap list_pref_map_;
bengr 2014/09/09 02:09:40 Add: DISALLOW_COPY_AND_ASSIGN(DataReductionProxySt
megjablon 2014/09/09 18:52:23 Done.
93 };
94
95 } // namespace data_reduction_proxy
96
97 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_STATISTI CS_PREFS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698