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/metrics/histogram.h" | |
| 8 #include "components/page_load_metrics/common/page_load_metrics_messages.h" | |
| 9 #include "components/page_load_metrics/common/page_load_timing.h" | |
| 10 #include "content/public/browser/render_frame_host.h" | |
| 11 #include "content/public/browser/web_contents.h" | |
| 12 #include "content/public/browser/web_contents_observer.h" | |
| 13 #include "content/public/browser/web_contents_user_data.h" | |
| 14 #include "ipc/ipc_message.h" | |
| 15 #include "ipc/ipc_message_macros.h" | |
| 16 | |
| 17 DEFINE_WEB_CONTENTS_USER_DATA_KEY( | |
| 18 page_load_metrics::PageLoadMetricsWebContentsObserver); | |
| 19 | |
| 20 namespace page_load_metrics { | |
| 21 | |
| 22 PageLoadMetricsWebContentsObserver::PageLoadMetricsWebContentsObserver( | |
| 23 content::WebContents* web_contents) | |
| 24 : content::WebContentsObserver(web_contents) { | |
| 25 } | |
| 26 | |
| 27 PageLoadMetricsWebContentsObserver::~PageLoadMetricsWebContentsObserver() {} | |
|
nasko
2015/08/26 17:27:24
nit: Be consistent with the constructor. Either {}
| |
| 28 | |
| 29 bool PageLoadMetricsWebContentsObserver::OnMessageReceived( | |
| 30 const IPC::Message& message, content::RenderFrameHost* render_frame_host) { | |
|
nasko
2015/08/26 17:27:24
Each parameter must be on a new line.
| |
| 31 // TODO verify that this is getting called on the thread that other | |
| 32 // WebContentsObserver callbacks get invoked on (browser UI thread?). | |
|
nasko
2015/08/26 17:27:24
WebContentsObserver methods are only called on the
| |
| 33 bool handled = true; | |
| 34 IPC_BEGIN_MESSAGE_MAP(PageLoadMetricsWebContentsObserver, message) | |
| 35 IPC_MESSAGE_HANDLER(PageLoadMetricsMsg_OnTimingUpdated, | |
| 36 OnTimingUpdated) | |
| 37 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 38 IPC_END_MESSAGE_MAP() | |
| 39 return handled; | |
| 40 } | |
| 41 | |
| 42 #if 0 | |
| 43 | |
| 44 // TODO figure out which of these hooks may actually be useful to implement. | |
| 45 | |
| 46 void PageLoadMetricsWebContentsObserver::DidCommitNavigation( | |
| 47 content::NavigationHandle* navigation_handle) { | |
| 48 if (!navigation_handle->IsInMainFrame()) | |
| 49 return; | |
| 50 | |
| 51 if (!navigation_handle->HasCommittedDocument()) | |
| 52 return; | |
| 53 | |
| 54 const GURL& url = navigation_handle->GetURL(); | |
| 55 if (!url.SchemeIsHTTPOrHTTPS()) | |
| 56 return; | |
| 57 | |
| 58 page_timing_metrics_receiver_.reset(new PageTimingMetricsReceiver()); | |
| 59 } | |
| 60 | |
| 61 void PageLoadMetricsWebContentsObserver::DidNavigateMainFrame( | |
| 62 const LoadCommittedDetails& details, | |
| 63 const FrameNavigateParams& params) { | |
| 64 DCHECK(details.is_main_frame); | |
| 65 | |
| 66 // TODO how are the 2 checks below different? | |
| 67 if (details.type != NAVIGATION_TYPE_NEW_PAGE) | |
| 68 return; | |
| 69 if (details.is_in_page) | |
| 70 return; | |
| 71 | |
| 72 } | |
| 73 #endif | |
| 74 | |
| 75 #define PAGE_LOAD_HISTOGRAM(name, sample) \ | |
| 76 UMA_HISTOGRAM_CUSTOM_TIMES(name, \ | |
| 77 sample, \ | |
| 78 base::TimeDelta::FromMilliseconds(10), \ | |
| 79 base::TimeDelta::FromMinutes(10), \ | |
| 80 100); | |
| 81 | |
| 82 void PageLoadMetricsWebContentsObserver::OnTimingUpdated( | |
| 83 const PageLoadTiming& timing) { | |
| 84 // TODO ignore non-HTTP/HTTPS URLs (e.g. chrome://newtab). | |
| 85 | |
| 86 // TODO store the updated timing info, and log it when the next | |
| 87 // navigation occurrs. | |
| 88 } | |
| 89 | |
| 90 // TODO call this when a page is being navigated away from | |
| 91 void PageLoadMetricsWebContentsObserver::RecordTimingHistograms( | |
| 92 const PageLoadTiming& timing) { | |
| 93 if (timing.navigation_start.is_null()) | |
| 94 return; | |
| 95 | |
| 96 if (!timing.dom_content_loaded_event_start.is_null()) | |
| 97 PAGE_LOAD_HISTOGRAM("PageLoad.Timing.DOMContentLoadedEventFired", | |
| 98 timing.dom_content_loaded_event_start - timing.navigation_start); | |
| 99 | |
| 100 if (!timing.load_event_start.is_null()) | |
| 101 PAGE_LOAD_HISTOGRAM("PageLoad.Timing.LoadEventFired", | |
| 102 timing.load_event_start - timing.navigation_start); | |
| 103 | |
| 104 if (!timing.load_event_start.is_null()) | |
| 105 PAGE_LOAD_HISTOGRAM("PageLoad.Timing.FirstLayout", | |
| 106 timing.first_layout - timing.navigation_start); | |
| 107 } | |
| 108 | |
| 109 } // namespace page_load_metrics | |
| OLD | NEW |