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

Side by Side Diff: chrome/browser/previews/previews_infobar_delegate.cc

Issue 2875993002: Converging the two previews type enums (Closed)
Patch Set: megjablon nit Created 3 years, 7 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 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_delegate.h" 5 #include "chrome/browser/previews/previews_infobar_delegate.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram.h"
8 #include "base/optional.h" 8 #include "base/optional.h"
9 #include "chrome/browser/android/android_theme_resources.h" 9 #include "chrome/browser/android/android_theme_resources.h"
10 #include "chrome/browser/infobars/infobar_service.h" 10 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" 11 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
12 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" 12 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h"
13 #include "chrome/browser/previews/previews_infobar_tab_helper.h" 13 #include "chrome/browser/previews/previews_infobar_tab_helper.h"
14 #include "chrome/grit/generated_resources.h" 14 #include "chrome/grit/generated_resources.h"
15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping back_client.h" 15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping back_client.h"
16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h" 16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h"
17 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" 17 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h"
18 #include "components/infobars/core/infobar.h" 18 #include "components/infobars/core/infobar.h"
19 #include "content/public/browser/render_frame_host.h" 19 #include "content/public/browser/render_frame_host.h"
20 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
21 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
22 22
23 #if defined(OS_ANDROID) 23 #if defined(OS_ANDROID)
24 #include "chrome/browser/ui/android/infobars/previews_infobar.h" 24 #include "chrome/browser/ui/android/infobars/previews_infobar.h"
25 #endif 25 #endif
26 26
27 namespace { 27 namespace {
28 28
29 // Key of the UMA Previews.InfoBarAction.LoFi histogram. 29 void RecordPreviewsInfoBarAction(
30 const char kUMAPreviewsInfoBarActionLoFi[] = "Previews.InfoBarAction.LoFi"; 30 previews::PreviewsType previews_type,
31 PreviewsInfoBarDelegate::PreviewsInfoBarAction action) {
32 int32_t max_limit =
33 static_cast<int32_t>(PreviewsInfoBarDelegate::INFOBAR_INDEX_BOUNDARY);
34 base::LinearHistogram::FactoryGet(
35 base::StringPrintf("Previews.InfoBarAction.%s",
36 GetStringNameForType(previews_type).c_str()),
37 1, max_limit, max_limit + 1,
38 base::HistogramBase::kUmaTargetedHistogramFlag)
39 ->Add(static_cast<int32_t>(action));
40 }
31 41
32 // Key of the UMA Previews.InfoBarAction.Offline histogram. 42 // Sends opt out information to the pingback service based on a key value in the
33 const char kUMAPreviewsInfoBarActionOffline[] = 43 // infobar tab helper. Sending this information in the case of a navigation that
34 "Previews.InfoBarAction.Offline"; 44 // should not send a pingback (or is not a server preview) will not alter the
35 45 // pingback.
36 // Key of the UMA Previews.InfoBarAction.LitePage histogram. 46 void ReportPingbackInformation(content::WebContents* web_contents) {
37 const char kUMAPreviewsInfoBarActionLitePage[] = 47 auto* data_reduction_proxy_settings =
38 "Previews.InfoBarAction.LitePage"; 48 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
39 49 web_contents->GetBrowserContext());
40 void RecordPreviewsInfoBarAction( 50 PreviewsInfoBarTabHelper* infobar_tab_helper =
41 PreviewsInfoBarDelegate::PreviewsInfoBarType infobar_type, 51 PreviewsInfoBarTabHelper::FromWebContents(web_contents);
42 PreviewsInfoBarDelegate::PreviewsInfoBarAction action) { 52 if (infobar_tab_helper &&
43 if (infobar_type == PreviewsInfoBarDelegate::LOFI) { 53 infobar_tab_helper->committed_data_saver_navigation_id()) {
44 UMA_HISTOGRAM_ENUMERATION(kUMAPreviewsInfoBarActionLoFi, action, 54 data_reduction_proxy_settings->data_reduction_proxy_service()
45 PreviewsInfoBarDelegate::INFOBAR_INDEX_BOUNDARY); 55 ->pingback_client()
46 } else if (infobar_type == PreviewsInfoBarDelegate::LITE_PAGE) { 56 ->AddOptOut(
47 UMA_HISTOGRAM_ENUMERATION(kUMAPreviewsInfoBarActionLitePage, action, 57 infobar_tab_helper->committed_data_saver_navigation_id().value());
48 PreviewsInfoBarDelegate::INFOBAR_INDEX_BOUNDARY);
49 } else if (infobar_type == PreviewsInfoBarDelegate::OFFLINE) {
50 UMA_HISTOGRAM_ENUMERATION(kUMAPreviewsInfoBarActionOffline, action,
51 PreviewsInfoBarDelegate::INFOBAR_INDEX_BOUNDARY);
52 } 58 }
53 } 59 }
54 60
61 // Increments the prefs-based opt out information for data reduction proxy when
62 // the user is not already transitioned to the PreviewsBlackList.
63 void IncrementDataReductionProxyPrefs(content::WebContents* web_contents) {
64 auto* data_reduction_proxy_settings =
65 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
66 web_contents->GetBrowserContext());
67 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages();
68 }
69
70 // Reloads the content of the page without previews.
71 void ReloadWithoutPreviews(previews::PreviewsType previews_type,
72 content::WebContents* web_contents) {
73 switch (previews_type) {
74 case previews::PreviewsType::LITE_PAGE:
75 case previews::PreviewsType::OFFLINE:
76 // Prevent LoFi and lite page modes from showing after reload.
77 // TODO(ryansturm): rename DISABLE_LOFI_MODE to DISABLE_PREVIEWS.
78 // crbug.com/707272
79 web_contents->GetController().Reload(
80 content::ReloadType::DISABLE_LOFI_MODE, true);
81 break;
82 case previews::PreviewsType::LOFI:
83 web_contents->ReloadLoFiImages();
84 break;
85 case previews::PreviewsType::NONE:
86 case previews::PreviewsType::LAST:
87 break;
88 }
89 }
90
55 } // namespace 91 } // namespace
56 92
57 PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() { 93 PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() {
58 if (!on_dismiss_callback_.is_null()) 94 if (!on_dismiss_callback_.is_null())
59 on_dismiss_callback_.Run(false); 95 on_dismiss_callback_.Run(false);
60 96
61 RecordPreviewsInfoBarAction(infobar_type_, infobar_dismissed_action_); 97 RecordPreviewsInfoBarAction(previews_type_, infobar_dismissed_action_);
62 } 98 }
63 99
64 // static 100 // static
65 void PreviewsInfoBarDelegate::Create( 101 void PreviewsInfoBarDelegate::Create(
66 content::WebContents* web_contents, 102 content::WebContents* web_contents,
67 PreviewsInfoBarType infobar_type, 103 previews::PreviewsType previews_type,
68 bool is_data_saver_user, 104 bool is_data_saver_user,
69 const OnDismissPreviewsInfobarCallback& on_dismiss_callback) { 105 const OnDismissPreviewsInfobarCallback& on_dismiss_callback) {
70 PreviewsInfoBarTabHelper* infobar_tab_helper = 106 PreviewsInfoBarTabHelper* infobar_tab_helper =
71 PreviewsInfoBarTabHelper::FromWebContents(web_contents); 107 PreviewsInfoBarTabHelper::FromWebContents(web_contents);
72 InfoBarService* infobar_service = 108 InfoBarService* infobar_service =
73 InfoBarService::FromWebContents(web_contents); 109 InfoBarService::FromWebContents(web_contents);
74 110
75 // The WebContents may not have TabHelpers set. If TabHelpers are not set, 111 // The WebContents may not have TabHelpers set. If TabHelpers are not set,
76 // don't show Previews infobars. 112 // don't show Previews infobars.
77 if (!infobar_tab_helper || !infobar_service) 113 if (!infobar_tab_helper || !infobar_service)
78 return; 114 return;
79 if (infobar_tab_helper->displayed_preview_infobar()) 115 if (infobar_tab_helper->displayed_preview_infobar())
80 return; 116 return;
81 117
82 std::unique_ptr<PreviewsInfoBarDelegate> delegate(new PreviewsInfoBarDelegate( 118 std::unique_ptr<PreviewsInfoBarDelegate> delegate(new PreviewsInfoBarDelegate(
83 web_contents, infobar_type, is_data_saver_user, on_dismiss_callback)); 119 web_contents, previews_type, is_data_saver_user, on_dismiss_callback));
84 120
85 #if defined(OS_ANDROID) 121 #if defined(OS_ANDROID)
86 std::unique_ptr<infobars::InfoBar> infobar_ptr( 122 std::unique_ptr<infobars::InfoBar> infobar_ptr(
87 PreviewsInfoBar::CreateInfoBar(infobar_service, std::move(delegate))); 123 PreviewsInfoBar::CreateInfoBar(infobar_service, std::move(delegate)));
88 #else 124 #else
89 std::unique_ptr<infobars::InfoBar> infobar_ptr( 125 std::unique_ptr<infobars::InfoBar> infobar_ptr(
90 infobar_service->CreateConfirmInfoBar(std::move(delegate))); 126 infobar_service->CreateConfirmInfoBar(std::move(delegate)));
91 #endif 127 #endif
92 128
93 infobars::InfoBar* infobar = 129 infobars::InfoBar* infobar =
94 infobar_service->AddInfoBar(std::move(infobar_ptr)); 130 infobar_service->AddInfoBar(std::move(infobar_ptr));
95 131
96 if (infobar && (infobar_type == LITE_PAGE || infobar_type == LOFI)) { 132 if (infobar && (previews_type == previews::PreviewsType::LITE_PAGE ||
133 previews_type == previews::PreviewsType::LOFI)) {
97 auto* data_reduction_proxy_settings = 134 auto* data_reduction_proxy_settings =
98 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( 135 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
99 web_contents->GetBrowserContext()); 136 web_contents->GetBrowserContext());
100 data_reduction_proxy_settings->IncrementLoFiUIShown(); 137 data_reduction_proxy_settings->IncrementLoFiUIShown();
101 } 138 }
102 139
103 RecordPreviewsInfoBarAction(infobar_type, INFOBAR_SHOWN); 140 RecordPreviewsInfoBarAction(previews_type, INFOBAR_SHOWN);
104 infobar_tab_helper->set_displayed_preview_infobar(true); 141 infobar_tab_helper->set_displayed_preview_infobar(true);
105 } 142 }
106 143
107 PreviewsInfoBarDelegate::PreviewsInfoBarDelegate( 144 PreviewsInfoBarDelegate::PreviewsInfoBarDelegate(
108 content::WebContents* web_contents, 145 content::WebContents* web_contents,
109 PreviewsInfoBarType infobar_type, 146 previews::PreviewsType previews_type,
110 bool is_data_saver_user, 147 bool is_data_saver_user,
111 const OnDismissPreviewsInfobarCallback& on_dismiss_callback) 148 const OnDismissPreviewsInfobarCallback& on_dismiss_callback)
112 : ConfirmInfoBarDelegate(), 149 : ConfirmInfoBarDelegate(),
113 infobar_type_(infobar_type), 150 previews_type_(previews_type),
114 infobar_dismissed_action_(INFOBAR_DISMISSED_BY_TAB_CLOSURE), 151 infobar_dismissed_action_(INFOBAR_DISMISSED_BY_TAB_CLOSURE),
115 message_text_(l10n_util::GetStringUTF16( 152 message_text_(l10n_util::GetStringUTF16(
116 is_data_saver_user ? IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE 153 is_data_saver_user ? IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE
117 : IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE)), 154 : IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE)),
118 on_dismiss_callback_(on_dismiss_callback) {} 155 on_dismiss_callback_(on_dismiss_callback) {}
119 156
120 infobars::InfoBarDelegate::InfoBarIdentifier 157 infobars::InfoBarDelegate::InfoBarIdentifier
121 PreviewsInfoBarDelegate::GetIdentifier() const { 158 PreviewsInfoBarDelegate::GetIdentifier() const {
122 return DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE; 159 return DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE;
123 } 160 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 192 }
156 193
157 bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { 194 bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
158 infobar_dismissed_action_ = INFOBAR_LOAD_ORIGINAL_CLICKED; 195 infobar_dismissed_action_ = INFOBAR_LOAD_ORIGINAL_CLICKED;
159 if (!on_dismiss_callback_.is_null()) 196 if (!on_dismiss_callback_.is_null())
160 on_dismiss_callback_.Run(true); 197 on_dismiss_callback_.Run(true);
161 on_dismiss_callback_.Reset(); 198 on_dismiss_callback_.Reset();
162 199
163 content::WebContents* web_contents = 200 content::WebContents* web_contents =
164 InfoBarService::WebContentsFromInfoBar(infobar()); 201 InfoBarService::WebContentsFromInfoBar(infobar());
165 if (infobar_type_ == LITE_PAGE || infobar_type_ == LOFI) {
166 auto* data_reduction_proxy_settings =
167 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
168 web_contents->GetBrowserContext());
169 if (!data_reduction_proxy::params::IsBlackListEnabledForServerPreviews())
170 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages();
171 PreviewsInfoBarTabHelper* infobar_tab_helper =
172 PreviewsInfoBarTabHelper::FromWebContents(web_contents);
173 if (infobar_tab_helper &&
174 infobar_tab_helper->committed_data_saver_navigation_id()) {
175 data_reduction_proxy_settings->data_reduction_proxy_service()
176 ->pingback_client()
177 ->AddOptOut(
178 infobar_tab_helper->committed_data_saver_navigation_id().value());
179 }
180 202
181 if (infobar_type_ == LITE_PAGE) 203 ReportPingbackInformation(web_contents);
182 web_contents->GetController().Reload( 204
183 content::ReloadType::DISABLE_LOFI_MODE, true); 205 if ((previews_type_ == previews::PreviewsType::LITE_PAGE ||
184 else if (infobar_type_ == LOFI) 206 previews_type_ == previews::PreviewsType::LOFI) &&
185 web_contents->ReloadLoFiImages(); 207 !data_reduction_proxy::params::IsBlackListEnabledForServerPreviews()) {
186 } else if (infobar_type_ == OFFLINE) { 208 IncrementDataReductionProxyPrefs(web_contents);
187 // Prevent LoFi and lite page modes from showing after reload.
188 // TODO(ryansturm): rename DISABLE_LOFI_MODE to DISABLE_PREVIEWS.
189 // crbug.com/707272
190 web_contents->GetController().Reload(content::ReloadType::DISABLE_LOFI_MODE,
191 true);
192 } 209 }
193 210
211 ReloadWithoutPreviews(previews_type_, web_contents);
212
194 return true; 213 return true;
195 } 214 }
196 215
197 base::string16 PreviewsInfoBarDelegate::GetTimestampText() const { 216 base::string16 PreviewsInfoBarDelegate::GetTimestampText() const {
198 return base::string16(); 217 return base::string16();
199 } 218 }
OLDNEW
« no previous file with comments | « chrome/browser/previews/previews_infobar_delegate.h ('k') | chrome/browser/previews/previews_infobar_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698