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

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

Issue 2737563007: Add support for tracking loading behavior of child frames. (Closed)
Patch Set: test fixes Created 3 years, 9 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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 } 503 }
504 504
505 aborted_provisional_loads_.clear(); 505 aborted_provisional_loads_.clear();
506 return last_aborted_load; 506 return last_aborted_load;
507 } 507 }
508 508
509 void MetricsWebContentsObserver::OnTimingUpdated( 509 void MetricsWebContentsObserver::OnTimingUpdated(
510 content::RenderFrameHost* render_frame_host, 510 content::RenderFrameHost* render_frame_host,
511 const PageLoadTiming& timing, 511 const PageLoadTiming& timing,
512 const PageLoadMetadata& metadata) { 512 const PageLoadMetadata& metadata) {
513 content::RenderFrameHost* root_render_frame_host = render_frame_host;
Charlie Harrison 2017/03/08 21:47:17 I would probably prefer GetRenderViewHost()->GetMa
Bryan McQuade 2017/03/09 03:06:11 ah, absolutely, thanks! didn't know about that.
514 while (root_render_frame_host->GetParent() != nullptr) {
515 root_render_frame_host = root_render_frame_host->GetParent();
516 }
517
513 // We may receive notifications from frames that have been navigated away 518 // We may receive notifications from frames that have been navigated away
514 // from. We simply ignore them. 519 // from. We simply ignore them.
515 if (render_frame_host != web_contents()->GetMainFrame()) { 520 if (root_render_frame_host != web_contents()->GetMainFrame()) {
516 RecordInternalError(ERR_IPC_FROM_WRONG_FRAME); 521 RecordInternalError(ERR_IPC_FROM_WRONG_FRAME);
517 return; 522 return;
518 } 523 }
519 524
520 // While timings arriving for the wrong frame are expected, we do not expect 525 // While timings arriving for the wrong frame are expected, we do not expect
521 // any of the errors below. Thus, we track occurrences of all errors below, 526 // any of the errors below. Thus, we track occurrences of all errors below,
522 // rather than returning early after encountering an error. 527 // rather than returning early after encountering an error.
523 528
524 bool error = false; 529 bool error = false;
525 if (!committed_load_) { 530 if (!committed_load_) {
526 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD); 531 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD);
527 error = true; 532 error = true;
528 } 533 }
529 534
530 if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) { 535 if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) {
531 RecordInternalError(ERR_IPC_FROM_BAD_URL_SCHEME); 536 RecordInternalError(ERR_IPC_FROM_BAD_URL_SCHEME);
532 error = true; 537 error = true;
533 } 538 }
534 539
535 if (error) 540 if (error)
536 return; 541 return;
537 542
543 if (render_frame_host->GetParent() != nullptr) {
544 // Child frames may send PageLoadMetadata updates, but not PageLoadTiming
545 // updates.
546 if (!timing.IsEmpty())
547 RecordInternalError(ERR_TIMING_IPC_FROM_SUBFRAME);
548 committed_load_->UpdateChildMetadata(metadata);
549 return;
550 }
551
538 if (!committed_load_->UpdateTiming(timing, metadata)) { 552 if (!committed_load_->UpdateTiming(timing, metadata)) {
539 // If the page load tracker cannot update its timing, something is wrong 553 // If the page load tracker cannot update its timing, something is wrong
540 // with the IPC (it's from another load, or it's invalid in some other way). 554 // with the IPC (it's from another load, or it's invalid in some other way).
541 // We expect this to be a rare occurrence. 555 // We expect this to be a rare occurrence.
542 RecordInternalError(ERR_BAD_TIMING_IPC); 556 RecordInternalError(ERR_BAD_TIMING_IPC);
543 } 557 }
544 } 558 }
545 559
546 bool MetricsWebContentsObserver::ShouldTrackNavigation( 560 bool MetricsWebContentsObserver::ShouldTrackNavigation(
547 content::NavigationHandle* navigation_handle) const { 561 content::NavigationHandle* navigation_handle) const {
548 DCHECK(navigation_handle->IsInMainFrame()); 562 DCHECK(navigation_handle->IsInMainFrame());
549 DCHECK(!navigation_handle->HasCommitted() || 563 DCHECK(!navigation_handle->HasCommitted() ||
550 !navigation_handle->IsSameDocument()); 564 !navigation_handle->IsSameDocument());
551 565
552 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(), 566 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(),
553 navigation_handle).ShouldTrack(); 567 navigation_handle).ShouldTrack();
554 } 568 }
555 569
556 } // namespace page_load_metrics 570 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698