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.
5 #ifndef COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSERVER_H_
6 #define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSERVER_H_
8 #include "base/macros.h"
9 #include "base/time/time.h"
10 #include "components/page_load_metrics/common/page_load_timing.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"
16 class NavigationHandle
;
17 class RenderFrameHost
;
18 } // namespace content
24 namespace page_load_metrics
{
26 // MetricsWebContentsObserver logs page load UMA metrics based on
27 // IPC messages received from a MetricsRenderFrameObserver.
28 class MetricsWebContentsObserver
29 : public content::WebContentsObserver
,
30 public content::WebContentsUserData
<MetricsWebContentsObserver
> {
32 ~MetricsWebContentsObserver() override
;
34 // content::WebContentsObserver implementation:
35 bool OnMessageReceived(const IPC::Message
& message
,
36 content::RenderFrameHost
* render_frame_host
) override
;
37 void DidCommitNavigation(
38 content::NavigationHandle
* navigation_handle
) override
;
39 void RenderProcessGone(base::TerminationStatus status
) override
;
42 explicit MetricsWebContentsObserver(content::WebContents
* web_contents
);
43 friend class content::WebContentsUserData
<MetricsWebContentsObserver
>;
44 friend class MetricsWebContentsObserverTest
;
46 void OnTimingUpdated(content::RenderFrameHost
*, const PageLoadTiming
& timing
);
47 void RecordTimingHistograms();
49 bool IsRelevantNavigation(content::NavigationHandle
* navigation_handle
);
51 // Will be null before any navigations have committed. When a navigation
52 // commits we will initialize this as empty.
53 scoped_ptr
<PageLoadTiming
> current_timing_
;
55 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver
);
58 } // namespace page_load_metrics
60 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSERVER_H_