OLD | NEW |
---|---|
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/containers/scoped_ptr_map.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "components/page_load_metrics/common/page_load_timing.h" | 11 #include "components/page_load_metrics/common/page_load_timing.h" |
12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
13 #include "content/public/browser/web_contents_observer.h" | 13 #include "content/public/browser/web_contents_observer.h" |
14 #include "content/public/browser/web_contents_user_data.h" | 14 #include "content/public/browser/web_contents_user_data.h" |
15 #include "net/base/net_errors.h" | |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 class NavigationHandle; | 18 class NavigationHandle; |
18 class RenderFrameHost; | 19 class RenderFrameHost; |
19 } // namespace content | 20 } // namespace content |
20 | 21 |
21 namespace IPC { | 22 namespace IPC { |
22 class Message; | 23 class Message; |
23 } // namespace IPC | 24 } // namespace IPC |
24 | 25 |
25 namespace page_load_metrics { | 26 namespace page_load_metrics { |
26 | 27 |
28 // If you add or remove elements from this enum, make sure you update the enum | |
Alexei Svitkine (slow)
2015/10/02 14:57:14
Nit: Please rephrase this, as current comment impl
| |
29 // value in histograms.xml. | |
30 enum PageLoadEvent { | |
31 PAGE_LOAD_STARTED, | |
32 | |
33 // A provisional load is a load before it commits, i.e. before it receives the | |
34 // first bytes of the response body or knows the encoding of the response | |
35 // body. A load failed before it was committed for any reason, e.g. from a | |
36 // user abort or a network timeout. | |
37 PAGE_LOAD_FAILED_BEFORE_COMMIT, | |
38 | |
39 // A subset of PAGE_LOAD_FAILED_BEFORE_COMMIT, this counts the | |
40 // specific failures due to user aborts. | |
41 PAGE_LOAD_ABORTED_BEFORE_COMMIT, | |
42 | |
43 // When a load is aborted anytime before the page's first layout, we increase | |
44 // these counts. This includes all failed provisional loads. | |
45 PAGE_LOAD_ABORTED_BEFORE_FIRST_LAYOUT, | |
46 | |
47 // We increase this count if a page load successfully has a layout. | |
48 // Differentiate between loads that were backgrounded before first layout. | |
49 // Note that a load that is backgrounded, then foregrounded before first | |
50 // layout will still end up in the backgrounded bucket. | |
51 PAGE_LOAD_SUCCESSFUL_FIRST_LAYOUT_FOREGROUND, | |
52 PAGE_LOAD_SUCCESSFUL_FIRST_LAYOUT_BACKGROUND, | |
53 | |
54 // Add values before this final count. | |
55 PAGE_LOAD_LAST_ENTRY | |
56 }; | |
57 | |
27 class PageLoadTracker { | 58 class PageLoadTracker { |
28 public: | 59 public: |
29 explicit PageLoadTracker(bool in_foreground); | 60 explicit PageLoadTracker(bool in_foreground); |
30 ~PageLoadTracker(); | 61 ~PageLoadTracker(); |
31 void Commit(); | 62 void Commit(); |
32 void WebContentsHidden(); | 63 void WebContentsHidden(); |
33 | 64 |
34 // Returns true if the timing was successfully updated. | 65 // Returns true if the timing was successfully updated. |
35 bool UpdateTiming(const PageLoadTiming& timing); | 66 bool UpdateTiming(const PageLoadTiming& timing); |
67 void RecordEvent(PageLoadEvent event); | |
36 | 68 |
37 private: | 69 private: |
38 void RecordTimingHistograms(); | 70 void RecordTimingHistograms(); |
39 | 71 |
40 bool has_commit_; | 72 bool has_commit_; |
41 | 73 |
42 // We record separate metrics for events that occur after a background, | 74 // We record separate metrics for events that occur after a background, |
43 // because metrics like layout/paint are delayed artificially | 75 // because metrics like layout/paint are delayed artificially |
44 // when they occur in the bacground. | 76 // when they occur in the bacground. |
45 base::TimeTicks background_time_; | 77 base::TimeTicks background_time_; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 base::ScopedPtrMap<content::NavigationHandle*, scoped_ptr<PageLoadTracker>> | 122 base::ScopedPtrMap<content::NavigationHandle*, scoped_ptr<PageLoadTracker>> |
91 provisional_loads_; | 123 provisional_loads_; |
92 scoped_ptr<PageLoadTracker> committed_load_; | 124 scoped_ptr<PageLoadTracker> committed_load_; |
93 | 125 |
94 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); | 126 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); |
95 }; | 127 }; |
96 | 128 |
97 } // namespace page_load_metrics | 129 } // namespace page_load_metrics |
98 | 130 |
99 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O BSERVER_H_ | 131 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O BSERVER_H_ |
OLD | NEW |