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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 } // namespace internal | 101 } // namespace internal |
| 102 | 102 |
| 103 PageLoadTracker::PageLoadTracker( | 103 PageLoadTracker::PageLoadTracker( |
| 104 bool in_foreground, | 104 bool in_foreground, |
| 105 PageLoadMetricsEmbedderInterface* embedder_interface, | 105 PageLoadMetricsEmbedderInterface* embedder_interface, |
| 106 content::NavigationHandle* navigation_handle) | 106 content::NavigationHandle* navigation_handle) |
| 107 : renderer_tracked_(false), | 107 : renderer_tracked_(false), |
| 108 navigation_start_(navigation_handle->NavigationStart()), | 108 navigation_start_(navigation_handle->NavigationStart()), |
| 109 abort_type_(ABORT_NONE), | 109 abort_type_(ABORT_NONE), |
| 110 started_in_foreground_(in_foreground), | 110 started_in_foreground_(in_foreground), |
| 111 embedder_interface_(embedder_interface) { | 111 embedder_interface_(embedder_interface), |
| 112 is_using_lofi_(false), | |
| 113 was_fetched_via_data_reduction_proxy_(false) { | |
| 112 embedder_interface_->RegisterObservers(this); | 114 embedder_interface_->RegisterObservers(this); |
| 113 for (const auto& observer : observers_) { | 115 for (const auto& observer : observers_) { |
| 114 observer->OnStart(navigation_handle); | 116 observer->OnStart(navigation_handle); |
| 115 } | 117 } |
| 116 } | 118 } |
| 117 | 119 |
| 118 PageLoadTracker::~PageLoadTracker() { | 120 PageLoadTracker::~PageLoadTracker() { |
| 119 const PageLoadExtraInfo info = GetPageLoadMetricsInfo(); | 121 const PageLoadExtraInfo info = GetPageLoadMetricsInfo(); |
| 120 if (!info.time_to_commit.is_zero() && renderer_tracked() && | 122 if (!info.time_to_commit.is_zero() && renderer_tracked() && |
| 121 timing_.IsEmpty()) { | 123 timing_.IsEmpty()) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 | 185 |
| 184 void PageLoadTracker::set_renderer_tracked(bool renderer_tracked) { | 186 void PageLoadTracker::set_renderer_tracked(bool renderer_tracked) { |
| 185 renderer_tracked_ = renderer_tracked; | 187 renderer_tracked_ = renderer_tracked; |
| 186 } | 188 } |
| 187 | 189 |
| 188 void PageLoadTracker::AddObserver( | 190 void PageLoadTracker::AddObserver( |
| 189 scoped_ptr<PageLoadMetricsObserver> observer) { | 191 scoped_ptr<PageLoadMetricsObserver> observer) { |
| 190 observers_.push_back(std::move(observer)); | 192 observers_.push_back(std::move(observer)); |
| 191 } | 193 } |
| 192 | 194 |
| 195 void PageLoadTracker::set_is_using_lofi(bool is_using_lofi) { | |
| 196 is_using_lofi_ = is_using_lofi; | |
| 197 } | |
| 198 | |
| 199 void PageLoadTracker::set_was_fetched_via_data_reduction_proxy( | |
| 200 bool was_fetched_via_data_reduction_proxy) { | |
| 201 was_fetched_via_data_reduction_proxy_ = was_fetched_via_data_reduction_proxy; | |
| 202 } | |
| 203 | |
| 193 PageLoadExtraInfo PageLoadTracker::GetPageLoadMetricsInfo() { | 204 PageLoadExtraInfo PageLoadTracker::GetPageLoadMetricsInfo() { |
| 194 base::TimeDelta first_background_time; | 205 base::TimeDelta first_background_time; |
| 195 base::TimeDelta first_foreground_time; | 206 base::TimeDelta first_foreground_time; |
| 196 base::TimeDelta time_to_abort; | 207 base::TimeDelta time_to_abort; |
| 197 base::TimeDelta time_to_commit; | 208 base::TimeDelta time_to_commit; |
| 198 if (!background_time_.is_null() && started_in_foreground_) | 209 if (!background_time_.is_null() && started_in_foreground_) |
| 199 first_background_time = background_time_ - navigation_start_; | 210 first_background_time = background_time_ - navigation_start_; |
| 200 if (!foreground_time_.is_null() && !started_in_foreground_) | 211 if (!foreground_time_.is_null() && !started_in_foreground_) |
| 201 first_foreground_time = foreground_time_ - navigation_start_; | 212 first_foreground_time = foreground_time_ - navigation_start_; |
| 202 if (abort_type_ != ABORT_NONE) { | 213 if (abort_type_ != ABORT_NONE) { |
| 203 DCHECK_GT(abort_time_, navigation_start_); | 214 DCHECK_GT(abort_time_, navigation_start_); |
| 204 time_to_abort = abort_time_ - navigation_start_; | 215 time_to_abort = abort_time_ - navigation_start_; |
| 205 } else { | 216 } else { |
| 206 DCHECK(abort_time_.is_null()); | 217 DCHECK(abort_time_.is_null()); |
| 207 } | 218 } |
| 208 if (!committed_url_.is_empty()) { | 219 if (!committed_url_.is_empty()) { |
| 209 DCHECK_GT(commit_time_, navigation_start_); | 220 DCHECK_GT(commit_time_, navigation_start_); |
| 210 time_to_commit = commit_time_ - navigation_start_; | 221 time_to_commit = commit_time_ - navigation_start_; |
| 211 } else { | 222 } else { |
| 212 DCHECK(commit_time_.is_null()); | 223 DCHECK(commit_time_.is_null()); |
| 213 } | 224 } |
| 214 return PageLoadExtraInfo(first_background_time, first_foreground_time, | 225 |
| 215 started_in_foreground_, committed_url_, | 226 return PageLoadExtraInfo( |
| 216 time_to_commit, abort_type_, time_to_abort); | 227 first_background_time, first_foreground_time, started_in_foreground_, |
| 228 committed_url_, time_to_commit, abort_type_, time_to_abort, | |
| 229 is_using_lofi_, was_fetched_via_data_reduction_proxy_); | |
| 217 } | 230 } |
| 218 | 231 |
| 219 void PageLoadTracker::NotifyAbort(UserAbortType abort_type, | 232 void PageLoadTracker::NotifyAbort(UserAbortType abort_type, |
| 220 const base::TimeTicks& timestamp) { | 233 const base::TimeTicks& timestamp) { |
| 221 DCHECK_NE(abort_type, ABORT_NONE); | 234 DCHECK_NE(abort_type, ABORT_NONE); |
| 222 // Use UpdateAbort to update an already notified PageLoadTracker. | 235 // Use UpdateAbort to update an already notified PageLoadTracker. |
| 223 if (abort_type_ != ABORT_NONE) | 236 if (abort_type_ != ABORT_NONE) |
| 224 return; | 237 return; |
| 225 | 238 |
| 226 UpdateAbortInternal(abort_type, timestamp); | 239 UpdateAbortInternal(abort_type, timestamp); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 aborted_provisional_loads_.push_back(std::move(finished_nav)); | 366 aborted_provisional_loads_.push_back(std::move(finished_nav)); |
| 354 } | 367 } |
| 355 | 368 |
| 356 return; | 369 return; |
| 357 } | 370 } |
| 358 | 371 |
| 359 // Don't treat a same-page nav as a new page load. | 372 // Don't treat a same-page nav as a new page load. |
| 360 if (navigation_handle->IsSamePage()) | 373 if (navigation_handle->IsSamePage()) |
| 361 return; | 374 return; |
| 362 | 375 |
| 376 finished_nav->set_is_using_lofi(navigation_handle->IsUsingLofi()); | |
|
bengr
2016/02/26 22:53:57
Is there an existing pattern to set the PageLoadTr
RyanSturm
2016/03/01 19:36:04
set_renderer_tracked is the only setter I see on P
| |
| 377 finished_nav->set_was_fetched_via_data_reduction_proxy( | |
| 378 navigation_handle->WasFetchedViaDataReductionProxy()); | |
| 379 | |
| 363 // Notify other loads that they may have been aborted by this committed load. | 380 // Notify other loads that they may have been aborted by this committed load. |
| 364 // Note that by using the committed navigation start as the abort cause, we | 381 // Note that by using the committed navigation start as the abort cause, we |
| 365 // lose data on provisional loads that were aborted by other provisional | 382 // lose data on provisional loads that were aborted by other provisional |
| 366 // loads. Those will either be listed as ABORT_OTHER or as being aborted by | 383 // loads. Those will either be listed as ABORT_OTHER or as being aborted by |
| 367 // this load. | 384 // this load. |
| 368 NotifyAbortAllLoadsWithTimestamp( | 385 NotifyAbortAllLoadsWithTimestamp( |
| 369 AbortTypeForPageTransition(navigation_handle->GetPageTransition()), | 386 AbortTypeForPageTransition(navigation_handle->GetPageTransition()), |
| 370 navigation_handle->NavigationStart()); | 387 navigation_handle->NavigationStart()); |
| 371 | 388 |
| 372 committed_load_ = std::move(finished_nav); | 389 committed_load_ = std::move(finished_nav); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 490 | 507 |
| 491 if (!committed_load_->UpdateTiming(timing)) { | 508 if (!committed_load_->UpdateTiming(timing)) { |
| 492 // If the page load tracker cannot update its timing, something is wrong | 509 // If the page load tracker cannot update its timing, something is wrong |
| 493 // with the IPC (it's from another load, or it's invalid in some other way). | 510 // with the IPC (it's from another load, or it's invalid in some other way). |
| 494 // We expect this to be a rare occurrence. | 511 // We expect this to be a rare occurrence. |
| 495 RecordInternalError(ERR_BAD_TIMING_IPC); | 512 RecordInternalError(ERR_BAD_TIMING_IPC); |
| 496 } | 513 } |
| 497 } | 514 } |
| 498 | 515 |
| 499 } // namespace page_load_metrics | 516 } // namespace page_load_metrics |
| OLD | NEW |