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

Unified Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.h

Issue 1054363002: Update DataReductionProxyNetworkDelegate/BypassStats to post tasks safely. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bengr CR comments Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.h
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.h
index 199029512d126c3750bdcf934f5c97024cbc8fcc..297f810093c9efc43c986125f539b30aadc65c9b 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.h
@@ -13,6 +13,7 @@
#include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h"
#include "base/time/time.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metrics.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
class PrefChangeRegistrar;
@@ -44,41 +45,49 @@ class DataReductionProxyCompressionStats {
const base::TimeDelta& delay);
~DataReductionProxyCompressionStats();
- // Loads all data_reduction_proxy::prefs into the |pref_map_| and
- // |list_pref_map_|.
- void Init();
-
- void OnUpdateContentLengths();
-
- // Gets the int64 pref at |pref_path| from the |DataReductionProxyPrefMap|.
- int64 GetInt64(const char* pref_path);
-
- // 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);
-
- // Writes the prefs stored in |DataReductionProxyPrefMap| and
- // |DataReductionProxyListPrefMap| to |pref_service|.
- void WritePrefs();
+ // Records daily data savings statistics to prefs and reports data savings
+ // UMA.
+ void UpdateContentLengths(int received_content_length,
+ int original_content_length,
+ bool data_reduction_proxy_enabled,
+ DataReductionProxyRequestType request_type);
// Creates a |Value| summary of the persistent state of the network session.
// The caller is responsible for deleting the returned value.
// Must be called on the UI thread.
base::Value* HistoricNetworkStatsInfoToValue();
+ // Returns the time in milliseconds since epoch that the last update was made
+ // to the daily original and received content lengths.
+ int64 GetLastUpdateTime();
+
+ // Resets daily content length statistics.
+ void ResetStatistics();
+
// Clears all data saving statistics.
void ClearDataSavingStatistics();
- base::WeakPtr<DataReductionProxyCompressionStats> GetWeakPtr();
+ // Returns a list of all the daily content lengths.
+ ContentLengthList GetDailyContentLengths(const char* pref_name);
+
+ // Returns aggregate received and original content lengths over the specified
+ // number of days, as well as the time these stats were last updated.
+ void GetContentLengths(unsigned int days,
+ int64* original_content_length,
+ int64* received_content_length,
+ int64* last_update_time);
private:
+ friend class DataReductionProxyCompressionStatsTest;
+
typedef std::map<const char*, int64> DataReductionProxyPrefMap;
typedef base::ScopedPtrHashMap<const char*, base::ListValue>
DataReductionProxyListPrefMap;
+ // 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);
@@ -87,6 +96,22 @@ class DataReductionProxyCompressionStats {
// |list_pref_map|.
void InitListPref(const char* pref);
+ void OnUpdateContentLengths();
+
+ // Gets the int64 pref at |pref_path| from the |DataReductionProxyPrefMap|.
+ int64 GetInt64(const char* pref_path);
+
+ // 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);
+
+ // 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 DelayedWritePrefs();
@@ -100,6 +125,14 @@ class DataReductionProxyCompressionStats {
// index.
int64 GetListPrefInt64Value(const base::ListValue& list_update, size_t index);
+ // Records content length updates to prefs.
+ void RecordContentLengthPrefs(
+ int received_content_length,
+ int original_content_length,
+ bool with_data_reduction_proxy_enabled,
+ DataReductionProxyRequestType request_type,
+ base::Time now);
+
PrefService* pref_service_;
scoped_refptr<base::SequencedTaskRunner> task_runner_;
const base::TimeDelta delay_;

Powered by Google App Engine
This is Rietveld 408576698