Chromium Code Reviews| 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 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 } | 518 } |
| 519 | 519 |
| 520 aborted_provisional_loads_.clear(); | 520 aborted_provisional_loads_.clear(); |
| 521 return last_aborted_load; | 521 return last_aborted_load; |
| 522 } | 522 } |
| 523 | 523 |
| 524 void MetricsWebContentsObserver::OnTimingUpdated( | 524 void MetricsWebContentsObserver::OnTimingUpdated( |
| 525 content::RenderFrameHost* render_frame_host, | 525 content::RenderFrameHost* render_frame_host, |
| 526 const PageLoadTiming& timing, | 526 const PageLoadTiming& timing, |
| 527 const PageLoadMetadata& metadata) { | 527 const PageLoadMetadata& metadata) { |
| 528 if (render_frame_host->GetParent() != nullptr) { | |
|
nasko
2017/04/04 22:18:14
Dumping just a bit of context from chat with cshar
Bryan McQuade
2017/04/06 18:46:33
Thanks for this. It's helpful to know.
I'm assumi
| |
| 529 // Child frames may send PageLoadMetadata updates, but not PageLoadTiming | |
| 530 // updates. | |
| 531 if (!timing.IsEmpty()) | |
| 532 RecordInternalError(ERR_TIMING_IPC_FROM_SUBFRAME); | |
| 533 committed_load_->UpdateChildFrameMetadata(metadata); | |
| 534 return; | |
| 535 } | |
| 536 | |
| 528 // We may receive notifications from frames that have been navigated away | 537 // We may receive notifications from frames that have been navigated away |
| 529 // from. We simply ignore them. | 538 // from. We simply ignore them. |
| 530 if (!render_frame_host->GetRenderViewHost() || | 539 if (render_frame_host != web_contents()->GetMainFrame()) { |
| 531 render_frame_host->GetRenderViewHost()->GetMainFrame() != | |
| 532 web_contents()->GetMainFrame()) { | |
| 533 RecordInternalError(ERR_IPC_FROM_WRONG_FRAME); | 540 RecordInternalError(ERR_IPC_FROM_WRONG_FRAME); |
| 534 return; | 541 return; |
| 535 } | 542 } |
| 536 | 543 |
| 537 // While timings arriving for the wrong frame are expected, we do not expect | 544 // While timings arriving for the wrong frame are expected, we do not expect |
| 538 // any of the errors below. Thus, we track occurrences of all errors below, | 545 // any of the errors below. Thus, we track occurrences of all errors below, |
| 539 // rather than returning early after encountering an error. | 546 // rather than returning early after encountering an error. |
| 540 | 547 |
| 541 bool error = false; | 548 bool error = false; |
| 542 if (!committed_load_) { | 549 if (!committed_load_) { |
| 543 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD); | 550 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD); |
| 544 error = true; | 551 error = true; |
| 545 } | 552 } |
| 546 | 553 |
| 547 if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) { | 554 if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) { |
| 548 RecordInternalError(ERR_IPC_FROM_BAD_URL_SCHEME); | 555 RecordInternalError(ERR_IPC_FROM_BAD_URL_SCHEME); |
| 549 error = true; | 556 error = true; |
| 550 } | 557 } |
| 551 | 558 |
| 552 if (error) | 559 if (error) |
| 553 return; | 560 return; |
| 554 | 561 |
| 555 if (render_frame_host->GetParent() != nullptr) { | |
| 556 // Child frames may send PageLoadMetadata updates, but not PageLoadTiming | |
| 557 // updates. | |
| 558 if (!timing.IsEmpty()) | |
| 559 RecordInternalError(ERR_TIMING_IPC_FROM_SUBFRAME); | |
| 560 committed_load_->UpdateChildFrameMetadata(metadata); | |
| 561 return; | |
| 562 } | |
| 563 | |
| 564 if (!committed_load_->UpdateTiming(timing, metadata)) { | 562 if (!committed_load_->UpdateTiming(timing, metadata)) { |
| 565 // If the page load tracker cannot update its timing, something is wrong | 563 // If the page load tracker cannot update its timing, something is wrong |
| 566 // with the IPC (it's from another load, or it's invalid in some other way). | 564 // with the IPC (it's from another load, or it's invalid in some other way). |
| 567 // We expect this to be a rare occurrence. | 565 // We expect this to be a rare occurrence. |
| 568 RecordInternalError(ERR_BAD_TIMING_IPC); | 566 RecordInternalError(ERR_BAD_TIMING_IPC); |
| 569 } | 567 } |
| 570 } | 568 } |
| 571 | 569 |
| 572 bool MetricsWebContentsObserver::ShouldTrackNavigation( | 570 bool MetricsWebContentsObserver::ShouldTrackNavigation( |
| 573 content::NavigationHandle* navigation_handle) const { | 571 content::NavigationHandle* navigation_handle) const { |
| 574 DCHECK(navigation_handle->IsInMainFrame()); | 572 DCHECK(navigation_handle->IsInMainFrame()); |
| 575 DCHECK(!navigation_handle->HasCommitted() || | 573 DCHECK(!navigation_handle->HasCommitted() || |
| 576 !navigation_handle->IsSameDocument()); | 574 !navigation_handle->IsSameDocument()); |
| 577 | 575 |
| 578 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(), | 576 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(), |
| 579 navigation_handle).ShouldTrack(); | 577 navigation_handle).ShouldTrack(); |
| 580 } | 578 } |
| 581 | 579 |
| 582 } // namespace page_load_metrics | 580 } // namespace page_load_metrics |
| OLD | NEW |