Commit 6cd9082c authored by rajendrant's avatar rajendrant Committed by Commit Bot

Record total data use of services and user-traffic for network-service

Bug: 898326
Change-Id: Ife17e6b2ce3ad21d5049377318a8e14c70e5ec98
Reviewed-on: https://chromium-review.googlesource.com/c/1351591
Commit-Queue: rajendrant <rajendrant@chromium.org>
Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611310}
parent a487ad8f
......@@ -120,7 +120,8 @@ void ChromeDataUseMeasurement::ReportNetworkServiceDataUse(
if (!is_user_request || DataUseMeasurement::IsUserDownloadsRequest(
network_traffic_annotation_id_hash)) {
for (auto& observer : services_data_use_observer_list_)
observer.OnServicesDataUse(recv_bytes, sent_bytes);
observer.OnServicesDataUse(network_traffic_annotation_id_hash, recv_bytes,
sent_bytes);
}
UMA_HISTOGRAM_COUNTS_1M("DataUse.BytesReceived.Delegate", recv_bytes);
UMA_HISTOGRAM_COUNTS_1M("DataUse.BytesSent.Delegate", sent_bytes);
......
......@@ -20,6 +20,7 @@
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h"
#include "components/data_reduction_proxy/proto/client_config.pb.h"
#include "components/prefs/pref_service.h"
......@@ -354,6 +355,37 @@ IN_PROC_BROWSER_TEST_F(DataReductionProxyBrowsertest, UMAMetricsRecorded) {
1);
}
class DataReductionProxyBrowsertestWithNetworkService
: public DataReductionProxyBrowsertest {
public:
void SetUp() override {
scoped_feature_list_.InitAndEnableFeature(
network::features::kNetworkService);
DataReductionProxyBrowsertest::SetUp();
}
base::test::ScopedFeatureList scoped_feature_list_;
};
IN_PROC_BROWSER_TEST_F(DataReductionProxyBrowsertestWithNetworkService,
DataUsePrefsRecorded) {
PrefService* prefs = browser()->profile()->GetPrefs();
// Make sure we wait for timing information.
page_load_metrics::PageLoadMetricsTestWaiter waiter(
browser()->tab_strip_model()->GetActiveWebContents());
waiter.AddPageExpectation(
page_load_metrics::PageLoadMetricsTestWaiter::TimingField::kFirstPaint);
// Proxy will be used, so it shouldn't matter if the host cannot be resolved.
ui_test_utils::NavigateToURL(browser(), GURL("http://does.not.resolve/echo"));
waiter.Wait();
ASSERT_GE(0, prefs->GetInt64(
data_reduction_proxy::prefs::kHttpReceivedContentLength));
ASSERT_GE(0, prefs->GetInt64(
data_reduction_proxy::prefs::kHttpOriginalContentLength));
}
class DataReductionProxyFallbackBrowsertest
: public DataReductionProxyBrowsertest {
public:
......
......@@ -12,6 +12,7 @@
#include "content/public/browser/browser_context.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/web_contents.h"
#include "services/network/public/cpp/features.h"
#include "url/gurl.h"
DataSaverSiteBreakdownMetricsObserver::DataSaverSiteBreakdownMetricsObserver() =
......@@ -64,5 +65,17 @@ void DataSaverSiteBreakdownMetricsObserver::OnResourceDataUseObserved(
received_data_length,
received_data_length + data_reduction_proxy_bytes_saved,
committed_host_);
if (base::FeatureList::IsEnabled(network::features::kNetworkService)) {
// TODO(rajendrant): Fix the |request_type| and |mime_type| sent below or
// remove the respective histograms.
data_reduction_proxy_settings->data_reduction_proxy_service()
->UpdateContentLengths(
received_data_length,
received_data_length + data_reduction_proxy_bytes_saved,
data_reduction_proxy_settings->IsDataReductionProxyEnabled(),
data_reduction_proxy::VIA_DATA_REDUCTION_PROXY,
std::string() /* mime_type */, true /*is_user_traffic*/,
data_use_measurement::DataUseUserData::OTHER, 0);
}
}
}
......@@ -376,7 +376,8 @@ DataReductionProxyService::GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
void DataReductionProxyService::OnServicesDataUse(int64_t recv_bytes,
void DataReductionProxyService::OnServicesDataUse(int32_t service_hash_code,
int64_t recv_bytes,
int64_t sent_bytes) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (compression_stats_) {
......@@ -389,6 +390,10 @@ void DataReductionProxyService::OnServicesDataUse(int64_t recv_bytes,
compression_stats_->RecordDataUseByHost(
util::GetSiteBreakdownOtherHostName(), recv_bytes, recv_bytes,
base::Time::Now());
compression_stats_->RecordDataUseWithMimeType(
recv_bytes, recv_bytes, settings_->IsDataReductionProxyEnabled(), HTTPS,
std::string(), false, data_use_measurement::DataUseUserData::OTHER,
service_hash_code);
}
}
......
......@@ -193,7 +193,9 @@ class DataReductionProxyService
// Loads the Data Reduction Proxy configuration from |prefs_| and applies it.
void ReadPersistedClientConfig();
void OnServicesDataUse(int64_t recv_bytes, int64_t sent_bytes) override;
void OnServicesDataUse(int32_t service_hash_code,
int64_t recv_bytes,
int64_t sent_bytes) override;
// NetworkConnectionTracker::NetworkConnectionObserver
void OnConnectionChanged(network::mojom::ConnectionType type) override;
......
......@@ -48,7 +48,9 @@ class DataUseMeasurement
class ServicesDataUseObserver {
public:
// Called when services data use is reported.
virtual void OnServicesDataUse(int64_t recv_bytes, int64_t sent_bytes) = 0;
virtual void OnServicesDataUse(int32_t service_hash_code,
int64_t recv_bytes,
int64_t sent_bytes) = 0;
};
// Returns true if the NTA hash is initiated by user traffic.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment