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_update_dispatcher.h
" |
19 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" | 19 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
20 #include "chrome/browser/page_load_metrics/page_load_tracker.h" | 20 #include "chrome/browser/page_load_metrics/page_load_tracker.h" |
| 21 #include "chrome/browser/prerender/prerender_contents.h" |
21 #include "chrome/common/chrome_features.h" | 22 #include "chrome/common/chrome_features.h" |
22 #include "chrome/common/page_load_metrics/page_load_metrics_messages.h" | 23 #include "chrome/common/page_load_metrics/page_load_metrics_messages.h" |
23 #include "chrome/common/page_load_metrics/page_load_timing.h" | 24 #include "chrome/common/page_load_metrics/page_load_timing.h" |
24 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/global_request_id.h" | 26 #include "content/public/browser/global_request_id.h" |
26 #include "content/public/browser/navigation_details.h" | 27 #include "content/public/browser/navigation_details.h" |
27 #include "content/public/browser/navigation_handle.h" | 28 #include "content/public/browser/navigation_handle.h" |
28 #include "content/public/browser/render_frame_host.h" | 29 #include "content/public/browser/render_frame_host.h" |
29 #include "content/public/browser/render_view_host.h" | 30 #include "content/public/browser/render_view_host.h" |
30 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 navigation_handle->HasUserGesture(), | 63 navigation_handle->HasUserGesture(), |
63 committed_load && | 64 committed_load && |
64 committed_load->input_tracker()->FindAndConsumeInputEventsBefore( | 65 committed_load->input_tracker()->FindAndConsumeInputEventsBefore( |
65 navigation_handle->NavigationStart())); | 66 navigation_handle->NavigationStart())); |
66 } | 67 } |
67 | 68 |
68 } // namespace | 69 } // namespace |
69 | 70 |
70 MetricsWebContentsObserver::MetricsWebContentsObserver( | 71 MetricsWebContentsObserver::MetricsWebContentsObserver( |
71 content::WebContents* web_contents, | 72 content::WebContents* web_contents, |
| 73 const base::Optional<content::WebContents::CreateParams>& create_params, |
72 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) | 74 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) |
73 : content::WebContentsObserver(web_contents), | 75 : content::WebContentsObserver(web_contents), |
74 in_foreground_(false), | 76 in_foreground_(create_params ? !create_params->initially_hidden : false), |
75 embedder_interface_(std::move(embedder_interface)), | 77 embedder_interface_(std::move(embedder_interface)), |
76 has_navigated_(false), | 78 has_navigated_(false), |
77 page_load_metrics_binding_(web_contents, this) { | 79 page_load_metrics_binding_(web_contents, this) { |
| 80 // Prerender's CreateParams erroneously reports that it is not initially |
| 81 // hidden, so we manually override visibility state for prerender. |
| 82 const bool is_prerender = |
| 83 prerender::PrerenderContents::FromWebContents(web_contents) != nullptr; |
| 84 if (is_prerender) |
| 85 in_foreground_ = false; |
| 86 |
78 RegisterInputEventObserver(web_contents->GetRenderViewHost()); | 87 RegisterInputEventObserver(web_contents->GetRenderViewHost()); |
79 } | 88 } |
80 | 89 |
81 // static | 90 // static |
82 MetricsWebContentsObserver* MetricsWebContentsObserver::CreateForWebContents( | 91 MetricsWebContentsObserver* MetricsWebContentsObserver::CreateForWebContents( |
83 content::WebContents* web_contents, | 92 content::WebContents* web_contents, |
| 93 const base::Optional<content::WebContents::CreateParams>& create_params, |
84 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) { | 94 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) { |
85 DCHECK(web_contents); | 95 DCHECK(web_contents); |
86 | 96 |
87 MetricsWebContentsObserver* metrics = FromWebContents(web_contents); | 97 MetricsWebContentsObserver* metrics = FromWebContents(web_contents); |
88 if (!metrics) { | 98 if (!metrics) { |
89 metrics = new MetricsWebContentsObserver(web_contents, | 99 metrics = new MetricsWebContentsObserver(web_contents, create_params, |
90 std::move(embedder_interface)); | 100 std::move(embedder_interface)); |
91 web_contents->SetUserData(UserDataKey(), base::WrapUnique(metrics)); | 101 web_contents->SetUserData(UserDataKey(), base::WrapUnique(metrics)); |
92 } | 102 } |
93 return metrics; | 103 return metrics; |
94 } | 104 } |
95 | 105 |
96 MetricsWebContentsObserver::~MetricsWebContentsObserver() { | 106 MetricsWebContentsObserver::~MetricsWebContentsObserver() { |
97 // TODO(csharrison): Use a more user-initiated signal for CLOSE. | 107 // TODO(csharrison): Use a more user-initiated signal for CLOSE. |
98 NotifyPageEndAllLoads(END_CLOSE, UserInitiatedInfo::NotUserInitiated()); | 108 NotifyPageEndAllLoads(END_CLOSE, UserInitiatedInfo::NotUserInitiated()); |
99 | 109 |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 observer_->RemoveTestingObserver(this); | 685 observer_->RemoveTestingObserver(this); |
676 observer_ = nullptr; | 686 observer_ = nullptr; |
677 } | 687 } |
678 } | 688 } |
679 | 689 |
680 void MetricsWebContentsObserver::TestingObserver::OnGoingAway() { | 690 void MetricsWebContentsObserver::TestingObserver::OnGoingAway() { |
681 observer_ = nullptr; | 691 observer_ = nullptr; |
682 } | 692 } |
683 | 693 |
684 } // namespace page_load_metrics | 694 } // namespace page_load_metrics |
OLD | NEW |