Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: chrome/browser/page_load_metrics/metrics_web_contents_observer.cc

Issue 2983533002: Revert of Provide WebContents::CreateParams to tab helpers. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
22 #include "chrome/common/chrome_features.h" 21 #include "chrome/common/chrome_features.h"
23 #include "chrome/common/page_load_metrics/page_load_metrics_messages.h" 22 #include "chrome/common/page_load_metrics/page_load_metrics_messages.h"
24 #include "chrome/common/page_load_metrics/page_load_timing.h" 23 #include "chrome/common/page_load_metrics/page_load_timing.h"
25 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/global_request_id.h" 25 #include "content/public/browser/global_request_id.h"
27 #include "content/public/browser/navigation_details.h" 26 #include "content/public/browser/navigation_details.h"
28 #include "content/public/browser/navigation_handle.h" 27 #include "content/public/browser/navigation_handle.h"
29 #include "content/public/browser/render_frame_host.h" 28 #include "content/public/browser/render_frame_host.h"
30 #include "content/public/browser/render_view_host.h" 29 #include "content/public/browser/render_view_host.h"
31 #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
63 navigation_handle->HasUserGesture(), 62 navigation_handle->HasUserGesture(),
64 committed_load && 63 committed_load &&
65 committed_load->input_tracker()->FindAndConsumeInputEventsBefore( 64 committed_load->input_tracker()->FindAndConsumeInputEventsBefore(
66 navigation_handle->NavigationStart())); 65 navigation_handle->NavigationStart()));
67 } 66 }
68 67
69 } // namespace 68 } // namespace
70 69
71 MetricsWebContentsObserver::MetricsWebContentsObserver( 70 MetricsWebContentsObserver::MetricsWebContentsObserver(
72 content::WebContents* web_contents, 71 content::WebContents* web_contents,
73 const base::Optional<content::WebContents::CreateParams>& create_params,
74 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) 72 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface)
75 : content::WebContentsObserver(web_contents), 73 : content::WebContentsObserver(web_contents),
76 in_foreground_(create_params ? !create_params->initially_hidden : false), 74 in_foreground_(false),
77 embedder_interface_(std::move(embedder_interface)), 75 embedder_interface_(std::move(embedder_interface)),
78 has_navigated_(false), 76 has_navigated_(false),
79 page_load_metrics_binding_(web_contents, this) { 77 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
87 RegisterInputEventObserver(web_contents->GetRenderViewHost()); 78 RegisterInputEventObserver(web_contents->GetRenderViewHost());
88 } 79 }
89 80
90 // static 81 // static
91 MetricsWebContentsObserver* MetricsWebContentsObserver::CreateForWebContents( 82 MetricsWebContentsObserver* MetricsWebContentsObserver::CreateForWebContents(
92 content::WebContents* web_contents, 83 content::WebContents* web_contents,
93 const base::Optional<content::WebContents::CreateParams>& create_params,
94 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) { 84 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) {
95 DCHECK(web_contents); 85 DCHECK(web_contents);
96 86
97 MetricsWebContentsObserver* metrics = FromWebContents(web_contents); 87 MetricsWebContentsObserver* metrics = FromWebContents(web_contents);
98 if (!metrics) { 88 if (!metrics) {
99 metrics = new MetricsWebContentsObserver(web_contents, create_params, 89 metrics = new MetricsWebContentsObserver(web_contents,
100 std::move(embedder_interface)); 90 std::move(embedder_interface));
101 web_contents->SetUserData(UserDataKey(), base::WrapUnique(metrics)); 91 web_contents->SetUserData(UserDataKey(), base::WrapUnique(metrics));
102 } 92 }
103 return metrics; 93 return metrics;
104 } 94 }
105 95
106 MetricsWebContentsObserver::~MetricsWebContentsObserver() { 96 MetricsWebContentsObserver::~MetricsWebContentsObserver() {
107 // TODO(csharrison): Use a more user-initiated signal for CLOSE. 97 // TODO(csharrison): Use a more user-initiated signal for CLOSE.
108 NotifyPageEndAllLoads(END_CLOSE, UserInitiatedInfo::NotUserInitiated()); 98 NotifyPageEndAllLoads(END_CLOSE, UserInitiatedInfo::NotUserInitiated());
109 99
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 observer_->RemoveTestingObserver(this); 675 observer_->RemoveTestingObserver(this);
686 observer_ = nullptr; 676 observer_ = nullptr;
687 } 677 }
688 } 678 }
689 679
690 void MetricsWebContentsObserver::TestingObserver::OnGoingAway() { 680 void MetricsWebContentsObserver::TestingObserver::OnGoingAway() {
691 observer_ = nullptr; 681 observer_ = nullptr;
692 } 682 }
693 683
694 } // namespace page_load_metrics 684 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698