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

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

Issue 2152683004: Refactor PageLoadMetricsObserver completion callback policy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@relevantloads
Patch Set: fix metric Created 4 years, 5 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 "components/page_load_metrics/browser/metrics_web_contents_observer.h" 5 #include "components/page_load_metrics/browser/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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 const char kAbortChainSizeForwardBack[] = 42 const char kAbortChainSizeForwardBack[] =
43 "PageLoad.Internal.ProvisionalAbortChainSize.ForwardBack"; 43 "PageLoad.Internal.ProvisionalAbortChainSize.ForwardBack";
44 const char kAbortChainSizeNewNavigation[] = 44 const char kAbortChainSizeNewNavigation[] =
45 "PageLoad.Internal.ProvisionalAbortChainSize.NewNavigation"; 45 "PageLoad.Internal.ProvisionalAbortChainSize.NewNavigation";
46 const char kAbortChainSizeSameURL[] = 46 const char kAbortChainSizeSameURL[] =
47 "PageLoad.Internal.ProvisionalAbortChainSize.SameURL"; 47 "PageLoad.Internal.ProvisionalAbortChainSize.SameURL";
48 const char kAbortChainSizeNoCommit[] = 48 const char kAbortChainSizeNoCommit[] =
49 "PageLoad.Internal.ProvisionalAbortChainSize.NoCommit"; 49 "PageLoad.Internal.ProvisionalAbortChainSize.NoCommit";
50 const char kClientRedirectDelayAfterPaint[] = 50 const char kClientRedirectDelayAfterPaint[] =
51 "PageLoad.Internal.ClientRedirectDelayAfterPaint"; 51 "PageLoad.Internal.ClientRedirectDelayAfterPaint";
52 const char kCommitToCompleteNoTimingIPCs[] =
53 "PageLoad.Internal.CommitToComplete.NoTimingIPCs";
52 54
53 } // namespace internal 55 } // namespace internal
54 56
55 namespace { 57 namespace {
56 58
57 // Helper to allow use of Optional<> values in LOG() messages. 59 // Helper to allow use of Optional<> values in LOG() messages.
58 std::ostream& operator<<(std::ostream& os, 60 std::ostream& operator<<(std::ostream& os,
59 const base::Optional<base::TimeDelta>& opt) { 61 const base::Optional<base::TimeDelta>& opt) {
60 if (opt) 62 if (opt)
61 os << opt.value(); 63 os << opt.value();
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 observer->OnStart(navigation_handle, currently_committed_url, 258 observer->OnStart(navigation_handle, currently_committed_url,
257 started_in_foreground_); 259 started_in_foreground_);
258 } 260 }
259 } 261 }
260 262
261 PageLoadTracker::~PageLoadTracker() { 263 PageLoadTracker::~PageLoadTracker() {
262 if (did_stop_tracking_) 264 if (did_stop_tracking_)
263 return; 265 return;
264 266
265 const PageLoadExtraInfo info = ComputePageLoadExtraInfo(); 267 const PageLoadExtraInfo info = ComputePageLoadExtraInfo();
266 268 DCHECK_NE(static_cast<bool>(info.time_to_commit),
269 static_cast<bool>(failed_provisional_load_info_));
267 if (info.time_to_commit && timing_.IsEmpty()) { 270 if (info.time_to_commit && timing_.IsEmpty()) {
268 RecordInternalError(ERR_NO_IPCS_RECEIVED); 271 RecordInternalError(ERR_NO_IPCS_RECEIVED);
272 const base::TimeTicks commit_time =
273 navigation_start_ + info.time_to_commit.value();
274 PAGE_LOAD_HISTOGRAM(internal::kCommitToCompleteNoTimingIPCs,
275 base::TimeTicks::Now() - commit_time);
269 } 276 }
270 // Recall that trackers that are given ABORT_UNKNOWN_NAVIGATION have their 277 // Recall that trackers that are given ABORT_UNKNOWN_NAVIGATION have their
271 // chain length added to the next navigation. Take care not to double count 278 // chain length added to the next navigation. Take care not to double count
272 // them. Also do not double count committed loads, which call this already. 279 // them. Also do not double count committed loads, which call this already.
273 if (commit_time_.is_null() && abort_type_ != ABORT_UNKNOWN_NAVIGATION) 280 if (commit_time_.is_null() && abort_type_ != ABORT_UNKNOWN_NAVIGATION)
274 LogAbortChainHistograms(nullptr); 281 LogAbortChainHistograms(nullptr);
275 282
276 for (const auto& observer : observers_) { 283 for (const auto& observer : observers_) {
277 observer->OnComplete(timing_, info); 284 if (failed_provisional_load_info_) {
285 observer->OnFailedProvisionalLoad(failed_provisional_load_info_.value(),
286 info);
287 } else {
288 observer->OnComplete(timing_, info);
289 }
278 } 290 }
279 } 291 }
280 292
281 void PageLoadTracker::LogAbortChainHistograms( 293 void PageLoadTracker::LogAbortChainHistograms(
282 content::NavigationHandle* final_navigation) { 294 content::NavigationHandle* final_navigation) {
283 if (aborted_chain_size_ == 0) 295 if (aborted_chain_size_ == 0)
284 return; 296 return;
285 // Note that this could be broken out by this navigation's abort type, if more 297 // Note that this could be broken out by this navigation's abort type, if more
286 // granularity is needed. Add one to the chain size to count the current 298 // granularity is needed. Add one to the chain size to count the current
287 // navigation. In the other cases, the current navigation is the final 299 // navigation. In the other cases, the current navigation is the final
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 ClampBrowserTimestampIfInterProcessTimeTickSkew(&commit_time_); 372 ClampBrowserTimestampIfInterProcessTimeTickSkew(&commit_time_);
361 url_ = navigation_handle->GetURL(); 373 url_ = navigation_handle->GetURL();
362 for (const auto& observer : observers_) { 374 for (const auto& observer : observers_) {
363 observer->OnCommit(navigation_handle); 375 observer->OnCommit(navigation_handle);
364 } 376 }
365 LogAbortChainHistograms(navigation_handle); 377 LogAbortChainHistograms(navigation_handle);
366 } 378 }
367 379
368 void PageLoadTracker::FailedProvisionalLoad( 380 void PageLoadTracker::FailedProvisionalLoad(
369 content::NavigationHandle* navigation_handle) { 381 content::NavigationHandle* navigation_handle) {
370 for (const auto& observer : observers_) { 382 failed_provisional_load_info_ = FailedProvisionalLoadInfo(
371 observer->OnFailedProvisionalLoad(navigation_handle); 383 base::TimeTicks::Now() - navigation_handle->NavigationStart(),
372 } 384 navigation_handle->GetNetErrorCode());
373 } 385 }
374 386
375 void PageLoadTracker::Redirect(content::NavigationHandle* navigation_handle) { 387 void PageLoadTracker::Redirect(content::NavigationHandle* navigation_handle) {
376 for (const auto& observer : observers_) { 388 for (const auto& observer : observers_) {
377 observer->OnRedirect(navigation_handle); 389 observer->OnRedirect(navigation_handle);
378 } 390 }
379 } 391 }
380 392
381 void PageLoadTracker::OnInputEvent(const blink::WebInputEvent& event) { 393 void PageLoadTracker::OnInputEvent(const blink::WebInputEvent& event) {
382 for (const auto& observer : observers_) { 394 for (const auto& observer : observers_) {
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 if (navigation_handle->IsSamePage() || navigation_handle->IsErrorPage()) 947 if (navigation_handle->IsSamePage() || navigation_handle->IsErrorPage())
936 return false; 948 return false;
937 const std::string& mime_type = web_contents()->GetContentsMimeType(); 949 const std::string& mime_type = web_contents()->GetContentsMimeType();
938 if (mime_type != "text/html" && mime_type != "application/xhtml+xml") 950 if (mime_type != "text/html" && mime_type != "application/xhtml+xml")
939 return false; 951 return false;
940 } 952 }
941 return true; 953 return true;
942 } 954 }
943 955
944 } // namespace page_load_metrics 956 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698