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

Side by Side Diff: chrome/browser/page_load_metrics/metrics_web_contents_observer.cc

Issue 2560043004: [PageLoadMetrics] Record bytes usage per page (Closed)
Patch Set: Fix test Created 3 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" 5 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <ostream> 8 #include <ostream>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 navigation_handle, 171 navigation_handle,
172 base::MakeUnique<PageLoadTracker>( 172 base::MakeUnique<PageLoadTracker>(
173 in_foreground_, embedder_interface_.get(), currently_committed_url, 173 in_foreground_, embedder_interface_.get(), currently_committed_url,
174 navigation_handle, user_initiated_info, chain_size, 174 navigation_handle, user_initiated_info, chain_size,
175 chain_size_same_url))); 175 chain_size_same_url)));
176 } 176 }
177 177
178 void MetricsWebContentsObserver::OnRequestComplete( 178 void MetricsWebContentsObserver::OnRequestComplete(
179 content::ResourceType resource_type, 179 content::ResourceType resource_type,
180 bool was_cached, 180 bool was_cached,
181 int net_error) { 181 int64_t raw_body_bytes,
182 // For simplicity, only count subresources. Navigations are hard to attribute 182 base::TimeTicks creation_time) {
183 // here because we won't have a committed load by the time data streams in 183 // If the navigation hasn't committed yet then we'll miss the resource (this
184 // from the IO thread. 184 // happens on the new tab page). Also, if the resource request was started
185 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME && 185 // before this navigation then it should be ignored.
186 net_error != net::OK) { 186 // TODO(jkarlin): There is a race here. If a renderer starts URLRequests for
187 // page A after navigating (but before comitting) to page B, then page A's
188 // requests might wind up counting toward page B's size. This should be
189 // relatively rare but we may want to fix this at some point.
190 if (!committed_load_ || creation_time < committed_load_->navigation_start()) {
187 return; 191 return;
188 } 192 }
189 if (!committed_load_) 193
190 return; 194 committed_load_->OnLoadedResource(was_cached, raw_body_bytes);
191 committed_load_->OnLoadedSubresource(was_cached);
192 } 195 }
193 196
194 const PageLoadExtraInfo 197 const PageLoadExtraInfo
195 MetricsWebContentsObserver::GetPageLoadExtraInfoForCommittedLoad() { 198 MetricsWebContentsObserver::GetPageLoadExtraInfoForCommittedLoad() {
196 DCHECK(committed_load_); 199 DCHECK(committed_load_);
197 return committed_load_->ComputePageLoadExtraInfo(); 200 return committed_load_->ComputePageLoadExtraInfo();
198 } 201 }
199 202
200 void MetricsWebContentsObserver::DidFinishNavigation( 203 void MetricsWebContentsObserver::DidFinishNavigation(
201 content::NavigationHandle* navigation_handle) { 204 content::NavigationHandle* navigation_handle) {
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 content::NavigationHandle* navigation_handle) const { 477 content::NavigationHandle* navigation_handle) const {
475 DCHECK(navigation_handle->IsInMainFrame()); 478 DCHECK(navigation_handle->IsInMainFrame());
476 DCHECK(!navigation_handle->HasCommitted() || 479 DCHECK(!navigation_handle->HasCommitted() ||
477 !navigation_handle->IsSamePage()); 480 !navigation_handle->IsSamePage());
478 481
479 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(), 482 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(),
480 navigation_handle).ShouldTrack(); 483 navigation_handle).ShouldTrack();
481 } 484 }
482 485
483 } // namespace page_load_metrics 486 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698