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 "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" | 5 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <ostream> | 8 #include <ostream> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 aborted_provisional_loads_.clear(); | 505 aborted_provisional_loads_.clear(); |
506 return last_aborted_load; | 506 return last_aborted_load; |
507 } | 507 } |
508 | 508 |
509 void MetricsWebContentsObserver::OnTimingUpdated( | 509 void MetricsWebContentsObserver::OnTimingUpdated( |
510 content::RenderFrameHost* render_frame_host, | 510 content::RenderFrameHost* render_frame_host, |
511 const PageLoadTiming& timing, | 511 const PageLoadTiming& timing, |
512 const PageLoadMetadata& metadata) { | 512 const PageLoadMetadata& metadata) { |
513 // We may receive notifications from frames that have been navigated away | 513 // We may receive notifications from frames that have been navigated away |
514 // from. We simply ignore them. | 514 // from. We simply ignore them. |
515 if (render_frame_host != web_contents()->GetMainFrame()) { | 515 if (!render_frame_host->GetRenderViewHost() || |
| 516 render_frame_host->GetRenderViewHost()->GetMainFrame() != |
| 517 web_contents()->GetMainFrame()) { |
516 RecordInternalError(ERR_IPC_FROM_WRONG_FRAME); | 518 RecordInternalError(ERR_IPC_FROM_WRONG_FRAME); |
517 return; | 519 return; |
518 } | 520 } |
519 | 521 |
520 // While timings arriving for the wrong frame are expected, we do not expect | 522 // While timings arriving for the wrong frame are expected, we do not expect |
521 // any of the errors below. Thus, we track occurrences of all errors below, | 523 // any of the errors below. Thus, we track occurrences of all errors below, |
522 // rather than returning early after encountering an error. | 524 // rather than returning early after encountering an error. |
523 | 525 |
524 bool error = false; | 526 bool error = false; |
525 if (!committed_load_) { | 527 if (!committed_load_) { |
526 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD); | 528 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD); |
527 error = true; | 529 error = true; |
528 } | 530 } |
529 | 531 |
530 if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) { | 532 if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) { |
531 RecordInternalError(ERR_IPC_FROM_BAD_URL_SCHEME); | 533 RecordInternalError(ERR_IPC_FROM_BAD_URL_SCHEME); |
532 error = true; | 534 error = true; |
533 } | 535 } |
534 | 536 |
535 if (error) | 537 if (error) |
536 return; | 538 return; |
537 | 539 |
| 540 if (render_frame_host->GetParent() != nullptr) { |
| 541 // Child frames may send PageLoadMetadata updates, but not PageLoadTiming |
| 542 // updates. |
| 543 if (!timing.IsEmpty()) |
| 544 RecordInternalError(ERR_TIMING_IPC_FROM_SUBFRAME); |
| 545 committed_load_->UpdateChildMetadata(metadata); |
| 546 return; |
| 547 } |
| 548 |
538 if (!committed_load_->UpdateTiming(timing, metadata)) { | 549 if (!committed_load_->UpdateTiming(timing, metadata)) { |
539 // If the page load tracker cannot update its timing, something is wrong | 550 // If the page load tracker cannot update its timing, something is wrong |
540 // with the IPC (it's from another load, or it's invalid in some other way). | 551 // with the IPC (it's from another load, or it's invalid in some other way). |
541 // We expect this to be a rare occurrence. | 552 // We expect this to be a rare occurrence. |
542 RecordInternalError(ERR_BAD_TIMING_IPC); | 553 RecordInternalError(ERR_BAD_TIMING_IPC); |
543 } | 554 } |
544 } | 555 } |
545 | 556 |
546 bool MetricsWebContentsObserver::ShouldTrackNavigation( | 557 bool MetricsWebContentsObserver::ShouldTrackNavigation( |
547 content::NavigationHandle* navigation_handle) const { | 558 content::NavigationHandle* navigation_handle) const { |
548 DCHECK(navigation_handle->IsInMainFrame()); | 559 DCHECK(navigation_handle->IsInMainFrame()); |
549 DCHECK(!navigation_handle->HasCommitted() || | 560 DCHECK(!navigation_handle->HasCommitted() || |
550 !navigation_handle->IsSameDocument()); | 561 !navigation_handle->IsSameDocument()); |
551 | 562 |
552 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(), | 563 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(), |
553 navigation_handle).ShouldTrack(); | 564 navigation_handle).ShouldTrack(); |
554 } | 565 } |
555 | 566 |
556 } // namespace page_load_metrics | 567 } // namespace page_load_metrics |
OLD | NEW |