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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 PageLoadTracker* const currently_committed_load_or_null, |
211 content::NavigationHandle* navigation_handle, | 211 content::NavigationHandle* navigation_handle, |
| 212 content::WebContents* web_contents, |
212 int aborted_chain_size, | 213 int aborted_chain_size, |
213 int aborted_chain_size_same_url) | 214 int aborted_chain_size_same_url) |
214 : renderer_tracked_(false), | 215 : renderer_tracked_(false), |
215 navigation_start_(navigation_handle->NavigationStart()), | 216 navigation_start_(navigation_handle->NavigationStart()), |
216 url_(navigation_handle->GetURL()), | 217 url_(navigation_handle->GetURL()), |
217 abort_type_(ABORT_NONE), | 218 abort_type_(ABORT_NONE), |
218 started_in_foreground_(in_foreground), | 219 started_in_foreground_(in_foreground), |
219 aborted_chain_size_(aborted_chain_size), | 220 aborted_chain_size_(aborted_chain_size), |
220 aborted_chain_size_same_url_(aborted_chain_size_same_url), | 221 aborted_chain_size_same_url_(aborted_chain_size_same_url), |
221 embedder_interface_(embedder_interface) { | 222 embedder_interface_(embedder_interface) { |
222 DCHECK(!navigation_handle->HasCommitted()); | 223 DCHECK(!navigation_handle->HasCommitted()); |
223 embedder_interface_->RegisterObservers(this); | 224 embedder_interface_->RegisterObservers(this); |
224 const GURL& currently_committed_url = | 225 const GURL currently_committed_url = |
225 currently_committed_load_or_null | 226 currently_committed_load_or_null |
226 ? currently_committed_load_or_null->committed_url() | 227 ? currently_committed_load_or_null->committed_url() |
227 : GURL::EmptyGURL(); | 228 : GURL::EmptyGURL(); |
228 for (const auto& observer : observers_) { | 229 for (const auto& observer : observers_) { |
229 observer->OnStart(navigation_handle, currently_committed_url); | 230 observer->OnStart(navigation_handle, web_contents, currently_committed_url); |
230 } | 231 } |
231 } | 232 } |
232 | 233 |
233 PageLoadTracker::~PageLoadTracker() { | 234 PageLoadTracker::~PageLoadTracker() { |
234 const PageLoadExtraInfo info = GetPageLoadMetricsInfo(); | 235 const PageLoadExtraInfo info = GetPageLoadMetricsInfo(); |
235 if (!info.time_to_commit.is_zero() && renderer_tracked() && | 236 if (!info.time_to_commit.is_zero() && renderer_tracked() && |
236 timing_.IsEmpty()) { | 237 timing_.IsEmpty()) { |
237 RecordInternalError(ERR_NO_IPCS_RECEIVED); | 238 RecordInternalError(ERR_NO_IPCS_RECEIVED); |
238 } | 239 } |
239 // Recall that trackers that are given ABORT_UNKNOWN_NAVIGATION have their | 240 // Recall that trackers that are given ABORT_UNKNOWN_NAVIGATION have their |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 } | 518 } |
518 | 519 |
519 // We can have two provisional loads in some cases. E.g. a same-site | 520 // We can have two provisional loads in some cases. E.g. a same-site |
520 // navigation can have a concurrent cross-process navigation started | 521 // navigation can have a concurrent cross-process navigation started |
521 // from the omnibox. | 522 // from the omnibox. |
522 DCHECK_GT(2ul, provisional_loads_.size()); | 523 DCHECK_GT(2ul, provisional_loads_.size()); |
523 // Passing raw pointers to observers_ and embedder_interface_ is safe because | 524 // Passing raw pointers to observers_ and embedder_interface_ is safe because |
524 // the MetricsWebContentsObserver owns them both list and they are torn down | 525 // the MetricsWebContentsObserver owns them both list and they are torn down |
525 // after the PageLoadTracker. The PageLoadTracker does not hold on to | 526 // after the PageLoadTracker. The PageLoadTracker does not hold on to |
526 // committed_load_ or navigation_handle beyond the scope of the constructor. | 527 // committed_load_ or navigation_handle beyond the scope of the constructor. |
527 provisional_loads_.insert(std::make_pair( | 528 provisional_loads_.insert( |
528 navigation_handle, | 529 std::make_pair(navigation_handle, |
529 make_scoped_ptr(new PageLoadTracker( | 530 make_scoped_ptr(new PageLoadTracker( |
530 in_foreground_, embedder_interface_.get(), committed_load_.get(), | 531 in_foreground_, embedder_interface_.get(), |
531 navigation_handle, chain_size, chain_size_same_url)))); | 532 committed_load_.get(), navigation_handle, |
| 533 web_contents(), chain_size, chain_size_same_url)))); |
532 } | 534 } |
533 | 535 |
534 void MetricsWebContentsObserver::DidFinishNavigation( | 536 void MetricsWebContentsObserver::DidFinishNavigation( |
535 content::NavigationHandle* navigation_handle) { | 537 content::NavigationHandle* navigation_handle) { |
536 if (!navigation_handle->IsInMainFrame()) | 538 if (!navigation_handle->IsInMainFrame()) |
537 return; | 539 return; |
538 | 540 |
539 scoped_ptr<PageLoadTracker> finished_nav( | 541 scoped_ptr<PageLoadTracker> finished_nav( |
540 std::move(provisional_loads_[navigation_handle])); | 542 std::move(provisional_loads_[navigation_handle])); |
541 provisional_loads_.erase(navigation_handle); | 543 provisional_loads_.erase(navigation_handle); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 | 727 |
726 if (!committed_load_->UpdateTiming(timing, metadata)) { | 728 if (!committed_load_->UpdateTiming(timing, metadata)) { |
727 // If the page load tracker cannot update its timing, something is wrong | 729 // If the page load tracker cannot update its timing, something is wrong |
728 // with the IPC (it's from another load, or it's invalid in some other way). | 730 // with the IPC (it's from another load, or it's invalid in some other way). |
729 // We expect this to be a rare occurrence. | 731 // We expect this to be a rare occurrence. |
730 RecordInternalError(ERR_BAD_TIMING_IPC); | 732 RecordInternalError(ERR_BAD_TIMING_IPC); |
731 } | 733 } |
732 } | 734 } |
733 | 735 |
734 } // namespace page_load_metrics | 736 } // namespace page_load_metrics |
OLD | NEW |