Commit 133ca64b authored by John Delaney's avatar John Delaney Committed by Commit Bot

Refactor mime type resource counts in AdsPLMO

This a precursor change that tracks mime type counts for all
resource types in frames. This will allow future changes to record
other mime types without adding separate counters to FrameData.

Bug: 951480
Change-Id: I700c8ce9f3065082a621ce8e69027fa8607105e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1562291Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Commit-Queue: John Delaney <johnidel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649667}
parent 5d41d44e
......@@ -485,9 +485,12 @@ void AdsPageLoadMetricsObserver::RecordPageResourceTotalHistograms(
ukm::builders::AdPageLoad builder(source_id);
builder.SetTotalBytes(aggregate_frame_data_->network_bytes() >> 10)
.SetAdBytes(aggregate_frame_data_->ad_network_bytes() >> 10)
.SetAdJavascriptBytes(
aggregate_frame_data_->ad_javascript_network_bytes() >> 10)
.SetAdVideoBytes(aggregate_frame_data_->ad_video_network_bytes() >> 10);
.SetAdJavascriptBytes(aggregate_frame_data_->GetAdNetworkBytesForMime(
FrameData::ResourceMimeType::kJavascript) >>
10)
.SetAdVideoBytes(aggregate_frame_data_->GetAdNetworkBytesForMime(
FrameData::ResourceMimeType::kVideo) >>
10);
base::TimeTicks current_time = clock_->NowTicks();
if (!time_commit_.is_null()) {
int time_since_commit = (current_time - time_commit_).InMicroseconds();
......
......@@ -112,10 +112,7 @@ void FrameData::ProcessResourceLoadInFrame(
ad_bytes_ += resource->encoded_body_length;
ResourceMimeType mime_type = GetResourceMimeType(resource);
if (mime_type == ResourceMimeType::kVideo)
ad_video_network_bytes_ += resource->delta_bytes;
else if (mime_type == ResourceMimeType::kJavascript)
ad_javascript_network_bytes_ += resource->delta_bytes;
ad_bytes_by_mime_[static_cast<size_t>(mime_type)] += resource->delta_bytes;
}
}
......@@ -123,11 +120,7 @@ void FrameData::AdjustAdBytes(int64_t unaccounted_ad_bytes,
ResourceMimeType mime_type) {
ad_network_bytes_ += unaccounted_ad_bytes;
ad_bytes_ += unaccounted_ad_bytes;
if (mime_type == ResourceMimeType::kVideo)
ad_video_network_bytes_ += unaccounted_ad_bytes;
else if (mime_type == ResourceMimeType::kJavascript)
ad_javascript_network_bytes_ += unaccounted_ad_bytes;
ad_bytes_by_mime_[static_cast<size_t>(mime_type)] += unaccounted_ad_bytes;
}
void FrameData::SetFrameSize(gfx::Size frame_size) {
......@@ -162,6 +155,10 @@ void FrameData::SetReceivedUserActivation(base::TimeDelta foreground_duration) {
pre_activation_foreground_duration_ = foreground_duration;
}
size_t FrameData::GetAdNetworkBytesForMime(ResourceMimeType mime_type) const {
return ad_bytes_by_mime_[static_cast<size_t>(mime_type)];
}
void FrameData::UpdateFrameVisibility() {
visibility_ =
!is_display_none_ &&
......
......@@ -145,11 +145,7 @@ class FrameData {
size_t ad_network_bytes() const { return ad_network_bytes_; }
size_t ad_video_network_bytes() const { return ad_video_network_bytes_; }
size_t ad_javascript_network_bytes() const {
return ad_javascript_network_bytes_;
}
size_t GetAdNetworkBytesForMime(ResourceMimeType mime_type) const;
UserActivationStatus user_activation_status() const {
return user_activation_status_;
......@@ -179,10 +175,10 @@ class FrameData {
size_t bytes_;
size_t network_bytes_;
// Tallies for bytes and counts observed in resource data updates for the
// Records ad network bytes for different mime type resources loaded in the
// frame.
size_t ad_javascript_network_bytes_ = 0u;
size_t ad_video_network_bytes_ = 0u;
size_t ad_bytes_by_mime_[static_cast<size_t>(ResourceMimeType::kMaxValue) +
1] = {0};
// Time spent by the frame in the cpu before and after interactive.
base::TimeDelta cpu_by_interactive_period_[static_cast<size_t>(
......
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