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

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

Issue 2802693002: Revert of Simplify MetricsWebContentsObserver::OnTimingUpdated (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 } 518 }
519 519
520 aborted_provisional_loads_.clear(); 520 aborted_provisional_loads_.clear();
521 return last_aborted_load; 521 return last_aborted_load;
522 } 522 }
523 523
524 void MetricsWebContentsObserver::OnTimingUpdated( 524 void MetricsWebContentsObserver::OnTimingUpdated(
525 content::RenderFrameHost* render_frame_host, 525 content::RenderFrameHost* render_frame_host,
526 const PageLoadTiming& timing, 526 const PageLoadTiming& timing,
527 const PageLoadMetadata& metadata) { 527 const PageLoadMetadata& metadata) {
528 // We may receive notifications from frames that have been navigated away
529 // from. We simply ignore them.
530 if (!render_frame_host->GetRenderViewHost() ||
531 render_frame_host->GetRenderViewHost()->GetMainFrame() !=
532 web_contents()->GetMainFrame()) {
533 RecordInternalError(ERR_IPC_FROM_WRONG_FRAME);
534 return;
535 }
536
537 // While timings arriving for the wrong frame are expected, we do not expect
538 // any of the errors below. Thus, we track occurrences of all errors below,
539 // rather than returning early after encountering an error.
540
541 bool error = false;
542 if (!committed_load_) {
543 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD);
544 error = true;
545 }
546
547 if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) {
548 RecordInternalError(ERR_IPC_FROM_BAD_URL_SCHEME);
549 error = true;
550 }
551
552 if (error)
553 return;
554
528 if (render_frame_host->GetParent() != nullptr) { 555 if (render_frame_host->GetParent() != nullptr) {
529 // Child frames may send PageLoadMetadata updates, but not PageLoadTiming 556 // Child frames may send PageLoadMetadata updates, but not PageLoadTiming
530 // updates. 557 // updates.
531 if (!timing.IsEmpty()) 558 if (!timing.IsEmpty())
532 RecordInternalError(ERR_TIMING_IPC_FROM_SUBFRAME); 559 RecordInternalError(ERR_TIMING_IPC_FROM_SUBFRAME);
533 committed_load_->UpdateChildFrameMetadata(metadata); 560 committed_load_->UpdateChildFrameMetadata(metadata);
534 return; 561 return;
535 } 562 }
536 563
537 // We may receive notifications from frames that have been navigated away
538 // from. We simply ignore them.
539 if (render_frame_host != web_contents()->GetMainFrame()) {
540 RecordInternalError(ERR_IPC_FROM_WRONG_FRAME);
541 return;
542 }
543
544 // While timings arriving for the wrong frame are expected, we do not expect
545 // any of the errors below. Thus, we track occurrences of all errors below,
546 // rather than returning early after encountering an error.
547
548 bool error = false;
549 if (!committed_load_) {
550 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD);
551 error = true;
552 }
553
554 if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) {
555 RecordInternalError(ERR_IPC_FROM_BAD_URL_SCHEME);
556 error = true;
557 }
558
559 if (error)
560 return;
561
562 if (!committed_load_->UpdateTiming(timing, metadata)) { 564 if (!committed_load_->UpdateTiming(timing, metadata)) {
563 // If the page load tracker cannot update its timing, something is wrong 565 // If the page load tracker cannot update its timing, something is wrong
564 // with the IPC (it's from another load, or it's invalid in some other way). 566 // with the IPC (it's from another load, or it's invalid in some other way).
565 // We expect this to be a rare occurrence. 567 // We expect this to be a rare occurrence.
566 RecordInternalError(ERR_BAD_TIMING_IPC); 568 RecordInternalError(ERR_BAD_TIMING_IPC);
567 } 569 }
568 } 570 }
569 571
570 bool MetricsWebContentsObserver::ShouldTrackNavigation( 572 bool MetricsWebContentsObserver::ShouldTrackNavigation(
571 content::NavigationHandle* navigation_handle) const { 573 content::NavigationHandle* navigation_handle) const {
572 DCHECK(navigation_handle->IsInMainFrame()); 574 DCHECK(navigation_handle->IsInMainFrame());
573 DCHECK(!navigation_handle->HasCommitted() || 575 DCHECK(!navigation_handle->HasCommitted() ||
574 !navigation_handle->IsSameDocument()); 576 !navigation_handle->IsSameDocument());
575 577
576 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(), 578 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(),
577 navigation_handle).ShouldTrack(); 579 navigation_handle).ShouldTrack();
578 } 580 }
579 581
580 } // namespace page_load_metrics 582 } // namespace page_load_metrics
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698