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

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

Issue 2859393002: Report page load timing information for child frames. (Closed)
Patch Set: add comment Created 3 years, 7 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 21 matching lines...) Expand all
32 #include "net/base/net_errors.h" 32 #include "net/base/net_errors.h"
33 #include "ui/base/page_transition_types.h" 33 #include "ui/base/page_transition_types.h"
34 34
35 DEFINE_WEB_CONTENTS_USER_DATA_KEY( 35 DEFINE_WEB_CONTENTS_USER_DATA_KEY(
36 page_load_metrics::MetricsWebContentsObserver); 36 page_load_metrics::MetricsWebContentsObserver);
37 37
38 namespace page_load_metrics { 38 namespace page_load_metrics {
39 39
40 namespace { 40 namespace {
41 41
42 content::RenderFrameHost* GetMainFrame(content::RenderFrameHost* rfh) {
43 // Don't use rfh->GetRenderViewHost()->GetMainFrame() here because
44 // RenderViewHost is being deprecated and because in OOPIF,
45 // RenderViewHost::GetMainFrame() returns nullptr for child frames hosted in a
46 // different process from the main frame.
47 while (rfh->GetParent() != nullptr)
48 rfh = rfh->GetParent();
49 return rfh;
50 }
51
52 UserInitiatedInfo CreateUserInitiatedInfo( 42 UserInitiatedInfo CreateUserInitiatedInfo(
53 content::NavigationHandle* navigation_handle, 43 content::NavigationHandle* navigation_handle,
54 PageLoadTracker* committed_load) { 44 PageLoadTracker* committed_load) {
55 if (!navigation_handle->IsRendererInitiated()) 45 if (!navigation_handle->IsRendererInitiated())
56 return UserInitiatedInfo::BrowserInitiated(); 46 return UserInitiatedInfo::BrowserInitiated();
57 47
58 return UserInitiatedInfo::RenderInitiated( 48 return UserInitiatedInfo::RenderInitiated(
59 navigation_handle->HasUserGesture(), 49 navigation_handle->HasUserGesture(),
60 committed_load && 50 committed_load &&
61 committed_load->input_tracker()->FindAndConsumeInputEventsBefore( 51 committed_load->input_tracker()->FindAndConsumeInputEventsBefore(
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 } 578 }
589 579
590 if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) { 580 if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) {
591 RecordInternalError(ERR_IPC_FROM_BAD_URL_SCHEME); 581 RecordInternalError(ERR_IPC_FROM_BAD_URL_SCHEME);
592 error = true; 582 error = true;
593 } 583 }
594 584
595 if (error) 585 if (error)
596 return; 586 return;
597 587
598 if (render_frame_host->GetParent() != nullptr) { 588 const bool is_main_frame = (render_frame_host->GetParent() == nullptr);
599 // Child frames may send PageLoadMetadata updates, but not PageLoadTiming 589 if (is_main_frame) {
600 // updates. 590 committed_load_->UpdateTiming(timing, metadata);
601 if (!timing.IsEmpty()) 591 } else {
602 RecordInternalError(ERR_TIMING_IPC_FROM_SUBFRAME); 592 committed_load_->UpdateSubFrameTiming(render_frame_host, timing, metadata);
603 committed_load_->UpdateChildFrameMetadata(metadata);
604 return;
605 } 593 }
606 594
607 committed_load_->UpdateTiming(timing, metadata);
608
609 for (auto& observer : testing_observers_) 595 for (auto& observer : testing_observers_)
610 observer.OnTimingUpdated(timing, metadata); 596 observer.OnTimingUpdated(is_main_frame, timing, metadata);
611 } 597 }
612 598
613 bool MetricsWebContentsObserver::ShouldTrackNavigation( 599 bool MetricsWebContentsObserver::ShouldTrackNavigation(
614 content::NavigationHandle* navigation_handle) const { 600 content::NavigationHandle* navigation_handle) const {
615 DCHECK(navigation_handle->IsInMainFrame()); 601 DCHECK(navigation_handle->IsInMainFrame());
616 DCHECK(!navigation_handle->HasCommitted() || 602 DCHECK(!navigation_handle->HasCommitted() ||
617 !navigation_handle->IsSameDocument()); 603 !navigation_handle->IsSameDocument());
618 604
619 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(), 605 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(),
620 navigation_handle).ShouldTrack(); 606 navigation_handle).ShouldTrack();
(...skipping 21 matching lines...) Expand all
642 observer_->RemoveTestingObserver(this); 628 observer_->RemoveTestingObserver(this);
643 observer_ = nullptr; 629 observer_ = nullptr;
644 } 630 }
645 } 631 }
646 632
647 void MetricsWebContentsObserver::TestingObserver::OnGoingAway() { 633 void MetricsWebContentsObserver::TestingObserver::OnGoingAway() {
648 observer_ = nullptr; 634 observer_ = nullptr;
649 } 635 }
650 636
651 } // namespace page_load_metrics 637 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698