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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/previews/previews_infobar_delegate.cc
diff --git a/chrome/browser/previews/previews_infobar_delegate.cc b/chrome/browser/previews/previews_infobar_delegate.cc
index d4eb931215f6f483cf28aac1e5eeea3a0b87b59c..e5947ca3c35ad4baeb0f3003794dd1bc6d61e27d 100644
--- a/chrome/browser/previews/previews_infobar_delegate.cc
+++ b/chrome/browser/previews/previews_infobar_delegate.cc
@@ -4,7 +4,7 @@
#include "chrome/browser/previews/previews_infobar_delegate.h"
-#include "base/metrics/histogram_macros.h"
+#include "base/metrics/histogram.h"
#include "base/optional.h"
#include "chrome/browser/android/android_theme_resources.h"
#include "chrome/browser/infobars/infobar_service.h"
@@ -26,29 +26,65 @@
namespace {
-// Key of the UMA Previews.InfoBarAction.LoFi histogram.
-const char kUMAPreviewsInfoBarActionLoFi[] = "Previews.InfoBarAction.LoFi";
+void RecordPreviewsInfoBarAction(
+ previews::PreviewsType previews_type,
+ PreviewsInfoBarDelegate::PreviewsInfoBarAction action) {
+ int32_t max_limit =
+ static_cast<int32_t>(PreviewsInfoBarDelegate::INFOBAR_INDEX_BOUNDARY);
+ base::LinearHistogram::FactoryGet(
+ base::StringPrintf("Previews.InfoBarAction.%s",
+ GetStringNameForType(previews_type).c_str()),
+ 1, max_limit, max_limit + 1,
+ base::HistogramBase::kUmaTargetedHistogramFlag)
+ ->Add(static_cast<int32_t>(action));
+}
-// Key of the UMA Previews.InfoBarAction.Offline histogram.
-const char kUMAPreviewsInfoBarActionOffline[] =
- "Previews.InfoBarAction.Offline";
+// Sends opt out information to the pingback service based on a key value in the
+// infobar tab helper. Sending this information in the case of a navigation that
+// should not send a pingback (or is not a server preview) will not alter the
+// pingback.
+void ReportPingbackInformation(content::WebContents* web_contents) {
+ auto* data_reduction_proxy_settings =
+ DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
+ web_contents->GetBrowserContext());
+ PreviewsInfoBarTabHelper* infobar_tab_helper =
+ PreviewsInfoBarTabHelper::FromWebContents(web_contents);
+ if (infobar_tab_helper &&
+ infobar_tab_helper->committed_data_saver_navigation_id()) {
+ data_reduction_proxy_settings->data_reduction_proxy_service()
+ ->pingback_client()
+ ->AddOptOut(
+ infobar_tab_helper->committed_data_saver_navigation_id().value());
+ }
+}
-// Key of the UMA Previews.InfoBarAction.LitePage histogram.
-const char kUMAPreviewsInfoBarActionLitePage[] =
- "Previews.InfoBarAction.LitePage";
+// Increments the prefs-based opt out information for data reduction proxy when
+// the user is not already transitioned to the PreviewsBlackList.
+void IncrementDataReductionProxyPrefs(content::WebContents* web_contents) {
+ auto* data_reduction_proxy_settings =
+ DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
+ web_contents->GetBrowserContext());
+ data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages();
+}
-void RecordPreviewsInfoBarAction(
- PreviewsInfoBarDelegate::PreviewsInfoBarType infobar_type,
- PreviewsInfoBarDelegate::PreviewsInfoBarAction action) {
- if (infobar_type == PreviewsInfoBarDelegate::LOFI) {
- UMA_HISTOGRAM_ENUMERATION(kUMAPreviewsInfoBarActionLoFi, action,
- PreviewsInfoBarDelegate::INFOBAR_INDEX_BOUNDARY);
- } else if (infobar_type == PreviewsInfoBarDelegate::LITE_PAGE) {
- UMA_HISTOGRAM_ENUMERATION(kUMAPreviewsInfoBarActionLitePage, action,
- PreviewsInfoBarDelegate::INFOBAR_INDEX_BOUNDARY);
- } else if (infobar_type == PreviewsInfoBarDelegate::OFFLINE) {
- UMA_HISTOGRAM_ENUMERATION(kUMAPreviewsInfoBarActionOffline, action,
- PreviewsInfoBarDelegate::INFOBAR_INDEX_BOUNDARY);
+// Reloads the content of the page without previews.
+void ReloadWithoutPreviews(previews::PreviewsType previews_type,
+ content::WebContents* web_contents) {
+ switch (previews_type) {
+ case previews::PreviewsType::LITE_PAGE:
+ case previews::PreviewsType::OFFLINE:
+ // Prevent LoFi and lite page modes from showing after reload.
+ // TODO(ryansturm): rename DISABLE_LOFI_MODE to DISABLE_PREVIEWS.
+ // crbug.com/707272
+ web_contents->GetController().Reload(
+ content::ReloadType::DISABLE_LOFI_MODE, true);
+ break;
+ case previews::PreviewsType::LOFI:
+ web_contents->ReloadLoFiImages();
+ break;
+ case previews::PreviewsType::NONE:
+ case previews::PreviewsType::LAST:
+ break;
}
}
@@ -58,13 +94,13 @@ PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() {
if (!on_dismiss_callback_.is_null())
on_dismiss_callback_.Run(false);
- RecordPreviewsInfoBarAction(infobar_type_, infobar_dismissed_action_);
+ RecordPreviewsInfoBarAction(previews_type_, infobar_dismissed_action_);
}
// static
void PreviewsInfoBarDelegate::Create(
content::WebContents* web_contents,
- PreviewsInfoBarType infobar_type,
+ previews::PreviewsType previews_type,
bool is_data_saver_user,
const OnDismissPreviewsInfobarCallback& on_dismiss_callback) {
PreviewsInfoBarTabHelper* infobar_tab_helper =
@@ -80,7 +116,7 @@ void PreviewsInfoBarDelegate::Create(
return;
std::unique_ptr<PreviewsInfoBarDelegate> delegate(new PreviewsInfoBarDelegate(
- web_contents, infobar_type, is_data_saver_user, on_dismiss_callback));
+ web_contents, previews_type, is_data_saver_user, on_dismiss_callback));
#if defined(OS_ANDROID)
std::unique_ptr<infobars::InfoBar> infobar_ptr(
@@ -93,24 +129,25 @@ void PreviewsInfoBarDelegate::Create(
infobars::InfoBar* infobar =
infobar_service->AddInfoBar(std::move(infobar_ptr));
- if (infobar && (infobar_type == LITE_PAGE || infobar_type == LOFI)) {
+ if (infobar && (previews_type == previews::PreviewsType::LITE_PAGE ||
+ previews_type == previews::PreviewsType::LOFI)) {
auto* data_reduction_proxy_settings =
DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
web_contents->GetBrowserContext());
data_reduction_proxy_settings->IncrementLoFiUIShown();
}
- RecordPreviewsInfoBarAction(infobar_type, INFOBAR_SHOWN);
+ RecordPreviewsInfoBarAction(previews_type, INFOBAR_SHOWN);
infobar_tab_helper->set_displayed_preview_infobar(true);
}
PreviewsInfoBarDelegate::PreviewsInfoBarDelegate(
content::WebContents* web_contents,
- PreviewsInfoBarType infobar_type,
+ previews::PreviewsType previews_type,
bool is_data_saver_user,
const OnDismissPreviewsInfobarCallback& on_dismiss_callback)
: ConfirmInfoBarDelegate(),
- infobar_type_(infobar_type),
+ previews_type_(previews_type),
infobar_dismissed_action_(INFOBAR_DISMISSED_BY_TAB_CLOSURE),
message_text_(l10n_util::GetStringUTF16(
is_data_saver_user ? IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE
@@ -162,35 +199,17 @@ bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
content::WebContents* web_contents =
InfoBarService::WebContentsFromInfoBar(infobar());
- if (infobar_type_ == LITE_PAGE || infobar_type_ == LOFI) {
- auto* data_reduction_proxy_settings =
- DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
- web_contents->GetBrowserContext());
- if (!data_reduction_proxy::params::IsBlackListEnabledForServerPreviews())
- data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages();
- PreviewsInfoBarTabHelper* infobar_tab_helper =
- PreviewsInfoBarTabHelper::FromWebContents(web_contents);
- if (infobar_tab_helper &&
- infobar_tab_helper->committed_data_saver_navigation_id()) {
- data_reduction_proxy_settings->data_reduction_proxy_service()
- ->pingback_client()
- ->AddOptOut(
- infobar_tab_helper->committed_data_saver_navigation_id().value());
- }
-
- if (infobar_type_ == LITE_PAGE)
- web_contents->GetController().Reload(
- content::ReloadType::DISABLE_LOFI_MODE, true);
- else if (infobar_type_ == LOFI)
- web_contents->ReloadLoFiImages();
- } else if (infobar_type_ == OFFLINE) {
- // Prevent LoFi and lite page modes from showing after reload.
- // TODO(ryansturm): rename DISABLE_LOFI_MODE to DISABLE_PREVIEWS.
- // crbug.com/707272
- web_contents->GetController().Reload(content::ReloadType::DISABLE_LOFI_MODE,
- true);
+
+ ReportPingbackInformation(web_contents);
+
+ if ((previews_type_ == previews::PreviewsType::LITE_PAGE ||
+ previews_type_ == previews::PreviewsType::LOFI) &&
+ !data_reduction_proxy::params::IsBlackListEnabledForServerPreviews()) {
+ IncrementDataReductionProxyPrefs(web_contents);
}
+ ReloadWithoutPreviews(previews_type_, web_contents);
+
return true;
}
« 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