Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/page_load_metrics/browser/page_load_metrics_web_contents_ob server.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/metrics/histogram.h" | |
| 9 #include "components/page_load_metrics/common/page_load_metrics_messages.h" | |
| 10 #include "components/page_load_metrics/common/page_load_timing.h" | |
| 11 #include "content/public/browser/navigation_details.h" | |
| 12 #include "content/public/browser/navigation_handle.h" | |
| 13 #include "content/public/browser/render_frame_host.h" | |
| 14 #include "content/public/browser/web_contents.h" | |
| 15 #include "content/public/browser/web_contents_observer.h" | |
| 16 #include "content/public/browser/web_contents_user_data.h" | |
| 17 #include "ipc/ipc_message.h" | |
| 18 #include "ipc/ipc_message_macros.h" | |
| 19 | |
| 20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(page_load_metrics::WebContentsObserver); | |
| 21 | |
| 22 namespace page_load_metrics { | |
| 23 | |
| 24 WebContentsObserver::WebContentsObserver(content::WebContents* web_contents) | |
| 25 : content::WebContentsObserver(web_contents) {} | |
| 26 | |
| 27 WebContentsObserver::~WebContentsObserver() { | |
| 28 RecordTimingHistograms(); | |
|
Bryan McQuade
2015/09/02 18:26:45
can we add a short comment here noting why it's co
Charlie Harrison
2015/09/03 14:00:52
This gets invoked when a tab is closed, and when w
| |
| 29 } | |
| 30 | |
| 31 bool WebContentsObserver::OnMessageReceived( | |
| 32 const IPC::Message& message, | |
| 33 content::RenderFrameHost* render_frame_host) { | |
| 34 bool handled = true; | |
|
Bryan McQuade
2015/09/02 18:26:45
just to sanity check, can we add a DCHECK that thi
Bryan McQuade
2015/09/02 18:38:31
actually, if you confirm that this does get invoke
Charlie Harrison
2015/09/03 14:00:52
Let's add a DCHECK. Do you know an easy way to see
Bryan McQuade
2015/09/03 20:23:37
I think you can do:
DCHECK(BrowserThread::Currentl
| |
| 35 IPC_BEGIN_MESSAGE_MAP(WebContentsObserver, message) | |
| 36 IPC_MESSAGE_HANDLER(PageLoadMetricsMsg_TimingUpdated, OnTimingUpdated) | |
| 37 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 38 IPC_END_MESSAGE_MAP() | |
| 39 return handled; | |
| 40 } | |
| 41 | |
| 42 void WebContentsObserver::DidCommitNavigation( | |
| 43 content::NavigationHandle* navigation_handle) { | |
| 44 if (!navigation_handle->IsInMainFrame()) | |
| 45 return; | |
| 46 | |
| 47 if (!navigation_handle->HasCommittedDocument()) | |
| 48 return; | |
| 49 | |
| 50 const GURL& url = navigation_handle->GetURL(); | |
| 51 const GURL& browser_url = GetLastCommittedURL(); | |
| 52 if (!url.SchemeIsHTTPOrHTTPS() && !browser_url.SchemeIsHTTPOrHTTPS()) | |
|
Bryan McQuade
2015/09/02 18:26:45
does this want to be || rather than &&?
in partic
Charlie Harrison
2015/09/03 14:00:52
Done. Will draft a bug soon.
| |
| 53 return; | |
| 54 RecordTimingHistograms(); | |
| 55 current_timing_ = pending_timing_; | |
| 56 pending_timing_ = PageLoadTiming(); | |
| 57 } | |
| 58 | |
| 59 void WebContentsObserver::RenderProcessGone(base::TerminationStatus status) { | |
| 60 RecordTimingHistograms(); | |
| 61 } | |
| 62 | |
| 63 #define PAGE_LOAD_HISTOGRAM(name, sample) \ | |
| 64 UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, \ | |
| 65 base::TimeDelta::FromMilliseconds(10), \ | |
| 66 base::TimeDelta::FromMinutes(10), 100); | |
| 67 | |
| 68 void WebContentsObserver::OnTimingUpdated(const PageLoadTiming& timing) { | |
| 69 if (!GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) | |
|
Bryan McQuade
2015/09/02 18:26:45
let's add a short comment here to note the specifi
Charlie Harrison
2015/09/03 14:00:52
Done.
| |
| 70 return; | |
| 71 | |
| 72 if (timing.IsChild(current_timing_)) { | |
|
Bryan McQuade
2015/09/02 18:26:45
in general (throughout this change), you can remov
| |
| 73 current_timing_ = timing; | |
| 74 } else if (timing.IsChild(pending_timing_)) { | |
|
Bryan McQuade
2015/09/02 18:26:45
I'm not following what's going on with these if/el
Charlie Harrison
2015/09/03 14:00:52
I think I'm going to remove the pending_timing fol
| |
| 75 pending_timing_ = timing; | |
| 76 } else { | |
| 77 NOTREACHED(); | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 void WebContentsObserver::RecordTimingHistograms() { | |
| 82 PageLoadTiming timing = current_timing_; | |
|
Bryan McQuade
2015/09/02 18:26:45
I don't think you need to take a function-scoped c
Charlie Harrison
2015/09/03 14:00:52
Done.
| |
| 83 if (timing.IsComplete()) | |
| 84 DCHECK(timing.IsOrdered()); | |
| 85 else if (timing.IsEmpty()) | |
|
Bryan McQuade
2015/09/02 18:26:45
nit: I'd do the test for timing.IsEmpty() before t
Charlie Harrison
2015/09/03 14:00:52
Done.
| |
| 86 return; | |
| 87 | |
| 88 if (!timing.dom_content_loaded_event_start.is_zero()) { | |
| 89 PAGE_LOAD_HISTOGRAM("PageLoad.Timing.DOMContentLoadedEventFired", | |
| 90 timing.dom_content_loaded_event_start); | |
| 91 } | |
| 92 | |
| 93 if (!timing.load_event_start.is_zero()) { | |
| 94 PAGE_LOAD_HISTOGRAM("PageLoad.Timing.LoadEventFired", | |
| 95 timing.load_event_start); | |
| 96 } | |
| 97 | |
| 98 if (!timing.first_layout.is_zero()) { | |
| 99 PAGE_LOAD_HISTOGRAM("PageLoad.Timing.FirstLayout", timing.first_layout); | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 const GURL& WebContentsObserver::GetLastCommittedURL() { | |
|
Bryan McQuade
2015/09/02 18:26:45
unless you need to override the implementation of
Charlie Harrison
2015/09/02 18:38:24
The reason is so we don't have to mock an entire W
Bryan McQuade
2015/09/02 18:40:27
Ok, that seems like a good reason - in that case y
Bryan McQuade
2015/09/03 12:04:29
Actually, it's been a while since I used private v
| |
| 104 return web_contents()->GetLastCommittedURL(); | |
| 105 } | |
| 106 | |
| 107 } // namespace page_load_metrics | |
| OLD | NEW |