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

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

Issue 2875993002: Converging the two previews type enums (Closed)
Patch Set: header change 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);
megjablon 2017/05/11 23:49:45 Can we just use INFOBAR_INDEX_BOUNDARY without cas
RyanSturm 2017/05/15 16:23:08 I'd rather be explicit about casts from enum to in
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<int>(action));
megjablon 2017/05/11 23:49:45 Does this need to be cast?
RyanSturm 2017/05/15 16:23:08 Same as above comment. I am changing it to int32_t
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 if (data_reduction_proxy::params::IsBlackListEnabledForServerPreviews())
65 return;
66 auto* data_reduction_proxy_settings =
67 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
68 web_contents->GetBrowserContext());
69 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages();
70 }
71
72 // Reloads the content of the page without previews.
73 void ReloadWithoutPreviews(previews::PreviewsType previews_type,
74 content::WebContents* web_contents) {
75 switch (previews_type) {
76 case previews::PreviewsType::LITE_PAGE:
77 case previews::PreviewsType::OFFLINE:
78 // Prevent LoFi and lite page modes from showing after reload.
79 // TODO(ryansturm): rename DISABLE_LOFI_MODE to DISABLE_PREVIEWS.
80 // crbug.com/707272
megjablon 2017/05/11 23:49:45 nit: extra space
RyanSturm 2017/05/15 16:23:08 Done.
81 web_contents->GetController().Reload(
82 content::ReloadType::DISABLE_LOFI_MODE, true);
83 break;
84 case previews::PreviewsType::LOFI:
85 web_contents->ReloadLoFiImages();
86 break;
87 case previews::PreviewsType::NONE:
88 case previews::PreviewsType::LAST:
89 break;
90 }
91 }
92
55 } // namespace 93 } // namespace
56 94
57 PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() { 95 PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() {
58 if (!on_dismiss_callback_.is_null()) 96 if (!on_dismiss_callback_.is_null())
59 on_dismiss_callback_.Run(false); 97 on_dismiss_callback_.Run(false);
60 98
61 RecordPreviewsInfoBarAction(infobar_type_, infobar_dismissed_action_); 99 RecordPreviewsInfoBarAction(previews_type_, infobar_dismissed_action_);
62 } 100 }
63 101
64 // static 102 // static
65 void PreviewsInfoBarDelegate::Create( 103 void PreviewsInfoBarDelegate::Create(
66 content::WebContents* web_contents, 104 content::WebContents* web_contents,
67 PreviewsInfoBarType infobar_type, 105 previews::PreviewsType previews_type,
68 bool is_data_saver_user, 106 bool is_data_saver_user,
69 const OnDismissPreviewsInfobarCallback& on_dismiss_callback) { 107 const OnDismissPreviewsInfobarCallback& on_dismiss_callback) {
70 PreviewsInfoBarTabHelper* infobar_tab_helper = 108 PreviewsInfoBarTabHelper* infobar_tab_helper =
71 PreviewsInfoBarTabHelper::FromWebContents(web_contents); 109 PreviewsInfoBarTabHelper::FromWebContents(web_contents);
72 InfoBarService* infobar_service = 110 InfoBarService* infobar_service =
73 InfoBarService::FromWebContents(web_contents); 111 InfoBarService::FromWebContents(web_contents);
74 112
75 // The WebContents may not have TabHelpers set. If TabHelpers are not set, 113 // The WebContents may not have TabHelpers set. If TabHelpers are not set,
76 // don't show Previews infobars. 114 // don't show Previews infobars.
77 if (!infobar_tab_helper || !infobar_service) 115 if (!infobar_tab_helper || !infobar_service)
78 return; 116 return;
79 if (infobar_tab_helper->displayed_preview_infobar()) 117 if (infobar_tab_helper->displayed_preview_infobar())
80 return; 118 return;
81 119
82 std::unique_ptr<PreviewsInfoBarDelegate> delegate(new PreviewsInfoBarDelegate( 120 std::unique_ptr<PreviewsInfoBarDelegate> delegate(new PreviewsInfoBarDelegate(
83 web_contents, infobar_type, is_data_saver_user, on_dismiss_callback)); 121 web_contents, previews_type, is_data_saver_user, on_dismiss_callback));
84 122
85 #if defined(OS_ANDROID) 123 #if defined(OS_ANDROID)
86 std::unique_ptr<infobars::InfoBar> infobar_ptr( 124 std::unique_ptr<infobars::InfoBar> infobar_ptr(
87 PreviewsInfoBar::CreateInfoBar(infobar_service, std::move(delegate))); 125 PreviewsInfoBar::CreateInfoBar(infobar_service, std::move(delegate)));
88 #else 126 #else
89 std::unique_ptr<infobars::InfoBar> infobar_ptr( 127 std::unique_ptr<infobars::InfoBar> infobar_ptr(
90 infobar_service->CreateConfirmInfoBar(std::move(delegate))); 128 infobar_service->CreateConfirmInfoBar(std::move(delegate)));
91 #endif 129 #endif
92 130
93 infobars::InfoBar* infobar = 131 infobars::InfoBar* infobar =
94 infobar_service->AddInfoBar(std::move(infobar_ptr)); 132 infobar_service->AddInfoBar(std::move(infobar_ptr));
95 133
96 if (infobar && (infobar_type == LITE_PAGE || infobar_type == LOFI)) { 134 if (infobar && (previews_type == previews::PreviewsType::LITE_PAGE ||
135 previews_type == previews::PreviewsType::LOFI)) {
97 auto* data_reduction_proxy_settings = 136 auto* data_reduction_proxy_settings =
98 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( 137 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
99 web_contents->GetBrowserContext()); 138 web_contents->GetBrowserContext());
100 data_reduction_proxy_settings->IncrementLoFiUIShown(); 139 data_reduction_proxy_settings->IncrementLoFiUIShown();
101 } 140 }
102 141
103 RecordPreviewsInfoBarAction(infobar_type, INFOBAR_SHOWN); 142 RecordPreviewsInfoBarAction(previews_type, INFOBAR_SHOWN);
104 infobar_tab_helper->set_displayed_preview_infobar(true); 143 infobar_tab_helper->set_displayed_preview_infobar(true);
105 } 144 }
106 145
107 PreviewsInfoBarDelegate::PreviewsInfoBarDelegate( 146 PreviewsInfoBarDelegate::PreviewsInfoBarDelegate(
108 content::WebContents* web_contents, 147 content::WebContents* web_contents,
109 PreviewsInfoBarType infobar_type, 148 previews::PreviewsType previews_type,
110 bool is_data_saver_user, 149 bool is_data_saver_user,
111 const OnDismissPreviewsInfobarCallback& on_dismiss_callback) 150 const OnDismissPreviewsInfobarCallback& on_dismiss_callback)
112 : ConfirmInfoBarDelegate(), 151 : ConfirmInfoBarDelegate(),
113 infobar_type_(infobar_type), 152 previews_type_(previews_type),
114 infobar_dismissed_action_(INFOBAR_DISMISSED_BY_TAB_CLOSURE), 153 infobar_dismissed_action_(INFOBAR_DISMISSED_BY_TAB_CLOSURE),
115 message_text_(l10n_util::GetStringUTF16( 154 message_text_(l10n_util::GetStringUTF16(
116 is_data_saver_user ? IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE 155 is_data_saver_user ? IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE
117 : IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE)), 156 : IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE)),
118 on_dismiss_callback_(on_dismiss_callback) {} 157 on_dismiss_callback_(on_dismiss_callback) {}
119 158
120 infobars::InfoBarDelegate::InfoBarIdentifier 159 infobars::InfoBarDelegate::InfoBarIdentifier
121 PreviewsInfoBarDelegate::GetIdentifier() const { 160 PreviewsInfoBarDelegate::GetIdentifier() const {
122 return DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE; 161 return DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE;
123 } 162 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 194 }
156 195
157 bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { 196 bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
158 infobar_dismissed_action_ = INFOBAR_LOAD_ORIGINAL_CLICKED; 197 infobar_dismissed_action_ = INFOBAR_LOAD_ORIGINAL_CLICKED;
159 if (!on_dismiss_callback_.is_null()) 198 if (!on_dismiss_callback_.is_null())
160 on_dismiss_callback_.Run(true); 199 on_dismiss_callback_.Run(true);
161 on_dismiss_callback_.Reset(); 200 on_dismiss_callback_.Reset();
162 201
163 content::WebContents* web_contents = 202 content::WebContents* web_contents =
164 InfoBarService::WebContentsFromInfoBar(infobar()); 203 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 204
181 if (infobar_type_ == LITE_PAGE) 205 ReportPingbackInformation(web_contents);
182 web_contents->GetController().Reload( 206
183 content::ReloadType::DISABLE_LOFI_MODE, true); 207 if (previews_type_ == previews::PreviewsType::LITE_PAGE ||
184 else if (infobar_type_ == LOFI) 208 previews_type_ == previews::PreviewsType::LOFI) {
megjablon 2017/05/11 23:49:45 Don't you still want: if (!data_reduction_proxy::
RyanSturm 2017/05/15 16:23:08 Done. IncrementDataReductionProxyPrefs had an ear
185 web_contents->ReloadLoFiImages(); 209 IncrementDataReductionProxyPrefs(web_contents);
186 } else if (infobar_type_ == OFFLINE) {
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 } 210 }
193 211
212 ReloadWithoutPreviews(previews_type_, web_contents);
213
194 return true; 214 return true;
195 } 215 }
196 216
197 base::string16 PreviewsInfoBarDelegate::GetTimestampText() const { 217 base::string16 PreviewsInfoBarDelegate::GetTimestampText() const {
198 return base::string16(); 218 return base::string16();
199 } 219 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698