Index: components/data_reduction_proxy/browser/data_reduction_proxy_statistics_prefs.h |
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_statistics_prefs.h b/components/data_reduction_proxy/browser/data_reduction_proxy_statistics_prefs.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..40aa74d03fe66b7e751502c8cc4735bd2cf53782 |
--- /dev/null |
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_statistics_prefs.h |
@@ -0,0 +1,96 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_STATISTICS_PREFS_H_ |
+#define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_STATISTICS_PREFS_H_ |
+ |
+#include <map> |
+ |
+#include "base/containers/scoped_ptr_hash_map.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/time/time.h" |
+#include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names.h" |
+ |
+class PrefService; |
+ |
+namespace base { |
+class ListValue; |
+class SequencedTaskRunner; |
+} |
+ |
+namespace data_reduction_proxy { |
+ |
+// Data reduction proxy delayed pref service reduces the number calls to pref |
+// service by storing prefs in memory and writing to the given PrefService after |
+// |delay| amount of time. If |delay| is zero, the delayed pref service writes |
+// directly to the PrefService and does not store the prefs in memory. All |
+// 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.
|
+class DataReductionProxyStatisticsPrefs { |
+public: |
+ typedef std::map<const char*, int64> DataReductionProxyPrefMap; |
+ typedef base::ScopedPtrHashMap<const char*, base::ListValue> |
+ DataReductionProxyListPrefMap; |
+ |
+ // Constructs a data reduction proxy delayed pref service object using |
+ // |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.
|
+ // 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.
|
+ // 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
|
+ DataReductionProxyStatisticsPrefs( |
+ PrefService* pref_service, |
+ scoped_refptr<base::SequencedTaskRunner> task_runner, |
+ base::TimeDelta delay); |
bengr
2014/08/27 04:53:25
const base::TimeDelta& delay
megjablon
2014/08/28 20:44:07
Done.
|
+ virtual ~DataReductionProxyStatisticsPrefs(); |
+ |
+ // Loads all data_reduction_proxy::prefs into the |pref_map_| and |
+ // |list_pref_map_|. |
+ void Init(); |
+ |
+ // Gets the value of |pref| from the pref service and adds it to the |
+ // |pref_map|. |
+ 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.
|
+ |
+ // Gets the value of |pref| from the pref service and adds it to the |
+ // |list_pref_map|. |
+ 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.
|
+ |
+ // Gets the int64 pref at |pref_path| from the |DataReductionProxyPrefMap|. |
+ 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.
|
+ |
+ // Updates the pref value in the |DataReductionProxyPrefMap| map. |
+ // The pref is later written to |pref service_|. |
+ void SetInt64(const char* pref_path, int64 pref_value); |
+ |
+ // Gets the pref list at |pref_path| from the |DataReductionProxyPrefMap|. |
+ base::ListValue* GetList(const char* pref_path); |
+ |
+private: |
+ // Writes the prefs stored in |DataReductionProxyPrefMap| and |
+ // |DataReductionProxyListPrefMap| to |pref_service|. |
+ void WritePrefs(); |
+ |
+ // Writes the stored prefs to |pref_service| and then posts another a delayed |
+ // task to write prefs again in |kMinutesBetweenWrites|. |
+ void WritePrefsAndPost(); |
+ |
+ // Copies the values at each index of |from_list| to the same index in |
+ // |to_list|. |
+ void TransferList(const base::ListValue& from_list, |
+ base::ListValue* to_list); |
+ |
+ // Gets an int64, stored as a string, in a ListPref at the specified |
+ // index. |
+ int64 GetListPrefInt64Value(const base::ListValue& list_update, size_t index); |
+ |
+ PrefService* pref_service_; |
+ scoped_refptr<base::SequencedTaskRunner> task_runner_; |
+ base::WeakPtrFactory<DataReductionProxyStatisticsPrefs> weak_factory_; |
+ base::TimeDelta delay_; |
bengr
2014/08/27 04:53:25
can this be const?
megjablon
2014/08/28 20:44:07
Done.
|
+ bool delayed_task_posted_; |
+ DataReductionProxyPrefMap pref_map_; |
+ DataReductionProxyListPrefMap list_pref_map_; |
+}; |
+ |
+} // namespace data_reduction_proxy |
bengr
2014/08/27 04:53:25
Add a space before //
megjablon
2014/08/28 20:44:08
Done.
|
+ |
+#endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_STATISTICS_PREFS_H_ |