| 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 "content/public/browser/render_frame_host.h" |
| 10 #include "content/public/browser/web_contents.h" |
| 11 #include "content/public/browser/web_contents_observer.h" |
| 12 #include "content/public/browser/web_contents_user_data.h" |
| 13 #include "ipc/ipc_message.h" |
| 14 #include "ipc/ipc_message_macros.h" |
| 15 |
| 16 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
| 17 page_load_metrics::PageLoadMetricsWebContentsObserver); |
| 18 |
| 19 namespace page_load_metrics { |
| 20 |
| 21 PageLoadMetricsWebContentsObserver::PageLoadMetricsWebContentsObserver( |
| 22 content::WebContents* web_contents) |
| 23 : content::WebContentsObserver(web_contents) { |
| 24 } |
| 25 |
| 26 PageLoadMetricsWebContentsObserver::~PageLoadMetricsWebContentsObserver() {} |
| 27 |
| 28 bool PageLoadMetricsWebContentsObserver::OnMessageReceived( |
| 29 const IPC::Message& message, content::RenderFrameHost* render_frame_host) { |
| 30 bool handled = true; |
| 31 IPC_BEGIN_MESSAGE_MAP(PageLoadMetricsWebContentsObserver, message) |
| 32 IPC_MESSAGE_HANDLER(PageLoadMetricsMsg_DOMContentLoadedEvent, |
| 33 OnDOMContentLoadedEvent) |
| 34 IPC_MESSAGE_HANDLER(PageLoadMetricsMsg_LoadEvent, OnLoadEvent) |
| 35 IPC_MESSAGE_HANDLER(PageLoadMetricsMsg_FirstLayout, OnFirstLayout) |
| 36 IPC_MESSAGE_UNHANDLED(handled = false) |
| 37 IPC_END_MESSAGE_MAP() |
| 38 return handled; |
| 39 } |
| 40 |
| 41 #define PAGE_LOAD_HISTOGRAM(name, sample) \ |
| 42 UMA_HISTOGRAM_CUSTOM_TIMES(name, \ |
| 43 sample, \ |
| 44 base::TimeDelta::FromMilliseconds(10), \ |
| 45 base::TimeDelta::FromMinutes(10), \ |
| 46 100); |
| 47 |
| 48 void PageLoadMetricsWebContentsObserver::OnDOMContentLoadedEvent( |
| 49 base::TimeDelta dom_content_loaded_event) { |
| 50 PAGE_LOAD_HISTOGRAM( |
| 51 "PageLoad.Timing.DOMContentLoadedEventFired", dom_content_loaded_event); |
| 52 } |
| 53 |
| 54 void PageLoadMetricsWebContentsObserver::OnLoadEvent( |
| 55 base::TimeDelta load_event) { |
| 56 PAGE_LOAD_HISTOGRAM("PageLoad.Timing.LoadEventFired", load_event); |
| 57 } |
| 58 |
| 59 void PageLoadMetricsWebContentsObserver::OnFirstLayout( |
| 60 base::TimeDelta first_layout) { |
| 61 PAGE_LOAD_HISTOGRAM("PageLoad.Timing.FirstLayout", first_layout); |
| 62 } |
| 63 |
| 64 } // namespace page_load_metrics |
| OLD | NEW |