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_util.h" | 18 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
19 #include "chrome/browser/page_load_metrics/page_load_tracker.h" | 19 #include "chrome/browser/page_load_metrics/page_load_tracker.h" |
20 #include "chrome/browser/prerender/prerender_contents.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" |
28 #include "content/public/browser/render_view_host.h" | 29 #include "content/public/browser/render_view_host.h" |
29 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 navigation_handle->HasUserGesture(), | 62 navigation_handle->HasUserGesture(), |
62 committed_load && | 63 committed_load && |
63 committed_load->input_tracker()->FindAndConsumeInputEventsBefore( | 64 committed_load->input_tracker()->FindAndConsumeInputEventsBefore( |
64 navigation_handle->NavigationStart())); | 65 navigation_handle->NavigationStart())); |
65 } | 66 } |
66 | 67 |
67 } // namespace | 68 } // namespace |
68 | 69 |
69 MetricsWebContentsObserver::MetricsWebContentsObserver( | 70 MetricsWebContentsObserver::MetricsWebContentsObserver( |
70 content::WebContents* web_contents, | 71 content::WebContents* web_contents, |
72 const base::Optional<content::WebContents::CreateParams>& create_params, | |
71 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) | 73 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) |
72 : content::WebContentsObserver(web_contents), | 74 : content::WebContentsObserver(web_contents), |
73 in_foreground_(false), | 75 in_foreground_(create_params ? !create_params->initially_hidden : false), |
74 embedder_interface_(std::move(embedder_interface)), | 76 embedder_interface_(std::move(embedder_interface)), |
75 has_navigated_(false), | 77 has_navigated_(false), |
76 page_load_metrics_binding_(web_contents, this) { | 78 page_load_metrics_binding_(web_contents, this) { |
79 // Prerender's CreateParams erroneously reports that it is not initially | |
80 // hidden, so we manually override visibility state for prerender. | |
81 const bool is_prerender = | |
82 prerender::PrerenderContents::FromWebContents(web_contents) != nullptr; | |
Avi (use Gerrit)
2017/05/23 15:38:59
prerender 🙄
Bryan McQuade
2017/05/23 20:29:57
sorry, what are you requesting here? looks like th
Avi (use Gerrit)
2017/05/23 20:49:54
No request from me here.
| |
83 if (is_prerender) | |
84 in_foreground_ = false; | |
85 | |
77 RegisterInputEventObserver(web_contents->GetRenderViewHost()); | 86 RegisterInputEventObserver(web_contents->GetRenderViewHost()); |
78 } | 87 } |
79 | 88 |
80 // static | 89 // static |
81 MetricsWebContentsObserver* MetricsWebContentsObserver::CreateForWebContents( | 90 MetricsWebContentsObserver* MetricsWebContentsObserver::CreateForWebContents( |
82 content::WebContents* web_contents, | 91 content::WebContents* web_contents, |
92 const base::Optional<content::WebContents::CreateParams>& create_params, | |
83 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) { | 93 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) { |
84 DCHECK(web_contents); | 94 DCHECK(web_contents); |
85 | 95 |
86 MetricsWebContentsObserver* metrics = FromWebContents(web_contents); | 96 MetricsWebContentsObserver* metrics = FromWebContents(web_contents); |
87 if (!metrics) { | 97 if (!metrics) { |
88 metrics = new MetricsWebContentsObserver(web_contents, | 98 metrics = new MetricsWebContentsObserver(web_contents, create_params, |
89 std::move(embedder_interface)); | 99 std::move(embedder_interface)); |
90 web_contents->SetUserData(UserDataKey(), base::WrapUnique(metrics)); | 100 web_contents->SetUserData(UserDataKey(), base::WrapUnique(metrics)); |
91 } | 101 } |
92 return metrics; | 102 return metrics; |
93 } | 103 } |
94 | 104 |
95 MetricsWebContentsObserver::~MetricsWebContentsObserver() { | 105 MetricsWebContentsObserver::~MetricsWebContentsObserver() { |
96 // TODO(csharrison): Use a more user-initiated signal for CLOSE. | 106 // TODO(csharrison): Use a more user-initiated signal for CLOSE. |
97 NotifyPageEndAllLoads(END_CLOSE, UserInitiatedInfo::NotUserInitiated()); | 107 NotifyPageEndAllLoads(END_CLOSE, UserInitiatedInfo::NotUserInitiated()); |
98 | 108 |
(...skipping 576 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 |