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 ca6644ca7a004c895dc0c5d86ee3d2a1726cf1d5..4405aa624791fe7dfa4e323a678b4536bf766f00 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 |
@@ -15,59 +15,65 @@ |
#include "base/containers/scoped_ptr_hash_map.h" |
#include "base/macros.h" |
#include "base/memory/ref_counted.h" |
#include "base/memory/weak_ptr.h" |
#include "base/threading/thread_checker.h" |
#include "base/time/time.h" |
#include "base/timer/timer.h" |
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metrics.h" |
#include "components/data_reduction_proxy/core/browser/db_data_owner.h" |
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h" |
+#include "components/data_reduction_proxy/core/common/data_savings_recorder.h" |
#include "components/prefs/pref_member.h" |
class PrefService; |
namespace base { |
class ListValue; |
class Value; |
} |
namespace data_reduction_proxy { |
class DataReductionProxyService; |
class DataUsageBucket; |
class DataUseGroup; |
class PerSiteDataUsage; |
// 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 |
// prefs must be stored and read on the UI thread. |
-class DataReductionProxyCompressionStats { |
+class DataReductionProxyCompressionStats : public DataSavingsRecorder { |
public: |
typedef base::ScopedPtrHashMap<std::string, std::unique_ptr<PerSiteDataUsage>> |
SiteUsageMap; |
// Collects and store data usage and compression statistics. Basic data usage |
// stats are stored in browser preferences. More detailed stats broken down |
// by site and internet type are stored in |DataReductionProxyStore|. |
// |
// To store basic stats, it constructs a data reduction proxy delayed pref |
// service object using |pref_service|. Writes prefs to |pref_service| after |
// |delay| and stores them in |pref_map_| and |list_pref_map| between writes. |
// If |delay| is zero, writes directly to the PrefService and does not store |
// in the maps. |
DataReductionProxyCompressionStats(DataReductionProxyService* service, |
PrefService* pref_service, |
const base::TimeDelta& delay); |
~DataReductionProxyCompressionStats(); |
+ // DataSavingsRecorder implementation: |
+ void UpdateDataSavings(const std::string& data_usage_host, |
+ int64_t data_used, |
+ int64_t original_size) override; |
+ |
// Records detailed data usage broken down by connection type and domain. Also |
// records daily data savings statistics to prefs and reports data savings |
// UMA. |compressed_size| and |original_size| are measured in bytes. |
void UpdateContentLengths(int64_t compressed_size, |
int64_t original_size, |
bool data_reduction_proxy_enabled, |
DataReductionProxyRequestType request_type, |
const scoped_refptr<DataUseGroup>& data_use_group, |
const std::string& mime_type); |
@@ -217,20 +223,30 @@ class DataReductionProxyCompressionStats { |
// Called when |prefs::kDataUsageReportingEnabled| pref values changes. |
// Initializes data usage statistics in memory when pref is enabled and |
// persists data usage to memory when pref is disabled. |
void OnDataUsageReportingPrefChanged(); |
// Normalizes the hostname for data usage attribution. Returns a substring |
// without the protocol. |
// Example: "http://www.finance.google.com" -> "www.finance.google.com" |
static std::string NormalizeHostname(const std::string& host); |
+ // Records detailed data usage broken down by |host|. Also records daily data |
+ // savings statistics to prefs and reports data savings UMA. |data_used| and |
+ // |original_size| are measured in bytes. |
+ void RecordData(int64_t data_used, |
+ int64_t original_size, |
+ bool data_saver_enabled, |
+ DataReductionProxyRequestType request_type, |
+ const std::string& data_use_host, |
+ const std::string& mime_type); |
+ |
DataReductionProxyService* service_; |
PrefService* pref_service_; |
const base::TimeDelta delay_; |
DataReductionProxyPrefMap pref_map_; |
DataReductionProxyListPrefMap list_pref_map_; |
BooleanPrefMember data_usage_reporting_enabled_; |
// Maintains detailed data usage for current interval. |
SiteUsageMap data_usage_map_; |