| 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> |
| 11 | 11 |
| 12 #include "base/feature_list.h" | 12 #include "base/feature_list.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 16 #include "chrome/browser/page_load_metrics/browser_page_track_decider.h" | 16 #include "chrome/browser/page_load_metrics/browser_page_track_decider.h" |
| 17 #include "chrome/browser/page_load_metrics/page_load_metrics_embedder_interface.
h" | 17 #include "chrome/browser/page_load_metrics/page_load_metrics_embedder_interface.
h" |
| 18 #include "chrome/browser/page_load_metrics/page_load_metrics_update_dispatcher.h
" |
| 18 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" | 19 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
| 19 #include "chrome/browser/page_load_metrics/page_load_tracker.h" | 20 #include "chrome/browser/page_load_metrics/page_load_tracker.h" |
| 20 #include "chrome/common/chrome_features.h" | 21 #include "chrome/common/chrome_features.h" |
| 21 #include "chrome/common/page_load_metrics/page_load_metrics_messages.h" | 22 #include "chrome/common/page_load_metrics/page_load_metrics_messages.h" |
| 22 #include "chrome/common/page_load_metrics/page_load_timing.h" | 23 #include "chrome/common/page_load_metrics/page_load_timing.h" |
| 23 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/global_request_id.h" | 25 #include "content/public/browser/global_request_id.h" |
| 25 #include "content/public/browser/navigation_details.h" | 26 #include "content/public/browser/navigation_details.h" |
| 26 #include "content/public/browser/navigation_handle.h" | 27 #include "content/public/browser/navigation_handle.h" |
| 27 #include "content/public/browser/render_frame_host.h" | 28 #include "content/public/browser/render_frame_host.h" |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 return committed_load_->ComputePageLoadExtraInfo(); | 320 return committed_load_->ComputePageLoadExtraInfo(); |
| 320 } | 321 } |
| 321 | 322 |
| 322 void MetricsWebContentsObserver::DidFinishNavigation( | 323 void MetricsWebContentsObserver::DidFinishNavigation( |
| 323 content::NavigationHandle* navigation_handle) { | 324 content::NavigationHandle* navigation_handle) { |
| 324 if (!navigation_handle->IsInMainFrame()) { | 325 if (!navigation_handle->IsInMainFrame()) { |
| 325 if (committed_load_ && navigation_handle->GetParentFrame() && | 326 if (committed_load_ && navigation_handle->GetParentFrame() && |
| 326 GetMainFrame(navigation_handle->GetParentFrame()) == | 327 GetMainFrame(navigation_handle->GetParentFrame()) == |
| 327 web_contents()->GetMainFrame()) { | 328 web_contents()->GetMainFrame()) { |
| 328 committed_load_->DidFinishSubFrameNavigation(navigation_handle); | 329 committed_load_->DidFinishSubFrameNavigation(navigation_handle); |
| 330 committed_load_->metrics_update_dispatcher()->DidFinishSubFrameNavigation( |
| 331 navigation_handle); |
| 329 } | 332 } |
| 330 return; | 333 return; |
| 331 } | 334 } |
| 332 | 335 |
| 333 std::unique_ptr<PageLoadTracker> finished_nav( | 336 std::unique_ptr<PageLoadTracker> finished_nav( |
| 334 std::move(provisional_loads_[navigation_handle])); | 337 std::move(provisional_loads_[navigation_handle])); |
| 335 provisional_loads_.erase(navigation_handle); | 338 provisional_loads_.erase(navigation_handle); |
| 336 | 339 |
| 337 // Ignore same-document navigations. | 340 // Ignore same-document navigations. |
| 338 if (navigation_handle->HasCommitted() && | 341 if (navigation_handle->HasCommitted() && |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 } | 605 } |
| 603 | 606 |
| 604 if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) { | 607 if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) { |
| 605 RecordInternalError(ERR_IPC_FROM_BAD_URL_SCHEME); | 608 RecordInternalError(ERR_IPC_FROM_BAD_URL_SCHEME); |
| 606 error = true; | 609 error = true; |
| 607 } | 610 } |
| 608 | 611 |
| 609 if (error) | 612 if (error) |
| 610 return; | 613 return; |
| 611 | 614 |
| 615 committed_load_->metrics_update_dispatcher()->UpdateMetrics(render_frame_host, |
| 616 timing, metadata); |
| 617 |
| 612 const bool is_main_frame = (render_frame_host->GetParent() == nullptr); | 618 const bool is_main_frame = (render_frame_host->GetParent() == nullptr); |
| 613 if (is_main_frame) { | |
| 614 committed_load_->UpdateTiming(timing, metadata); | |
| 615 } else { | |
| 616 committed_load_->UpdateSubFrameTiming(render_frame_host, timing, metadata); | |
| 617 } | |
| 618 | |
| 619 for (auto& observer : testing_observers_) | 619 for (auto& observer : testing_observers_) |
| 620 observer.OnTimingUpdated(is_main_frame, timing, metadata); | 620 observer.OnTimingUpdated(is_main_frame, timing, metadata); |
| 621 } | 621 } |
| 622 | 622 |
| 623 void MetricsWebContentsObserver::OnUpdateTimingOverIPC( | 623 void MetricsWebContentsObserver::OnUpdateTimingOverIPC( |
| 624 content::RenderFrameHost* render_frame_host, | 624 content::RenderFrameHost* render_frame_host, |
| 625 const mojom::PageLoadTiming& timing, | 625 const mojom::PageLoadTiming& timing, |
| 626 const mojom::PageLoadMetadata& metadata) { | 626 const mojom::PageLoadMetadata& metadata) { |
| 627 DCHECK(!base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication)); | 627 DCHECK(!base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication)); |
| 628 OnTimingUpdated(render_frame_host, timing, metadata); | 628 OnTimingUpdated(render_frame_host, timing, metadata); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 observer_->RemoveTestingObserver(this); | 675 observer_->RemoveTestingObserver(this); |
| 676 observer_ = nullptr; | 676 observer_ = nullptr; |
| 677 } | 677 } |
| 678 } | 678 } |
| 679 | 679 |
| 680 void MetricsWebContentsObserver::TestingObserver::OnGoingAway() { | 680 void MetricsWebContentsObserver::TestingObserver::OnGoingAway() { |
| 681 observer_ = nullptr; | 681 observer_ = nullptr; |
| 682 } | 682 } |
| 683 | 683 |
| 684 } // namespace page_load_metrics | 684 } // namespace page_load_metrics |
| OLD | NEW |