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/location.h" | 7 #include "base/location.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/metrics/user_metrics.h" |
10 #include "components/page_load_metrics/browser/page_load_metrics_macros.h" | 11 #include "components/page_load_metrics/browser/page_load_metrics_macros.h" |
11 #include "components/page_load_metrics/common/page_load_metrics_messages.h" | 12 #include "components/page_load_metrics/common/page_load_metrics_messages.h" |
12 #include "components/page_load_metrics/common/page_load_timing.h" | 13 #include "components/page_load_metrics/common/page_load_timing.h" |
13 #include "components/rappor/rappor_service.h" | 14 #include "components/rappor/rappor_service.h" |
14 #include "components/rappor/rappor_utils.h" | 15 #include "components/rappor/rappor_utils.h" |
15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/navigation_details.h" | 17 #include "content/public/browser/navigation_details.h" |
17 #include "content/public/browser/navigation_handle.h" | 18 #include "content/public/browser/navigation_handle.h" |
18 #include "content/public/browser/render_frame_host.h" | 19 #include "content/public/browser/render_frame_host.h" |
19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 url_ = navigation_handle->GetURL(); | 154 url_ = navigation_handle->GetURL(); |
154 // We log the event that this load started. Because we don't know if a load is | 155 // We log the event that this load started. Because we don't know if a load is |
155 // relevant or if it will commit before now, we have to log this event at | 156 // relevant or if it will commit before now, we have to log this event at |
156 // commit time. | 157 // commit time. |
157 RecordCommittedEvent(COMMITTED_LOAD_STARTED, !started_in_foreground_); | 158 RecordCommittedEvent(COMMITTED_LOAD_STARTED, !started_in_foreground_); |
158 | 159 |
159 FOR_EACH_OBSERVER(PageLoadMetricsObserver, *observers_, | 160 FOR_EACH_OBSERVER(PageLoadMetricsObserver, *observers_, |
160 OnCommit(navigation_handle)); | 161 OnCommit(navigation_handle)); |
161 } | 162 } |
162 | 163 |
| 164 void PageLoadTracker::Redirect(content::NavigationHandle* navigation_handle) { |
| 165 FOR_EACH_OBSERVER(PageLoadMetricsObserver, *observers_, |
| 166 OnRedirect(navigation_handle)); |
| 167 } |
| 168 |
163 bool PageLoadTracker::UpdateTiming(const PageLoadTiming& new_timing) { | 169 bool PageLoadTracker::UpdateTiming(const PageLoadTiming& new_timing) { |
164 // Throw away IPCs that are not relevant to the current navigation. | 170 // Throw away IPCs that are not relevant to the current navigation. |
165 // Two timing structures cannot refer to the same navigation if they indicate | 171 // Two timing structures cannot refer to the same navigation if they indicate |
166 // that a navigation started at different times, so a new timing struct with a | 172 // that a navigation started at different times, so a new timing struct with a |
167 // different start time from an earlier struct is considered invalid. | 173 // different start time from an earlier struct is considered invalid. |
168 bool valid_timing_descendent = | 174 bool valid_timing_descendent = |
169 timing_.navigation_start.is_null() || | 175 timing_.navigation_start.is_null() || |
170 timing_.navigation_start == new_timing.navigation_start; | 176 timing_.navigation_start == new_timing.navigation_start; |
171 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent) { | 177 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent) { |
172 timing_ = new_timing; | 178 timing_ = new_timing; |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 const std::string& mime_type = web_contents()->GetContentsMimeType(); | 486 const std::string& mime_type = web_contents()->GetContentsMimeType(); |
481 DCHECK(!browser_url.is_empty()); | 487 DCHECK(!browser_url.is_empty()); |
482 DCHECK(!mime_type.empty()); | 488 DCHECK(!mime_type.empty()); |
483 if (!IsRelevantNavigation(navigation_handle, browser_url, mime_type)) | 489 if (!IsRelevantNavigation(navigation_handle, browser_url, mime_type)) |
484 return; | 490 return; |
485 | 491 |
486 committed_load_ = finished_nav.Pass(); | 492 committed_load_ = finished_nav.Pass(); |
487 committed_load_->Commit(navigation_handle); | 493 committed_load_->Commit(navigation_handle); |
488 } | 494 } |
489 | 495 |
| 496 void MetricsWebContentsObserver::DidRedirectNavigation( |
| 497 content::NavigationHandle* navigation_handle) { |
| 498 if (!navigation_handle->IsInMainFrame()) |
| 499 return; |
| 500 auto it = provisional_loads_.find(navigation_handle); |
| 501 if (it == provisional_loads_.end()) |
| 502 return; |
| 503 it->second->Redirect(navigation_handle); |
| 504 } |
| 505 |
490 void MetricsWebContentsObserver::WasShown() { | 506 void MetricsWebContentsObserver::WasShown() { |
491 in_foreground_ = true; | 507 in_foreground_ = true; |
492 if (committed_load_) | 508 if (committed_load_) |
493 committed_load_->WebContentsShown(); | 509 committed_load_->WebContentsShown(); |
494 for (const auto& kv : provisional_loads_) { | 510 for (const auto& kv : provisional_loads_) { |
495 kv.second->WebContentsShown(); | 511 kv.second->WebContentsShown(); |
496 } | 512 } |
497 } | 513 } |
498 | 514 |
499 void MetricsWebContentsObserver::WasHidden() { | 515 void MetricsWebContentsObserver::WasHidden() { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 | 558 |
543 if (!committed_load_->UpdateTiming(timing)) { | 559 if (!committed_load_->UpdateTiming(timing)) { |
544 // If the page load tracker cannot update its timing, something is wrong | 560 // If the page load tracker cannot update its timing, something is wrong |
545 // with the IPC (it's from another load, or it's invalid in some other way). | 561 // with the IPC (it's from another load, or it's invalid in some other way). |
546 // We expect this to be a rare occurrence. | 562 // We expect this to be a rare occurrence. |
547 RecordInternalError(ERR_BAD_TIMING_IPC); | 563 RecordInternalError(ERR_BAD_TIMING_IPC); |
548 } | 564 } |
549 } | 565 } |
550 | 566 |
551 } // namespace page_load_metrics | 567 } // namespace page_load_metrics |
OLD | NEW |