| 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 #include "components/page_load_metrics/browser/metrics_web_contents_observer.h" | 5 #include "components/page_load_metrics/browser/metrics_web_contents_observer.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "components/page_load_metrics/common/page_load_metrics_messages.h" | 9 #include "components/page_load_metrics/common/page_load_metrics_messages.h" |
| 10 #include "components/page_load_metrics/common/page_load_timing.h" | 10 #include "components/page_load_metrics/common/page_load_timing.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } | 53 } |
| 54 | 54 |
| 55 } // namespace | 55 } // namespace |
| 56 | 56 |
| 57 #define PAGE_LOAD_HISTOGRAM(name, sample) \ | 57 #define PAGE_LOAD_HISTOGRAM(name, sample) \ |
| 58 UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, \ | 58 UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, \ |
| 59 base::TimeDelta::FromMilliseconds(10), \ | 59 base::TimeDelta::FromMilliseconds(10), \ |
| 60 base::TimeDelta::FromMinutes(10), 100) | 60 base::TimeDelta::FromMinutes(10), 100) |
| 61 | 61 |
| 62 PageLoadTracker::PageLoadTracker(bool in_foreground) | 62 PageLoadTracker::PageLoadTracker(bool in_foreground) |
| 63 : has_commit_(false), started_in_foreground_(in_foreground) {} | 63 : has_commit_(false), started_in_foreground_(in_foreground) { |
| 64 RecordEvent(PAGE_LOAD_STARTED); |
| 65 } |
| 64 | 66 |
| 65 PageLoadTracker::~PageLoadTracker() { | 67 PageLoadTracker::~PageLoadTracker() { |
| 68 // Even a load that failed a provisional load should log |
| 69 // that it aborted before first layout. |
| 70 if (timing_.first_layout.is_zero()) |
| 71 RecordEvent(PAGE_LOAD_ABORTED_BEFORE_FIRST_LAYOUT); |
| 72 |
| 66 if (has_commit_) | 73 if (has_commit_) |
| 67 RecordTimingHistograms(); | 74 RecordTimingHistograms(); |
| 68 } | 75 } |
| 69 | 76 |
| 70 void PageLoadTracker::WebContentsHidden() { | 77 void PageLoadTracker::WebContentsHidden() { |
| 71 // Only log the first time we background in a given page load. | 78 // Only log the first time we background in a given page load. |
| 72 if (background_time_.is_null()) { | 79 if (background_time_.is_null()) { |
| 73 background_time_ = base::TimeTicks::Now(); | 80 background_time_ = base::TimeTicks::Now(); |
| 74 } | 81 } |
| 75 } | 82 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 timing_.load_event_start); | 128 timing_.load_event_start); |
| 122 } else { | 129 } else { |
| 123 PAGE_LOAD_HISTOGRAM("PageLoad.Timing2.NavigationToLoadEventFired.BG", | 130 PAGE_LOAD_HISTOGRAM("PageLoad.Timing2.NavigationToLoadEventFired.BG", |
| 124 timing_.load_event_start); | 131 timing_.load_event_start); |
| 125 } | 132 } |
| 126 } | 133 } |
| 127 if (!timing_.first_layout.is_zero()) { | 134 if (!timing_.first_layout.is_zero()) { |
| 128 if (timing_.first_layout < background_delta) { | 135 if (timing_.first_layout < background_delta) { |
| 129 PAGE_LOAD_HISTOGRAM("PageLoad.Timing2.NavigationToFirstLayout", | 136 PAGE_LOAD_HISTOGRAM("PageLoad.Timing2.NavigationToFirstLayout", |
| 130 timing_.first_layout); | 137 timing_.first_layout); |
| 138 RecordEvent(PAGE_LOAD_SUCCESSFUL_FIRST_LAYOUT_FOREGROUND); |
| 131 } else { | 139 } else { |
| 132 PAGE_LOAD_HISTOGRAM("PageLoad.Timing2.NavigationToFirstLayout.BG", | 140 PAGE_LOAD_HISTOGRAM("PageLoad.Timing2.NavigationToFirstLayout.BG", |
| 133 timing_.first_layout); | 141 timing_.first_layout); |
| 142 RecordEvent(PAGE_LOAD_SUCCESSFUL_FIRST_LAYOUT_BACKGROUND); |
| 134 } | 143 } |
| 135 } | 144 } |
| 145 |
| 146 } |
| 147 |
| 148 void PageLoadTracker::RecordEvent(PageLoadEvent event) { |
| 149 UMA_HISTOGRAM_ENUMERATION( |
| 150 "PageLoad.EventCounts", event, PAGE_LOAD_LAST_ENTRY); |
| 136 } | 151 } |
| 137 | 152 |
| 138 MetricsWebContentsObserver::MetricsWebContentsObserver( | 153 MetricsWebContentsObserver::MetricsWebContentsObserver( |
| 139 content::WebContents* web_contents) | 154 content::WebContents* web_contents) |
| 140 : content::WebContentsObserver(web_contents), in_foreground_(false) {} | 155 : content::WebContentsObserver(web_contents), in_foreground_(false) {} |
| 141 | 156 |
| 142 MetricsWebContentsObserver::~MetricsWebContentsObserver() {} | 157 MetricsWebContentsObserver::~MetricsWebContentsObserver() {} |
| 143 | 158 |
| 144 bool MetricsWebContentsObserver::OnMessageReceived( | 159 bool MetricsWebContentsObserver::OnMessageReceived( |
| 145 const IPC::Message& message, | 160 const IPC::Message& message, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 168 | 183 |
| 169 void MetricsWebContentsObserver::DidFinishNavigation( | 184 void MetricsWebContentsObserver::DidFinishNavigation( |
| 170 content::NavigationHandle* navigation_handle) { | 185 content::NavigationHandle* navigation_handle) { |
| 171 if (!navigation_handle->IsInMainFrame()) | 186 if (!navigation_handle->IsInMainFrame()) |
| 172 return; | 187 return; |
| 173 | 188 |
| 174 scoped_ptr<PageLoadTracker> finished_nav( | 189 scoped_ptr<PageLoadTracker> finished_nav( |
| 175 provisional_loads_.take_and_erase(navigation_handle)); | 190 provisional_loads_.take_and_erase(navigation_handle)); |
| 176 DCHECK(finished_nav); | 191 DCHECK(finished_nav); |
| 177 | 192 |
| 178 // TODO(csharrison) handle the two error cases: | 193 // Handle a pre-commit error here. Navigations that result in an error page |
| 179 // 1. Error pages that replace the previous page. | 194 // will be ignored. |
| 180 // 2. Error pages that leave the user on the previous page. | 195 // TODO(csharrison) filter out error codes that shouldn't result in us logging |
| 181 // For now these cases will be ignored. | 196 // an aborted provisional load. |
| 182 if (!navigation_handle->HasCommitted()) | 197 if (!navigation_handle->HasCommitted()) { |
| 198 finished_nav->RecordEvent(PAGE_LOAD_FAILED_BEFORE_COMMIT); |
| 199 if (navigation_handle->GetNetErrorCode() == net::ERR_ABORTED) |
| 200 finished_nav->RecordEvent(PAGE_LOAD_ABORTED_BEFORE_COMMIT); |
| 183 return; | 201 return; |
| 202 } |
| 184 | 203 |
| 185 // Don't treat a same-page nav as a new page load. | 204 // Don't treat a same-page nav as a new page load. |
| 186 if (navigation_handle->IsSamePage()) | 205 if (navigation_handle->IsSamePage()) |
| 187 return; | 206 return; |
| 188 | 207 |
| 189 // Eagerly log the previous UMA even if we don't care about the current | 208 // Eagerly log the previous UMA even if we don't care about the current |
| 190 // navigation. | 209 // navigation. |
| 191 committed_load_.reset(); | 210 committed_load_.reset(); |
| 192 | 211 |
| 193 if (!IsRelevantNavigation(navigation_handle)) | 212 if (!IsRelevantNavigation(navigation_handle)) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 // sure here that we aren't logging UMA for internal pages. | 264 // sure here that we aren't logging UMA for internal pages. |
| 246 const GURL& browser_url = web_contents()->GetLastCommittedURL(); | 265 const GURL& browser_url = web_contents()->GetLastCommittedURL(); |
| 247 return navigation_handle->IsInMainFrame() && | 266 return navigation_handle->IsInMainFrame() && |
| 248 !navigation_handle->IsSamePage() && | 267 !navigation_handle->IsSamePage() && |
| 249 !navigation_handle->IsErrorPage() && | 268 !navigation_handle->IsErrorPage() && |
| 250 navigation_handle->GetURL().SchemeIsHTTPOrHTTPS() && | 269 navigation_handle->GetURL().SchemeIsHTTPOrHTTPS() && |
| 251 browser_url.SchemeIsHTTPOrHTTPS(); | 270 browser_url.SchemeIsHTTPOrHTTPS(); |
| 252 } | 271 } |
| 253 | 272 |
| 254 } // namespace page_load_metrics | 273 } // namespace page_load_metrics |
| OLD | NEW |