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

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

Issue 1921923002: Convert //components/[o-t]* from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 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
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_METRICS_WEB_CONTENTS_OBSERVER_H_ 5 #ifndef COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_
6 #define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_ 6 #define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "components/page_load_metrics/browser/page_load_metrics_observer.h" 15 #include "components/page_load_metrics/browser/page_load_metrics_observer.h"
15 #include "components/page_load_metrics/common/page_load_timing.h" 16 #include "components/page_load_metrics/common/page_load_timing.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_contents_observer.h" 18 #include "content/public/browser/web_contents_observer.h"
18 #include "content/public/browser/web_contents_user_data.h" 19 #include "content/public/browser/web_contents_user_data.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 bool renderer_tracked() const { return renderer_tracked_; } 132 bool renderer_tracked() const { return renderer_tracked_; }
132 133
133 int aborted_chain_size() const { return aborted_chain_size_; } 134 int aborted_chain_size() const { return aborted_chain_size_; }
134 int aborted_chain_size_same_url() const { 135 int aborted_chain_size_same_url() const {
135 return aborted_chain_size_same_url_; 136 return aborted_chain_size_same_url_;
136 } 137 }
137 138
138 UserAbortType abort_type() const { return abort_type_; } 139 UserAbortType abort_type() const { return abort_type_; }
139 base::TimeTicks abort_time() const { return abort_time_; } 140 base::TimeTicks abort_time() const { return abort_time_; }
140 141
141 void AddObserver(scoped_ptr<PageLoadMetricsObserver> observer); 142 void AddObserver(std::unique_ptr<PageLoadMetricsObserver> observer);
142 143
143 // If the user performs some abort-like action while we are tracking this page 144 // If the user performs some abort-like action while we are tracking this page
144 // load, notify the tracker. Note that we may not classify this as an abort if 145 // load, notify the tracker. Note that we may not classify this as an abort if
145 // we've already performed a first paint. 146 // we've already performed a first paint.
146 void NotifyAbort(UserAbortType abort_type, base::TimeTicks timestamp); 147 void NotifyAbort(UserAbortType abort_type, base::TimeTicks timestamp);
147 void UpdateAbort(UserAbortType abort_type, base::TimeTicks timestamp); 148 void UpdateAbort(UserAbortType abort_type, base::TimeTicks timestamp);
148 149
149 // This method returns true if this page load has been aborted with type of 150 // This method returns true if this page load has been aborted with type of
150 // ABORT_OTHER, and the |abort_cause_time| is within a sufficiently close 151 // ABORT_OTHER, and the |abort_cause_time| is within a sufficiently close
151 // delta to when it was aborted. Note that only provisional loads can be 152 // delta to when it was aborted. Note that only provisional loads can be
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // reload will produce a long chain with the RELOAD transition. 210 // reload will produce a long chain with the RELOAD transition.
210 const int aborted_chain_size_; 211 const int aborted_chain_size_;
211 212
212 // This member counts consecutive provisional aborts that share a url. It will 213 // This member counts consecutive provisional aborts that share a url. It will
213 // always be less than or equal to |aborted_chain_size_|. 214 // always be less than or equal to |aborted_chain_size_|.
214 const int aborted_chain_size_same_url_; 215 const int aborted_chain_size_same_url_;
215 216
216 // Interface to chrome features. Must outlive the class. 217 // Interface to chrome features. Must outlive the class.
217 PageLoadMetricsEmbedderInterface* const embedder_interface_; 218 PageLoadMetricsEmbedderInterface* const embedder_interface_;
218 219
219 std::vector<scoped_ptr<PageLoadMetricsObserver>> observers_; 220 std::vector<std::unique_ptr<PageLoadMetricsObserver>> observers_;
220 221
221 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker); 222 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker);
222 }; 223 };
223 224
224 // MetricsWebContentsObserver tracks page loads and loading metrics 225 // MetricsWebContentsObserver tracks page loads and loading metrics
225 // related data based on IPC messages received from a 226 // related data based on IPC messages received from a
226 // MetricsRenderFrameObserver. 227 // MetricsRenderFrameObserver.
227 class MetricsWebContentsObserver 228 class MetricsWebContentsObserver
228 : public content::WebContentsObserver, 229 : public content::WebContentsObserver,
229 public content::WebContentsUserData<MetricsWebContentsObserver> { 230 public content::WebContentsUserData<MetricsWebContentsObserver> {
230 public: 231 public:
231 // Note that the returned metrics is owned by the web contents. 232 // Note that the returned metrics is owned by the web contents.
232 static MetricsWebContentsObserver* CreateForWebContents( 233 static MetricsWebContentsObserver* CreateForWebContents(
233 content::WebContents* web_contents, 234 content::WebContents* web_contents,
234 scoped_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); 235 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface);
235 MetricsWebContentsObserver( 236 MetricsWebContentsObserver(
236 content::WebContents* web_contents, 237 content::WebContents* web_contents,
237 scoped_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); 238 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface);
238 ~MetricsWebContentsObserver() override; 239 ~MetricsWebContentsObserver() override;
239 240
240 // content::WebContentsObserver implementation: 241 // content::WebContentsObserver implementation:
241 bool OnMessageReceived(const IPC::Message& message, 242 bool OnMessageReceived(const IPC::Message& message,
242 content::RenderFrameHost* render_frame_host) override; 243 content::RenderFrameHost* render_frame_host) override;
243 void DidStartNavigation( 244 void DidStartNavigation(
244 content::NavigationHandle* navigation_handle) override; 245 content::NavigationHandle* navigation_handle) override;
245 void DidFinishNavigation( 246 void DidFinishNavigation(
246 content::NavigationHandle* navigation_handle) override; 247 content::NavigationHandle* navigation_handle) override;
247 void DidRedirectNavigation( 248 void DidRedirectNavigation(
248 content::NavigationHandle* navigation_handle) override; 249 content::NavigationHandle* navigation_handle) override;
249 void NavigationStopped() override; 250 void NavigationStopped() override;
250 void WasShown() override; 251 void WasShown() override;
251 void WasHidden() override; 252 void WasHidden() override;
252 void RenderProcessGone(base::TerminationStatus status) override; 253 void RenderProcessGone(base::TerminationStatus status) override;
253 254
254 private: 255 private:
255 friend class content::WebContentsUserData<MetricsWebContentsObserver>; 256 friend class content::WebContentsUserData<MetricsWebContentsObserver>;
256 257
257 // Notify all loads, provisional and committed, that we performed an action 258 // Notify all loads, provisional and committed, that we performed an action
258 // that might abort them. 259 // that might abort them.
259 void NotifyAbortAllLoads(UserAbortType abort_type); 260 void NotifyAbortAllLoads(UserAbortType abort_type);
260 void NotifyAbortAllLoadsWithTimestamp(UserAbortType abort_type, 261 void NotifyAbortAllLoadsWithTimestamp(UserAbortType abort_type,
261 base::TimeTicks timestamp); 262 base::TimeTicks timestamp);
262 // Notify aborted provisional loads that a new navigation occurred. This is 263 // Notify aborted provisional loads that a new navigation occurred. This is
263 // used for more consistent attribution tracking for aborted provisional 264 // used for more consistent attribution tracking for aborted provisional
264 // loads. This method returns the provisional load that was likely aborted by 265 // loads. This method returns the provisional load that was likely aborted by
265 // this navigation, to help instantiate the new PageLoadTracker. 266 // this navigation, to help instantiate the new PageLoadTracker.
266 scoped_ptr<PageLoadTracker> NotifyAbortedProvisionalLoadsNewNavigation( 267 std::unique_ptr<PageLoadTracker> NotifyAbortedProvisionalLoadsNewNavigation(
267 content::NavigationHandle* new_navigation); 268 content::NavigationHandle* new_navigation);
268 269
269 void OnTimingUpdated(content::RenderFrameHost*, 270 void OnTimingUpdated(content::RenderFrameHost*,
270 const PageLoadTiming& timing, 271 const PageLoadTiming& timing,
271 const PageLoadMetadata& metadata); 272 const PageLoadMetadata& metadata);
272 273
273 // True if the web contents is currently in the foreground. 274 // True if the web contents is currently in the foreground.
274 bool in_foreground_; 275 bool in_foreground_;
275 276
276 // The PageLoadTrackers must be deleted before the |embedded_interface_|, 277 // The PageLoadTrackers must be deleted before the |embedded_interface_|,
277 // because they hold a pointer to the |embedder_interface_|. 278 // because they hold a pointer to the |embedder_interface_|.
278 scoped_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_; 279 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_;
279 280
280 // This map tracks all of the navigations ongoing that are not committed 281 // This map tracks all of the navigations ongoing that are not committed
281 // yet. Once a navigation is committed, it moves from the map to 282 // yet. Once a navigation is committed, it moves from the map to
282 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only 283 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only
283 // valid until commit time, when we remove it from the map. 284 // valid until commit time, when we remove it from the map.
284 std::map<content::NavigationHandle*, scoped_ptr<PageLoadTracker>> 285 std::map<content::NavigationHandle*, std::unique_ptr<PageLoadTracker>>
285 provisional_loads_; 286 provisional_loads_;
286 287
287 // Tracks aborted provisional loads for a little bit longer than usual (one 288 // Tracks aborted provisional loads for a little bit longer than usual (one
288 // more navigation commit at the max), in order to better understand how the 289 // more navigation commit at the max), in order to better understand how the
289 // navigation failed. This is because most provisional loads are destroyed and 290 // navigation failed. This is because most provisional loads are destroyed and
290 // vanish before we get signal about what caused the abort (new navigation, 291 // vanish before we get signal about what caused the abort (new navigation,
291 // stop button, etc.). 292 // stop button, etc.).
292 std::vector<scoped_ptr<PageLoadTracker>> aborted_provisional_loads_; 293 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_;
293 294
294 scoped_ptr<PageLoadTracker> committed_load_; 295 std::unique_ptr<PageLoadTracker> committed_load_;
295 296
296 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); 297 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver);
297 }; 298 };
298 299
299 } // namespace page_load_metrics 300 } // namespace page_load_metrics
300 301
301 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_ 302 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_
OLDNEW
« no previous file with comments | « components/ownership/owner_settings_service.cc ('k') | 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