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

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

Issue 2249903004: Adding a DataSavingsRecorder interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bengr comments Created 4 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 side-by-side diff with in-line comments
Download patch
Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.cc
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.cc
index 934b6947a1642429c48b3202f1db26ae2007b989..9a600c080379f71a046214579c19836225909bcf 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.cc
@@ -413,42 +413,68 @@ void DataReductionProxyCompressionStats::Init() {
InitListPref(prefs::kDailyHttpReceivedContentLength);
InitListPref(prefs::kDailyOriginalContentLengthViaDataReductionProxy);
InitListPref(prefs::kDailyOriginalContentLengthWithDataReductionProxyEnabled);
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kClearDataReductionProxyDataSavings)) {
ClearDataSavingStatistics();
}
}
+void DataReductionProxyCompressionStats::UpdateDataSavings(
+ const std::string& data_usage_host,
+ int64_t data_used,
+ int64_t original_size) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ // Data is recorded at the URLRequest level, so an update should only change
+ // the original size amount by the savings amount.
+ int64_t update_to_original_size = original_size - data_used;
+ int64_t update_to_data_used = 0;
+ RecordData(update_to_data_used, update_to_original_size,
+ true /* data_saver_enabled */, UPDATE, data_usage_host,
+ std::string());
+}
+
void DataReductionProxyCompressionStats::UpdateContentLengths(
int64_t data_used,
int64_t original_size,
- bool data_reduction_proxy_enabled,
+ bool data_saver_enabled,
DataReductionProxyRequestType request_type,
const scoped_refptr<DataUseGroup>& data_use_group,
const std::string& mime_type) {
DCHECK(thread_checker_.CalledOnValidThread());
- TRACE_EVENT0("loader",
- "DataReductionProxyCompressionStats::UpdateContentLengths")
+ std::string data_use_host;
+ if (data_use_group) {
+ data_use_host = data_use_group->GetHostname();
+ }
+
+ RecordData(data_used, original_size, data_saver_enabled, request_type,
+ data_use_host, mime_type);
+}
+
+void DataReductionProxyCompressionStats::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) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ TRACE_EVENT0("loader", "DataReductionProxyCompressionStats::RecordData")
IncreaseInt64Pref(data_reduction_proxy::prefs::kHttpReceivedContentLength,
data_used);
IncreaseInt64Pref(data_reduction_proxy::prefs::kHttpOriginalContentLength,
original_size);
- std::string data_use_host;
- if (data_use_group) {
- data_use_host = data_use_group->GetHostname();
- }
RecordDataUsage(data_use_host, data_used, original_size, base::Time::Now());
- RecordRequestSizePrefs(data_used, original_size, data_reduction_proxy_enabled,
+ RecordRequestSizePrefs(data_used, original_size, data_saver_enabled,
request_type, mime_type, base::Time::Now());
}
void DataReductionProxyCompressionStats::InitInt64Pref(const char* pref) {
int64_t pref_value = pref_service_->GetInt64(pref);
pref_map_[pref] = pref_value;
}
void DataReductionProxyCompressionStats::InitListPref(const char* pref) {
std::unique_ptr<base::ListValue> pref_value =
@@ -678,21 +704,21 @@ void DataReductionProxyCompressionStats::DelayedWritePrefs() {
void DataReductionProxyCompressionStats::TransferList(
const base::ListValue& from_list,
base::ListValue* to_list) {
to_list->Clear();
from_list.CreateDeepCopy()->Swap(to_list);
}
void DataReductionProxyCompressionStats::RecordRequestSizePrefs(
int64_t data_used,
int64_t original_size,
- bool with_data_reduction_proxy_enabled,
+ bool with_data_saver_enabled,
DataReductionProxyRequestType request_type,
const std::string& mime_type,
const base::Time& now) {
// TODO(bengr): Remove this check once the underlying cause of
// http://crbug.com/287821 is fixed. For now, only continue if the current
// year is reported as being between 1972 and 2970.
base::TimeDelta time_since_unix_epoch = now - base::Time::UnixEpoch();
const int kMinDaysSinceUnixEpoch = 365 * 2; // 2 years.
const int kMaxDaysSinceUnixEpoch = 365 * 1000; // 1000 years.
if (time_since_unix_epoch.InDays() < kMinDaysSinceUnixEpoch ||
@@ -964,85 +990,90 @@ void DataReductionProxyCompressionStats::RecordRequestSizePrefs(
total.UpdateForDateChange(days_since_last_update);
proxy_enabled.UpdateForDateChange(days_since_last_update);
via_proxy.UpdateForDateChange(days_since_last_update);
https.UpdateForDateChange(days_since_last_update);
short_bypass.UpdateForDateChange(days_since_last_update);
long_bypass.UpdateForDateChange(days_since_last_update);
unknown.UpdateForDateChange(days_since_last_update);
total.Add(original_size, data_used);
- if (with_data_reduction_proxy_enabled) {
+ if (with_data_saver_enabled) {
proxy_enabled.Add(original_size, data_used);
// Ignore data source cases, if exist, when
- // "with_data_reduction_proxy_enabled == false"
+ // "with_data_saver_enabled == false"
switch (request_type) {
case VIA_DATA_REDUCTION_PROXY:
via_proxy.Add(original_size, data_used);
break;
case HTTPS:
https.Add(data_used);
break;
case SHORT_BYPASS:
short_bypass.Add(data_used);
break;
case LONG_BYPASS:
long_bypass.Add(data_used);
break;
+ case UPDATE:
+ // Don't record any request level prefs. If this is an update, this data
+ // was already recorded at the URLRequest level. Updates are generally
+ // page load level optimizations and don't correspond to request types.
+ return;
case UNKNOWN_TYPE:
unknown.Add(data_used);
break;
default:
NOTREACHED();
}
}
bool via_data_reduction_proxy = request_type == VIA_DATA_REDUCTION_PROXY;
bool is_application = net::MatchesMimeType("application/*", mime_type);
bool is_video = net::MatchesMimeType("video/*", mime_type);
bool is_mime_type_empty = mime_type.empty();
if (is_application) {
IncrementDailyUmaPrefs(
original_size, data_used,
data_reduction_proxy::prefs::kDailyHttpOriginalContentLengthApplication,
data_reduction_proxy::prefs::kDailyHttpReceivedContentLengthApplication,
- with_data_reduction_proxy_enabled,
+ with_data_saver_enabled,
data_reduction_proxy::prefs::
kDailyOriginalContentLengthWithDataReductionProxyEnabledApplication,
data_reduction_proxy::prefs::
kDailyContentLengthWithDataReductionProxyEnabledApplication,
via_data_reduction_proxy,
data_reduction_proxy::prefs::
kDailyOriginalContentLengthViaDataReductionProxyApplication,
data_reduction_proxy::prefs::
kDailyContentLengthViaDataReductionProxyApplication);
} else if (is_video) {
IncrementDailyUmaPrefs(
original_size, data_used,
data_reduction_proxy::prefs::kDailyHttpOriginalContentLengthVideo,
data_reduction_proxy::prefs::kDailyHttpReceivedContentLengthVideo,
- with_data_reduction_proxy_enabled,
+ with_data_saver_enabled,
data_reduction_proxy::prefs::
kDailyOriginalContentLengthWithDataReductionProxyEnabledVideo,
data_reduction_proxy::prefs::
kDailyContentLengthWithDataReductionProxyEnabledVideo,
via_data_reduction_proxy,
data_reduction_proxy::prefs::
kDailyOriginalContentLengthViaDataReductionProxyVideo,
data_reduction_proxy::prefs::
kDailyContentLengthViaDataReductionProxyVideo);
} else if (is_mime_type_empty) {
IncrementDailyUmaPrefs(
original_size, data_used,
data_reduction_proxy::prefs::kDailyHttpOriginalContentLengthUnknown,
data_reduction_proxy::prefs::kDailyHttpReceivedContentLengthUnknown,
- with_data_reduction_proxy_enabled,
+ with_data_saver_enabled,
data_reduction_proxy::prefs::
kDailyOriginalContentLengthWithDataReductionProxyEnabledUnknown,
data_reduction_proxy::prefs::
kDailyContentLengthWithDataReductionProxyEnabledUnknown,
via_data_reduction_proxy,
data_reduction_proxy::prefs::
kDailyOriginalContentLengthViaDataReductionProxyUnknown,
data_reduction_proxy::prefs::
kDailyContentLengthViaDataReductionProxyUnknown);
}

Powered by Google App Engine
This is Rietveld 408576698