OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/previews/previews_infobar_tab_helper.h" | 5 #include "chrome/browser/previews/previews_infobar_tab_helper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "chrome/browser/loader/chrome_navigation_data.h" | 9 #include "chrome/browser/loader/chrome_navigation_data.h" |
10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
11 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" | 11 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" |
12 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" | |
12 #include "chrome/browser/previews/previews_infobar_delegate.h" | 13 #include "chrome/browser/previews/previews_infobar_delegate.h" |
13 #include "chrome/browser/previews/previews_service.h" | 14 #include "chrome/browser/previews/previews_service.h" |
14 #include "chrome/browser/previews/previews_service_factory.h" | 15 #include "chrome/browser/previews/previews_service_factory.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h" | 17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h" |
17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h" | 18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h" |
18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h" | 19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h" |
19 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" | 20 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" |
20 #include "components/previews/core/previews_experiments.h" | 21 #include "components/previews/core/previews_experiments.h" |
21 #include "components/previews/core/previews_ui_service.h" | 22 #include "components/previews/core/previews_ui_service.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 | 65 |
65 void PreviewsInfoBarTabHelper::DidFinishNavigation( | 66 void PreviewsInfoBarTabHelper::DidFinishNavigation( |
66 content::NavigationHandle* navigation_handle) { | 67 content::NavigationHandle* navigation_handle) { |
67 // Only show the infobar if this is a full main frame navigation. | 68 // Only show the infobar if this is a full main frame navigation. |
68 if (!navigation_handle->IsInMainFrame() || | 69 if (!navigation_handle->IsInMainFrame() || |
69 !navigation_handle->HasCommitted() || navigation_handle->IsSameDocument()) | 70 !navigation_handle->HasCommitted() || navigation_handle->IsSameDocument()) |
70 return; | 71 return; |
71 displayed_preview_infobar_ = false; | 72 displayed_preview_infobar_ = false; |
72 ClearLastNavigationAsync(); | 73 ClearLastNavigationAsync(); |
73 committed_data_saver_navigation_id_.reset(); | 74 committed_data_saver_navigation_id_.reset(); |
75 source_id_.reset(); | |
74 | 76 |
75 // As documented in content/public/browser/navigation_handle.h, this | 77 // As documented in content/public/browser/navigation_handle.h, this |
76 // NavigationData is a clone of the NavigationData instance returned from | 78 // NavigationData is a clone of the NavigationData instance returned from |
77 // ResourceDispatcherHostDelegate::GetNavigationData during commit. | 79 // ResourceDispatcherHostDelegate::GetNavigationData during commit. |
78 // Because ChromeResourceDispatcherHostDelegate always returns a | 80 // Because ChromeResourceDispatcherHostDelegate always returns a |
79 // ChromeNavigationData, it is safe to static_cast here. | 81 // ChromeNavigationData, it is safe to static_cast here. |
80 ChromeNavigationData* chrome_navigation_data = | 82 ChromeNavigationData* chrome_navigation_data = |
81 static_cast<ChromeNavigationData*>( | 83 static_cast<ChromeNavigationData*>( |
82 navigation_handle->GetNavigationData()); | 84 navigation_handle->GetNavigationData()); |
83 if (chrome_navigation_data) { | 85 if (chrome_navigation_data) { |
84 data_reduction_proxy::DataReductionProxyData* data = | 86 data_reduction_proxy::DataReductionProxyData* data = |
85 chrome_navigation_data->GetDataReductionProxyData(); | 87 chrome_navigation_data->GetDataReductionProxyData(); |
86 | 88 |
87 if (data && data->page_id()) { | 89 if (data && data->page_id()) { |
88 committed_data_saver_navigation_id_ = data_reduction_proxy::NavigationID( | 90 committed_data_saver_navigation_id_ = data_reduction_proxy::NavigationID( |
89 data->page_id().value(), data->session_key()); | 91 data->page_id().value(), data->session_key()); |
90 } | 92 } |
91 } | 93 } |
94 page_load_metrics::MetricsWebContentsObserver* metrics_observer = | |
95 page_load_metrics::MetricsWebContentsObserver::FromWebContents( | |
96 web_contents()); | |
97 if (metrics_observer) { | |
98 // Due to undefined ordering between this observer and |metrics_observer|, | |
99 // whether this navigation is comitted in the PLM framework or tracked as | |
100 // pending is undefined. | |
101 source_id_ = | |
102 metrics_observer->GetUKMSourceIdForNavigationHandle(navigation_handle); | |
Bryan McQuade
2017/06/28 13:13:40
one risk with this approach is that PLM explicitly
RyanSturm
2017/06/28 16:19:35
I think that is fine as committed_load_ will be em
Bryan McQuade
2017/06/28 16:48:18
Thanks! It sounds like, given the order can vary d
RyanSturm
2017/06/28 16:56:56
I'll go ahead and add the comments as suggested be
RyanSturm
2017/07/11 21:46:41
Done.
| |
103 if (!source_id_) | |
104 source_id_ = metrics_observer->GetUKMSourceForCommittedLoad(); | |
105 } | |
92 | 106 |
93 #if defined(OS_ANDROID) | 107 #if defined(OS_ANDROID) |
94 offline_pages::OfflinePageTabHelper* tab_helper = | 108 offline_pages::OfflinePageTabHelper* tab_helper = |
95 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents()); | 109 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents()); |
96 | 110 |
97 if (tab_helper && tab_helper->IsShowingOfflinePreview()) { | 111 if (tab_helper && tab_helper->IsShowingOfflinePreview()) { |
98 if (navigation_handle->IsErrorPage()) { | 112 if (navigation_handle->IsErrorPage()) { |
99 // TODO(ryansturm): Add UMA for errors. | 113 // TODO(ryansturm): Add UMA for errors. |
100 return; | 114 return; |
101 } | 115 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 151 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
138 browser_context_); | 152 browser_context_); |
139 if (!data_reduction_proxy_settings || | 153 if (!data_reduction_proxy_settings || |
140 !data_reduction_proxy_settings->data_reduction_proxy_service()) { | 154 !data_reduction_proxy_settings->data_reduction_proxy_service()) { |
141 return; | 155 return; |
142 } | 156 } |
143 data_reduction_proxy_settings->data_reduction_proxy_service() | 157 data_reduction_proxy_settings->data_reduction_proxy_service() |
144 ->pingback_client() | 158 ->pingback_client() |
145 ->ClearNavigationKeyAsync(committed_data_saver_navigation_id_.value()); | 159 ->ClearNavigationKeyAsync(committed_data_saver_navigation_id_.value()); |
146 } | 160 } |
OLD | NEW |