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

Side by Side Diff: components/page_load_metrics/browser/metrics_web_contents_observer.h

Issue 1357403003: Separate page load metrics for backgrounded pages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only log first background time Created 5 years, 2 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 #ifndef COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSE RVER_H_ 5 #ifndef COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSE RVER_H_
6 #define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSE RVER_H_ 6 #define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSE RVER_H_
7 7
8 #include "base/containers/scoped_ptr_map.h"
8 #include "base/macros.h" 9 #include "base/macros.h"
9 #include "base/time/time.h" 10 #include "base/time/time.h"
10 #include "components/page_load_metrics/common/page_load_timing.h" 11 #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.h"
12 #include "content/public/browser/web_contents_observer.h" 13 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/browser/web_contents_user_data.h" 14 #include "content/public/browser/web_contents_user_data.h"
14 15
15 namespace content { 16 namespace content {
17
Alexei Svitkine (slow) 2015/09/28 21:40:35 Nit: I don't think it's convention to add empty li
16 class NavigationHandle; 18 class NavigationHandle;
17 class RenderFrameHost; 19 class RenderFrameHost;
20
18 } // namespace content 21 } // namespace content
19 22
20 namespace IPC { 23 namespace IPC {
24
21 class Message; 25 class Message;
26
22 } // namespace IPC 27 } // namespace IPC
23 28
24 namespace page_load_metrics { 29 namespace page_load_metrics {
25 30
31 class PageLoadTracker {
32 public:
33 PageLoadTracker(bool in_foreground);
34 ~PageLoadTracker();
35 void Commit();
36 void WebContentsHidden();
37
38 // Returns true if the timing was successfully updated.
39 bool UpdateTiming(const PageLoadTiming& timing);
40
41 private:
42 void RecordTimingHistograms();
43
44 bool has_commit_;
45
46 // Initialize |background_time| to TimeDelta::Max() so that we can see if an
47 // event happened before a background by a simple < comparison. This will work
48 // even if the page was never backgrounded. We record separate metrics for
49 // any web contents that have been backgrounded, because metrics like
50 // layout/paint are delayed artificially when they occur in the bacground.
51 base::TimeDelta background_time;
Alexei Svitkine (slow) 2015/09/28 21:40:35 Nit: _
52
53 PageLoadTiming timing_;
54
55 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker);
56 };
57
26 // MetricsWebContentsObserver logs page load UMA metrics based on 58 // MetricsWebContentsObserver logs page load UMA metrics based on
27 // IPC messages received from a MetricsRenderFrameObserver. 59 // IPC messages received from a MetricsRenderFrameObserver.
28 class MetricsWebContentsObserver 60 class MetricsWebContentsObserver
29 : public content::WebContentsObserver, 61 : public content::WebContentsObserver,
30 public content::WebContentsUserData<MetricsWebContentsObserver> { 62 public content::WebContentsUserData<MetricsWebContentsObserver> {
31 public: 63 public:
32 ~MetricsWebContentsObserver() override; 64 ~MetricsWebContentsObserver() override;
33 65
34 // content::WebContentsObserver implementation: 66 // content::WebContentsObserver implementation:
35 bool OnMessageReceived(const IPC::Message& message, 67 bool OnMessageReceived(const IPC::Message& message,
36 content::RenderFrameHost* render_frame_host) override; 68 content::RenderFrameHost* render_frame_host) override;
37 void DidFinishNavigation( 69 void DidFinishNavigation(
38 content::NavigationHandle* navigation_handle) override; 70 content::NavigationHandle* navigation_handle) override;
39 void RenderProcessGone(base::TerminationStatus status) override; 71 void DidStartNavigation(
72 content::NavigationHandle* navigation_handle) override;
73
74 void WasShown() override;
75 void WasHidden() override;
40 76
41 private: 77 private:
42 explicit MetricsWebContentsObserver(content::WebContents* web_contents); 78 explicit MetricsWebContentsObserver(content::WebContents* web_contents);
43 friend class content::WebContentsUserData<MetricsWebContentsObserver>; 79 friend class content::WebContentsUserData<MetricsWebContentsObserver>;
44 friend class MetricsWebContentsObserverTest; 80 friend class MetricsWebContentsObserverTest;
45 81
46 void OnTimingUpdated(content::RenderFrameHost*, const PageLoadTiming& timing); 82 void OnTimingUpdated(content::RenderFrameHost*, const PageLoadTiming& timing);
47 void RecordTimingHistograms();
48 83
49 bool IsRelevantNavigation(content::NavigationHandle* navigation_handle); 84 bool IsRelevantNavigation(content::NavigationHandle* navigation_handle);
50 85
51 // Will be null before any navigations have committed. When a navigation 86 // True if the web contents is currently in the foreground.
52 // commits we will initialize this as empty. 87 bool in_foreground_;
53 scoped_ptr<PageLoadTiming> current_timing_; 88
89 // This map tracks all of the navigations ongoing that are not committed
90 // yet. Once a navigation is committed, it moves from the map to
91 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only
92 // valid until commit time, when we remove it from the map.
93 base::ScopedPtrMap<content::NavigationHandle*, scoped_ptr<PageLoadTracker>>
94 provisional_loads_;
95 scoped_ptr<PageLoadTracker> committed_load_;
54 96
55 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); 97 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver);
56 }; 98 };
57 99
58 } // namespace page_load_metrics 100 } // namespace page_load_metrics
59 101
60 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O BSERVER_H_ 102 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O BSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698