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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 url_ = navigation_handle->GetURL(); | 153 url_ = navigation_handle->GetURL(); |
153 // We log the event that this load started. Because we don't know if a load is | 154 // We log the event that this load started. Because we don't know if a load is |
154 // relevant or if it will commit before now, we have to log this event at | 155 // relevant or if it will commit before now, we have to log this event at |
155 // commit time. | 156 // commit time. |
156 RecordCommittedEvent(COMMITTED_LOAD_STARTED, !started_in_foreground_); | 157 RecordCommittedEvent(COMMITTED_LOAD_STARTED, !started_in_foreground_); |
157 | 158 |
158 FOR_EACH_OBSERVER(PageLoadMetricsObserver, *observers_, | 159 FOR_EACH_OBSERVER(PageLoadMetricsObserver, *observers_, |
159 OnCommit(navigation_handle)); | 160 OnCommit(navigation_handle)); |
160 } | 161 } |
161 | 162 |
| 163 void PageLoadTracker::Redirect(content::NavigationHandle* navigation_handle) { |
| 164 FOR_EACH_OBSERVER(PageLoadMetricsObserver, *observers_, |
| 165 OnRedirect(navigation_handle)); |
| 166 } |
| 167 |
162 bool PageLoadTracker::UpdateTiming(const PageLoadTiming& new_timing) { | 168 bool PageLoadTracker::UpdateTiming(const PageLoadTiming& new_timing) { |
163 // Throw away IPCs that are not relevant to the current navigation. | 169 // Throw away IPCs that are not relevant to the current navigation. |
164 // Two timing structures cannot refer to the same navigation if they indicate | 170 // Two timing structures cannot refer to the same navigation if they indicate |
165 // that a navigation started at different times, so a new timing struct with a | 171 // that a navigation started at different times, so a new timing struct with a |
166 // different start time from an earlier struct is considered invalid. | 172 // different start time from an earlier struct is considered invalid. |
167 bool valid_timing_descendent = | 173 bool valid_timing_descendent = |
168 timing_.navigation_start.is_null() || | 174 timing_.navigation_start.is_null() || |
169 timing_.navigation_start == new_timing.navigation_start; | 175 timing_.navigation_start == new_timing.navigation_start; |
170 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent) { | 176 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent) { |
171 timing_ = new_timing; | 177 timing_ = new_timing; |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 const std::string& mime_type = web_contents()->GetContentsMimeType(); | 470 const std::string& mime_type = web_contents()->GetContentsMimeType(); |
465 DCHECK(!browser_url.is_empty()); | 471 DCHECK(!browser_url.is_empty()); |
466 DCHECK(!mime_type.empty()); | 472 DCHECK(!mime_type.empty()); |
467 if (!IsRelevantNavigation(navigation_handle, browser_url, mime_type)) | 473 if (!IsRelevantNavigation(navigation_handle, browser_url, mime_type)) |
468 return; | 474 return; |
469 | 475 |
470 committed_load_ = finished_nav.Pass(); | 476 committed_load_ = finished_nav.Pass(); |
471 committed_load_->Commit(navigation_handle); | 477 committed_load_->Commit(navigation_handle); |
472 } | 478 } |
473 | 479 |
| 480 void MetricsWebContentsObserver::DidRedirectNavigation( |
| 481 content::NavigationHandle* navigation_handle) { |
| 482 if (!navigation_handle->IsInMainFrame()) |
| 483 return; |
| 484 auto it = provisional_loads_.find(navigation_handle); |
| 485 if (it == provisional_loads_.end()) |
| 486 return; |
| 487 it->second->Redirect(navigation_handle); |
| 488 } |
| 489 |
474 void MetricsWebContentsObserver::WasShown() { | 490 void MetricsWebContentsObserver::WasShown() { |
475 in_foreground_ = true; | 491 in_foreground_ = true; |
476 if (committed_load_) | 492 if (committed_load_) |
477 committed_load_->WebContentsShown(); | 493 committed_load_->WebContentsShown(); |
478 for (const auto& kv : provisional_loads_) { | 494 for (const auto& kv : provisional_loads_) { |
479 kv.second->WebContentsShown(); | 495 kv.second->WebContentsShown(); |
480 } | 496 } |
481 } | 497 } |
482 | 498 |
483 void MetricsWebContentsObserver::WasHidden() { | 499 void MetricsWebContentsObserver::WasHidden() { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 | 542 |
527 if (!committed_load_->UpdateTiming(timing)) { | 543 if (!committed_load_->UpdateTiming(timing)) { |
528 // If the page load tracker cannot update its timing, something is wrong | 544 // If the page load tracker cannot update its timing, something is wrong |
529 // with the IPC (it's from another load, or it's invalid in some other way). | 545 // with the IPC (it's from another load, or it's invalid in some other way). |
530 // We expect this to be a rare occurrence. | 546 // We expect this to be a rare occurrence. |
531 RecordInternalError(ERR_BAD_TIMING_IPC); | 547 RecordInternalError(ERR_BAD_TIMING_IPC); |
532 } | 548 } |
533 } | 549 } |
534 | 550 |
535 } // namespace page_load_metrics | 551 } // namespace page_load_metrics |
OLD | NEW |