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

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_delayed_pref_service.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: Created 6 years, 4 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_DELAYED_PRE F_SERVICE_H_
6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_DELAYED_PRE F_SERVICE_H_
7
8 #include <map>
9
10 #include "base/memory/weak_ptr.h"
bengr 2014/08/14 17:39:42 #include "base/time/time.h" here and remove the fo
megjablon 2014/08/26 19:28:41 Done.
11
12 class PrefService;
13
14 namespace base {
15 class ListValue;
bengr 2014/08/14 17:39:42 remove indent.
megjablon 2014/08/26 19:28:41 Done.
16 class SequencedTaskRunner;
17 class TimeDelta;
18 }
19
20 namespace data_reduction_proxy {
21
22 // Data reduction proxy delayed pref service reduces the number calls to pref
23 // service by storing prefs in memory and writing to the given PrefService after
24 // |delay| amount of time. If |delay| is zero, the delayed pref service writes
25 // directly to the PrefService and does not store the prefs in memory. All
26 // variables are stored and should be read on the UI thread.
bengr 2014/08/14 17:39:42 should be stored and read...
megjablon 2014/08/26 19:28:41 Done.
27 class DataReductionProxyDelayedPrefService
28 : public base::SupportsWeakPtr<DataReductionProxyDelayedPrefService>{
29 public:
30 typedef std::map<const char*, int64> DataReductionProxyPrefMap;
31 typedef std::map<const char*, base::ListValue*>
32 DataReductionProxyListPrefMap;
bengr 2014/08/14 17:39:42 indent 4
megjablon 2014/08/26 19:28:41 Done.
33
34 // Constructs a data reduction proxy delayed pref service object using
35 // |pref_service|. Writes prefs to |pref_service| after |delay| amount of time
36 // and stores in |pref_map_| and |list_pref_map| between writes. If |delay| is
37 // zero, writes directly to the PrefService and does not store in the maps.
38 DataReductionProxyDelayedPrefService(
39 PrefService* pref_service,
40 scoped_refptr<base::SequencedTaskRunner> task_runner,
41 base::TimeDelta delay);
42 virtual ~DataReductionProxyDelayedPrefService();
43
44 // Gets the int64 pref at |pref_path| from the |DataReductionProxyPrefMap|.
45 // If |pref_path| is not in the map, gets the pref from |pref_service_| and
46 // stores it in the map.
47 int64 GetInt64(const char* pref_path);
48
49 // Updates the pref value in the |DataReductionProxyPrefMap| map. If
50 // |pref_path| is not in the map, gets the pref from |pref_service_| and
51 // stores it in the map. The pref is later written to |pref service_|.
52 void SetInt64(const char* pref_path, int64 pref_value);
53
54 // Gets the pref list at |pref_path| from the |DataReductionProxyPrefMap|.
55 // If |pref_path| is not in the map, gets the pref from |pref_service_| and
56 // stores it in the map.
57 base::ListValue* GetList(const char* pref_path);
58
59 private:
60 // Writes the prefs stored in |DataReductionProxyPrefMap| and
61 // |DataReductionProxyListPrefMap| to |pref_service|.
62 void WritePrefs();
63
64 // Writes the stored prefs to |pref_service| and then posts another a delayed
65 // task to write prefs again in |kMinutesBetweenWrites|.
66 void WritePrefsAndPost();
67
68 // Copies the values at each index of |from_list| to the same index in
69 // |to_list|.
70 void TransferList(const base::ListValue& from_list,
71 base::ListValue* to_list);
72
73 // Gets an int64, stored as a string, in a ListPref at the specified
74 // index.
75 int64 GetListPrefInt64Value(const base::ListValue& list_update, size_t index);
76
77 PrefService* pref_service_;
78 scoped_refptr<base::SequencedTaskRunner> task_runner_;
79 base::TimeDelta delay_;
80 bool delayed_task_posted_;
81 DataReductionProxyPrefMap* pref_map_;
bengr 2014/08/14 17:39:42 Why do these need to be pointers?
megjablon 2014/08/26 19:28:41 Done.
82 DataReductionProxyListPrefMap* list_pref_map_;
83 };
84
85 } // namespace data_reduction_proxy
86
87 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_DELAYED_ PREF_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698