Chromium Code Reviews| 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(STARTED_PROVISIONAL_LOAD); | |
| 65 } | |
| 64 | 66 |
| 65 PageLoadTracker::~PageLoadTracker() { | 67 PageLoadTracker::~PageLoadTracker() { |
| 66 if (has_commit_) | 68 if (has_commit_) { |
| 67 RecordTimingHistograms(); | 69 RecordTimingHistograms(); |
| 70 if (timing_.first_layout.is_zero()) | |
| 71 RecordEvent(ABORTED_LOAD_BEFORE_FIRST_LAYOUT); | |
| 72 else | |
| 73 RecordEvent(SUCCESSFUL_FIRST_LAYOUT); | |
| 74 } | |
| 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 } |
| 76 | 83 |
| 77 void PageLoadTracker::Commit() { | 84 void PageLoadTracker::Commit() { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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); |
| 131 } else { | 138 } else { |
| 132 PAGE_LOAD_HISTOGRAM("PageLoad.Timing2.NavigationToFirstLayout.BG", | 139 PAGE_LOAD_HISTOGRAM("PageLoad.Timing2.NavigationToFirstLayout.BG", |
| 133 timing_.first_layout); | 140 timing_.first_layout); |
| 134 } | 141 } |
| 135 } | 142 } |
| 136 } | 143 } |
| 137 | 144 |
| 145 void PageLoadTracker::RecordEvent(PageLoadEvent event) { | |
| 146 UMA_HISTOGRAM_ENUMERATION("PageLoad.EventCounts", event, EVENT_COUNT); | |
|
Bryan McQuade
2015/10/01 14:57:38
is EVENT_COUNT supposed to be the value of the las
Charlie Harrison
2015/10/01 15:26:20
The comments on LOCAL_HISTOGRAM_ENUMERATION clarif
| |
| 147 } | |
| 148 | |
| 138 MetricsWebContentsObserver::MetricsWebContentsObserver( | 149 MetricsWebContentsObserver::MetricsWebContentsObserver( |
| 139 content::WebContents* web_contents) | 150 content::WebContents* web_contents) |
| 140 : content::WebContentsObserver(web_contents), in_foreground_(false) {} | 151 : content::WebContentsObserver(web_contents), in_foreground_(false) {} |
| 141 | 152 |
| 142 MetricsWebContentsObserver::~MetricsWebContentsObserver() {} | 153 MetricsWebContentsObserver::~MetricsWebContentsObserver() {} |
| 143 | 154 |
| 144 bool MetricsWebContentsObserver::OnMessageReceived( | 155 bool MetricsWebContentsObserver::OnMessageReceived( |
| 145 const IPC::Message& message, | 156 const IPC::Message& message, |
| 146 content::RenderFrameHost* render_frame_host) { | 157 content::RenderFrameHost* render_frame_host) { |
| 147 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 158 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 168 | 179 |
| 169 void MetricsWebContentsObserver::DidFinishNavigation( | 180 void MetricsWebContentsObserver::DidFinishNavigation( |
| 170 content::NavigationHandle* navigation_handle) { | 181 content::NavigationHandle* navigation_handle) { |
| 171 if (!navigation_handle->IsInMainFrame()) | 182 if (!navigation_handle->IsInMainFrame()) |
| 172 return; | 183 return; |
| 173 | 184 |
| 174 scoped_ptr<PageLoadTracker> finished_nav( | 185 scoped_ptr<PageLoadTracker> finished_nav( |
| 175 provisional_loads_.take_and_erase(navigation_handle)); | 186 provisional_loads_.take_and_erase(navigation_handle)); |
| 176 DCHECK(finished_nav); | 187 DCHECK(finished_nav); |
| 177 | 188 |
| 178 // TODO(csharrison) handle the two error cases: | 189 // Handle a pre-commit error here. Navigations that result in an error page |
| 179 // 1. Error pages that replace the previous page. | 190 // will be ignored. |
| 180 // 2. Error pages that leave the user on the previous page. | 191 // TODO(csharrison) filter out error codes that shouldn't result in us logging |
| 181 // For now these cases will be ignored. | 192 // an aborted provisional load. |
| 182 if (!navigation_handle->HasCommitted()) | 193 if (!navigation_handle->HasCommitted()) { |
| 194 finished_nav->RecordEvent(ABORTED_PROVISIONAL_LOAD); | |
|
Bryan McQuade
2015/10/01 14:57:38
could we call this PROVISIONAL_LOAD_FAILED, which
| |
| 183 return; | 195 return; |
| 196 } | |
| 184 | 197 |
| 185 // Don't treat a same-page nav as a new page load. | 198 // Don't treat a same-page nav as a new page load. |
| 186 if (navigation_handle->IsSamePage()) | 199 if (navigation_handle->IsSamePage()) |
| 187 return; | 200 return; |
| 188 | 201 |
| 189 // Eagerly log the previous UMA even if we don't care about the current | 202 // Eagerly log the previous UMA even if we don't care about the current |
| 190 // navigation. | 203 // navigation. |
| 191 committed_load_.reset(); | 204 committed_load_.reset(); |
| 192 | 205 |
| 193 if (!IsRelevantNavigation(navigation_handle)) | 206 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. | 258 // sure here that we aren't logging UMA for internal pages. |
| 246 const GURL& browser_url = web_contents()->GetLastCommittedURL(); | 259 const GURL& browser_url = web_contents()->GetLastCommittedURL(); |
| 247 return navigation_handle->IsInMainFrame() && | 260 return navigation_handle->IsInMainFrame() && |
| 248 !navigation_handle->IsSamePage() && | 261 !navigation_handle->IsSamePage() && |
| 249 !navigation_handle->IsErrorPage() && | 262 !navigation_handle->IsErrorPage() && |
| 250 navigation_handle->GetURL().SchemeIsHTTPOrHTTPS() && | 263 navigation_handle->GetURL().SchemeIsHTTPOrHTTPS() && |
| 251 browser_url.SchemeIsHTTPOrHTTPS(); | 264 browser_url.SchemeIsHTTPOrHTTPS(); |
| 252 } | 265 } |
| 253 | 266 |
| 254 } // namespace page_load_metrics | 267 } // namespace page_load_metrics |
| OLD | NEW |