| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 UMA_HISTOGRAM_COUNTS(internal::kAbortChainSizeSameURL, | 200 UMA_HISTOGRAM_COUNTS(internal::kAbortChainSizeSameURL, |
| 201 aborted_chain_size_same_url); | 201 aborted_chain_size_same_url); |
| 202 } | 202 } |
| 203 } | 203 } |
| 204 | 204 |
| 205 } // namespace | 205 } // namespace |
| 206 | 206 |
| 207 PageLoadTracker::PageLoadTracker( | 207 PageLoadTracker::PageLoadTracker( |
| 208 bool in_foreground, | 208 bool in_foreground, |
| 209 PageLoadMetricsEmbedderInterface* embedder_interface, | 209 PageLoadMetricsEmbedderInterface* embedder_interface, |
| 210 PageLoadTracker* const currently_committed_load_or_null, |
| 210 content::NavigationHandle* navigation_handle, | 211 content::NavigationHandle* navigation_handle, |
| 211 int aborted_chain_size, | 212 int aborted_chain_size, |
| 212 int aborted_chain_size_same_url) | 213 int aborted_chain_size_same_url) |
| 213 : renderer_tracked_(false), | 214 : renderer_tracked_(false), |
| 214 navigation_start_(navigation_handle->NavigationStart()), | 215 navigation_start_(navigation_handle->NavigationStart()), |
| 215 url_(navigation_handle->GetURL()), | 216 url_(navigation_handle->GetURL()), |
| 216 abort_type_(ABORT_NONE), | 217 abort_type_(ABORT_NONE), |
| 217 started_in_foreground_(in_foreground), | 218 started_in_foreground_(in_foreground), |
| 218 aborted_chain_size_(aborted_chain_size), | 219 aborted_chain_size_(aborted_chain_size), |
| 219 aborted_chain_size_same_url_(aborted_chain_size_same_url), | 220 aborted_chain_size_same_url_(aborted_chain_size_same_url), |
| 220 embedder_interface_(embedder_interface) { | 221 embedder_interface_(embedder_interface) { |
| 221 DCHECK(!navigation_handle->HasCommitted()); | 222 DCHECK(!navigation_handle->HasCommitted()); |
| 222 embedder_interface_->RegisterObservers(this); | 223 embedder_interface_->RegisterObservers(this); |
| 224 const GURL& currently_committed_url = |
| 225 currently_committed_load_or_null |
| 226 ? currently_committed_load_or_null->committed_url() |
| 227 : GURL::EmptyGURL(); |
| 223 for (const auto& observer : observers_) { | 228 for (const auto& observer : observers_) { |
| 224 observer->OnStart(navigation_handle); | 229 observer->OnStart(navigation_handle, currently_committed_url); |
| 225 } | 230 } |
| 226 } | 231 } |
| 227 | 232 |
| 228 PageLoadTracker::~PageLoadTracker() { | 233 PageLoadTracker::~PageLoadTracker() { |
| 229 const PageLoadExtraInfo info = GetPageLoadMetricsInfo(); | 234 const PageLoadExtraInfo info = GetPageLoadMetricsInfo(); |
| 230 if (!info.time_to_commit.is_zero() && renderer_tracked() && | 235 if (!info.time_to_commit.is_zero() && renderer_tracked() && |
| 231 timing_.IsEmpty()) { | 236 timing_.IsEmpty()) { |
| 232 RecordInternalError(ERR_NO_IPCS_RECEIVED); | 237 RecordInternalError(ERR_NO_IPCS_RECEIVED); |
| 233 } | 238 } |
| 234 // Recall that trackers that are given ABORT_UNKNOWN_NAVIGATION have their | 239 // Recall that trackers that are given ABORT_UNKNOWN_NAVIGATION have their |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 metadata_.behavior_flags; | 353 metadata_.behavior_flags; |
| 349 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent && | 354 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent && |
| 350 valid_behavior_descendent) { | 355 valid_behavior_descendent) { |
| 351 timing_ = new_timing; | 356 timing_ = new_timing; |
| 352 metadata_ = new_metadata; | 357 metadata_ = new_metadata; |
| 353 return true; | 358 return true; |
| 354 } | 359 } |
| 355 return false; | 360 return false; |
| 356 } | 361 } |
| 357 | 362 |
| 358 bool PageLoadTracker::HasBackgrounded() { | |
| 359 return !started_in_foreground_ || !background_time_.is_null(); | |
| 360 } | |
| 361 | |
| 362 void PageLoadTracker::set_renderer_tracked(bool renderer_tracked) { | 363 void PageLoadTracker::set_renderer_tracked(bool renderer_tracked) { |
| 363 renderer_tracked_ = renderer_tracked; | 364 renderer_tracked_ = renderer_tracked; |
| 364 } | 365 } |
| 365 | 366 |
| 366 void PageLoadTracker::AddObserver( | 367 void PageLoadTracker::AddObserver( |
| 367 scoped_ptr<PageLoadMetricsObserver> observer) { | 368 scoped_ptr<PageLoadMetricsObserver> observer) { |
| 368 observers_.push_back(std::move(observer)); | 369 observers_.push_back(std::move(observer)); |
| 369 } | 370 } |
| 370 | 371 |
| 371 PageLoadExtraInfo PageLoadTracker::GetPageLoadMetricsInfo() { | 372 PageLoadExtraInfo PageLoadTracker::GetPageLoadMetricsInfo() { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 } | 515 } |
| 515 chain_size = last_aborted->aborted_chain_size() + 1; | 516 chain_size = last_aborted->aborted_chain_size() + 1; |
| 516 } | 517 } |
| 517 | 518 |
| 518 // We can have two provisional loads in some cases. E.g. a same-site | 519 // We can have two provisional loads in some cases. E.g. a same-site |
| 519 // navigation can have a concurrent cross-process navigation started | 520 // navigation can have a concurrent cross-process navigation started |
| 520 // from the omnibox. | 521 // from the omnibox. |
| 521 DCHECK_GT(2ul, provisional_loads_.size()); | 522 DCHECK_GT(2ul, provisional_loads_.size()); |
| 522 // Passing raw pointers to observers_ and embedder_interface_ is safe because | 523 // Passing raw pointers to observers_ and embedder_interface_ is safe because |
| 523 // the MetricsWebContentsObserver owns them both list and they are torn down | 524 // the MetricsWebContentsObserver owns them both list and they are torn down |
| 524 // after the PageLoadTracker. | 525 // after the PageLoadTracker. The PageLoadTracker does not hold on to |
| 525 provisional_loads_.insert( | 526 // committed_load_ or navigation_handle beyond the scope of the constructor. |
| 526 std::make_pair(navigation_handle, | 527 provisional_loads_.insert(std::make_pair( |
| 527 make_scoped_ptr(new PageLoadTracker( | 528 navigation_handle, |
| 528 in_foreground_, embedder_interface_.get(), | 529 make_scoped_ptr(new PageLoadTracker( |
| 529 navigation_handle, chain_size, chain_size_same_url)))); | 530 in_foreground_, embedder_interface_.get(), committed_load_.get(), |
| 531 navigation_handle, chain_size, chain_size_same_url)))); |
| 530 } | 532 } |
| 531 | 533 |
| 532 void MetricsWebContentsObserver::DidFinishNavigation( | 534 void MetricsWebContentsObserver::DidFinishNavigation( |
| 533 content::NavigationHandle* navigation_handle) { | 535 content::NavigationHandle* navigation_handle) { |
| 534 if (!navigation_handle->IsInMainFrame()) | 536 if (!navigation_handle->IsInMainFrame()) |
| 535 return; | 537 return; |
| 536 | 538 |
| 537 scoped_ptr<PageLoadTracker> finished_nav( | 539 scoped_ptr<PageLoadTracker> finished_nav( |
| 538 std::move(provisional_loads_[navigation_handle])); | 540 std::move(provisional_loads_[navigation_handle])); |
| 539 provisional_loads_.erase(navigation_handle); | 541 provisional_loads_.erase(navigation_handle); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 | 725 |
| 724 if (!committed_load_->UpdateTiming(timing, metadata)) { | 726 if (!committed_load_->UpdateTiming(timing, metadata)) { |
| 725 // If the page load tracker cannot update its timing, something is wrong | 727 // If the page load tracker cannot update its timing, something is wrong |
| 726 // with the IPC (it's from another load, or it's invalid in some other way). | 728 // with the IPC (it's from another load, or it's invalid in some other way). |
| 727 // We expect this to be a rare occurrence. | 729 // We expect this to be a rare occurrence. |
| 728 RecordInternalError(ERR_BAD_TIMING_IPC); | 730 RecordInternalError(ERR_BAD_TIMING_IPC); |
| 729 } | 731 } |
| 730 } | 732 } |
| 731 | 733 |
| 732 } // namespace page_load_metrics | 734 } // namespace page_load_metrics |
| OLD | NEW |