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

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: DCHECK nit 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
« no previous file with comments | « no previous file | components/page_load_metrics/browser/metrics_web_contents_observer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {
16 class NavigationHandle; 17 class NavigationHandle;
17 class RenderFrameHost; 18 class RenderFrameHost;
18 } // namespace content 19 } // namespace content
19 20
20 namespace IPC { 21 namespace IPC {
21 class Message; 22 class Message;
22 } // namespace IPC 23 } // namespace IPC
23 24
24 namespace page_load_metrics { 25 namespace page_load_metrics {
25 26
27 class PageLoadTracker {
28 public:
29 explicit PageLoadTracker(bool in_foreground);
30 ~PageLoadTracker();
31 void Commit();
32 void WebContentsHidden();
33
34 // Returns true if the timing was successfully updated.
35 bool UpdateTiming(const PageLoadTiming& timing);
36
37 private:
38 void RecordTimingHistograms();
39
40 bool has_commit_;
41
42 // We record separate metrics for events that occur after a background,
43 // because metrics like layout/paint are delayed artificially
44 // when they occur in the bacground.
45 base::TimeTicks background_time_;
46 bool started_in_foreground_;
47
48 PageLoadTiming timing_;
49
50 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker);
51 };
52
26 // MetricsWebContentsObserver logs page load UMA metrics based on 53 // MetricsWebContentsObserver logs page load UMA metrics based on
27 // IPC messages received from a MetricsRenderFrameObserver. 54 // IPC messages received from a MetricsRenderFrameObserver.
28 class MetricsWebContentsObserver 55 class MetricsWebContentsObserver
29 : public content::WebContentsObserver, 56 : public content::WebContentsObserver,
30 public content::WebContentsUserData<MetricsWebContentsObserver> { 57 public content::WebContentsUserData<MetricsWebContentsObserver> {
31 public: 58 public:
32 ~MetricsWebContentsObserver() override; 59 ~MetricsWebContentsObserver() override;
33 60
34 // content::WebContentsObserver implementation: 61 // content::WebContentsObserver implementation:
35 bool OnMessageReceived(const IPC::Message& message, 62 bool OnMessageReceived(const IPC::Message& message,
36 content::RenderFrameHost* render_frame_host) override; 63 content::RenderFrameHost* render_frame_host) override;
64 void DidStartNavigation(
65 content::NavigationHandle* navigation_handle) override;
37 void DidFinishNavigation( 66 void DidFinishNavigation(
38 content::NavigationHandle* navigation_handle) override; 67 content::NavigationHandle* navigation_handle) override;
68
69 void WasShown() override;
70 void WasHidden() override;
71
39 void RenderProcessGone(base::TerminationStatus status) override; 72 void RenderProcessGone(base::TerminationStatus status) override;
40 73
41 private: 74 private:
42 explicit MetricsWebContentsObserver(content::WebContents* web_contents); 75 explicit MetricsWebContentsObserver(content::WebContents* web_contents);
43 friend class content::WebContentsUserData<MetricsWebContentsObserver>; 76 friend class content::WebContentsUserData<MetricsWebContentsObserver>;
44 friend class MetricsWebContentsObserverTest; 77 friend class MetricsWebContentsObserverTest;
45 78
46 void OnTimingUpdated(content::RenderFrameHost*, const PageLoadTiming& timing); 79 void OnTimingUpdated(content::RenderFrameHost*, const PageLoadTiming& timing);
47 void RecordTimingHistograms();
48 80
49 bool IsRelevantNavigation(content::NavigationHandle* navigation_handle); 81 bool IsRelevantNavigation(content::NavigationHandle* navigation_handle);
50 82
51 // Will be null before any navigations have committed. When a navigation 83 // True if the web contents is currently in the foreground.
52 // commits we will initialize this as empty. 84 bool in_foreground_;
53 scoped_ptr<PageLoadTiming> current_timing_; 85
86 // This map tracks all of the navigations ongoing that are not committed
87 // yet. Once a navigation is committed, it moves from the map to
88 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only
89 // valid until commit time, when we remove it from the map.
90 base::ScopedPtrMap<content::NavigationHandle*, scoped_ptr<PageLoadTracker>>
91 provisional_loads_;
92 scoped_ptr<PageLoadTracker> committed_load_;
54 93
55 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); 94 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver);
56 }; 95 };
57 96
58 } // namespace page_load_metrics 97 } // namespace page_load_metrics
59 98
60 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O BSERVER_H_ 99 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O BSERVER_H_
OLDNEW
« no previous file with comments | « no previous file | components/page_load_metrics/browser/metrics_web_contents_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698