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

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

Issue 2847803002: Revert of Break page load metrics test dependency on IPC. (Closed)
Patch Set: Created 3 years, 7 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 | chrome/browser/page_load_metrics/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 CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_ 5 #ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_
6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_ 6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/observer_list.h"
14 #include "base/time/time.h" 13 #include "base/time/time.h"
15 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" 14 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h"
16 #include "chrome/common/page_load_metrics/page_load_timing.h" 15 #include "chrome/common/page_load_metrics/page_load_timing.h"
17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h" 16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h"
18 #include "content/public/browser/render_widget_host.h" 17 #include "content/public/browser/render_widget_host.h"
19 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
20 #include "content/public/browser/web_contents_observer.h" 19 #include "content/public/browser/web_contents_observer.h"
21 #include "content/public/browser/web_contents_user_data.h" 20 #include "content/public/browser/web_contents_user_data.h"
22 #include "content/public/common/resource_type.h" 21 #include "content/public/common/resource_type.h"
23 #include "third_party/WebKit/public/platform/WebInputEvent.h" 22 #include "third_party/WebKit/public/platform/WebInputEvent.h"
(...skipping 13 matching lines...) Expand all
37 class PageLoadTracker; 36 class PageLoadTracker;
38 37
39 // MetricsWebContentsObserver tracks page loads and loading metrics 38 // MetricsWebContentsObserver tracks page loads and loading metrics
40 // related data based on IPC messages received from a 39 // related data based on IPC messages received from a
41 // MetricsRenderFrameObserver. 40 // MetricsRenderFrameObserver.
42 class MetricsWebContentsObserver 41 class MetricsWebContentsObserver
43 : public content::WebContentsObserver, 42 : public content::WebContentsObserver,
44 public content::WebContentsUserData<MetricsWebContentsObserver>, 43 public content::WebContentsUserData<MetricsWebContentsObserver>,
45 public content::RenderWidgetHost::InputEventObserver { 44 public content::RenderWidgetHost::InputEventObserver {
46 public: 45 public:
47 // TestingObserver allows tests to observe MetricsWebContentsObserver state
48 // changes. Tests may use TestingObserver to wait until certain state changes,
49 // such as the arrivial of PageLoadTiming messages from the render process,
50 // have been observed.
51 class TestingObserver {
52 public:
53 explicit TestingObserver(content::WebContents* web_contents);
54 virtual ~TestingObserver();
55
56 void OnGoingAway();
57
58 // Invoked when a new PageLoadTiming update has been received and processed.
59 virtual void OnTimingUpdated(const PageLoadTiming& timing,
60 const PageLoadMetadata& metadata) {}
61
62 private:
63 page_load_metrics::MetricsWebContentsObserver* observer_;
64
65 DISALLOW_COPY_AND_ASSIGN(TestingObserver);
66 };
67
68 // Note that the returned metrics is owned by the web contents. 46 // Note that the returned metrics is owned by the web contents.
69 static MetricsWebContentsObserver* CreateForWebContents( 47 static MetricsWebContentsObserver* CreateForWebContents(
70 content::WebContents* web_contents, 48 content::WebContents* web_contents,
71 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); 49 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface);
72 MetricsWebContentsObserver( 50 MetricsWebContentsObserver(
73 content::WebContents* web_contents, 51 content::WebContents* web_contents,
74 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); 52 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface);
75 ~MetricsWebContentsObserver() override; 53 ~MetricsWebContentsObserver() override;
76 54
77 // content::WebContentsObserver implementation: 55 // content::WebContentsObserver implementation:
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 96
119 // Flush any buffered metrics, as part of the metrics subsystem persisting 97 // Flush any buffered metrics, as part of the metrics subsystem persisting
120 // metrics as the application goes into the background. The application may be 98 // metrics as the application goes into the background. The application may be
121 // killed at any time after this method is invoked without further 99 // killed at any time after this method is invoked without further
122 // notification. 100 // notification.
123 void FlushMetricsOnAppEnterBackground(); 101 void FlushMetricsOnAppEnterBackground();
124 102
125 // This getter function is required for testing. 103 // This getter function is required for testing.
126 const PageLoadExtraInfo GetPageLoadExtraInfoForCommittedLoad(); 104 const PageLoadExtraInfo GetPageLoadExtraInfoForCommittedLoad();
127 105
128 // Register / unregister TestingObservers. Should only be called from tests.
129 void AddTestingObserver(TestingObserver* observer);
130 void RemoveTestingObserver(TestingObserver* observer);
131
132 // public only for testing
133 void OnTimingUpdated(content::RenderFrameHost* render_frame_host,
134 const PageLoadTiming& timing,
135 const PageLoadMetadata& metadata);
136
137 private: 106 private:
138 friend class content::WebContentsUserData<MetricsWebContentsObserver>; 107 friend class content::WebContentsUserData<MetricsWebContentsObserver>;
139 108
140 void HandleFailedNavigationForTrackedLoad( 109 void HandleFailedNavigationForTrackedLoad(
141 content::NavigationHandle* navigation_handle, 110 content::NavigationHandle* navigation_handle,
142 std::unique_ptr<PageLoadTracker> tracker); 111 std::unique_ptr<PageLoadTracker> tracker);
143 112
144 void HandleCommittedNavigationForTrackedLoad( 113 void HandleCommittedNavigationForTrackedLoad(
145 content::NavigationHandle* navigation_handle, 114 content::NavigationHandle* navigation_handle,
146 std::unique_ptr<PageLoadTracker> tracker); 115 std::unique_ptr<PageLoadTracker> tracker);
(...skipping 20 matching lines...) Expand all
167 void UnregisterInputEventObserver(content::RenderViewHost* host); 136 void UnregisterInputEventObserver(content::RenderViewHost* host);
168 137
169 // Notify aborted provisional loads that a new navigation occurred. This is 138 // Notify aborted provisional loads that a new navigation occurred. This is
170 // used for more consistent attribution tracking for aborted provisional 139 // used for more consistent attribution tracking for aborted provisional
171 // loads. This method returns the provisional load that was likely aborted 140 // loads. This method returns the provisional load that was likely aborted
172 // by this navigation, to help instantiate the new PageLoadTracker. 141 // by this navigation, to help instantiate the new PageLoadTracker.
173 std::unique_ptr<PageLoadTracker> NotifyAbortedProvisionalLoadsNewNavigation( 142 std::unique_ptr<PageLoadTracker> NotifyAbortedProvisionalLoadsNewNavigation(
174 content::NavigationHandle* new_navigation, 143 content::NavigationHandle* new_navigation,
175 UserInitiatedInfo user_initiated_info); 144 UserInitiatedInfo user_initiated_info);
176 145
146 void OnTimingUpdated(content::RenderFrameHost*,
147 const PageLoadTiming& timing,
148 const PageLoadMetadata& metadata);
149
177 bool ShouldTrackNavigation( 150 bool ShouldTrackNavigation(
178 content::NavigationHandle* navigation_handle) const; 151 content::NavigationHandle* navigation_handle) const;
179 152
180 // True if the web contents is currently in the foreground. 153 // True if the web contents is currently in the foreground.
181 bool in_foreground_; 154 bool in_foreground_;
182 155
183 // The PageLoadTrackers must be deleted before the |embedder_interface_|, 156 // The PageLoadTrackers must be deleted before the |embedder_interface_|,
184 // because they hold a pointer to the |embedder_interface_|. 157 // because they hold a pointer to the |embedder_interface_|.
185 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_; 158 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_;
186 159
187 // This map tracks all of the navigations ongoing that are not committed 160 // This map tracks all of the navigations ongoing that are not committed
188 // yet. Once a navigation is committed, it moves from the map to 161 // yet. Once a navigation is committed, it moves from the map to
189 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only 162 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only
190 // valid until commit time, when we remove it from the map. 163 // valid until commit time, when we remove it from the map.
191 std::map<content::NavigationHandle*, std::unique_ptr<PageLoadTracker>> 164 std::map<content::NavigationHandle*, std::unique_ptr<PageLoadTracker>>
192 provisional_loads_; 165 provisional_loads_;
193 166
194 // Tracks aborted provisional loads for a little bit longer than usual (one 167 // Tracks aborted provisional loads for a little bit longer than usual (one
195 // more navigation commit at the max), in order to better understand how the 168 // more navigation commit at the max), in order to better understand how the
196 // navigation failed. This is because most provisional loads are destroyed 169 // navigation failed. This is because most provisional loads are destroyed
197 // and vanish before we get signal about what caused the abort (new 170 // and vanish before we get signal about what caused the abort (new
198 // navigation, stop button, etc.). 171 // navigation, stop button, etc.).
199 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_; 172 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_;
200 173
201 std::unique_ptr<PageLoadTracker> committed_load_; 174 std::unique_ptr<PageLoadTracker> committed_load_;
202 175
203 // Has the MWCO observed at least one navigation? 176 // Has the MWCO observed at least one navigation?
204 bool has_navigated_; 177 bool has_navigated_;
205 178
206 base::ObserverList<TestingObserver> testing_observers_;
207
208 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); 179 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver);
209 }; 180 };
210 181
211 } // namespace page_load_metrics 182 } // namespace page_load_metrics
212 183
213 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_ 184 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/page_load_metrics/metrics_web_contents_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698