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

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

Issue 2952343004: Adding previews information to PLM UKM (Closed)
Patch Set: stop observing on background Created 3 years, 6 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/feature_list.h" 7 #include "base/feature_list.h"
8 #include "base/metrics/field_trial_params.h" 8 #include "base/metrics/field_trial_params.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/optional.h" 10 #include "base/optional.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/android/android_theme_resources.h" 14 #include "chrome/browser/android/android_theme_resources.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/infobars/infobar_service.h" 16 #include "chrome/browser/infobars/infobar_service.h"
17 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" 17 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
18 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" 18 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h"
19 #include "chrome/browser/previews/previews_infobar_tab_helper.h" 19 #include "chrome/browser/previews/previews_infobar_tab_helper.h"
20 #include "chrome/grit/generated_resources.h" 20 #include "chrome/grit/generated_resources.h"
21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping back_client.h" 21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping back_client.h"
22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h" 22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h"
23 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" 23 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h"
24 #include "components/infobars/core/infobar.h" 24 #include "components/infobars/core/infobar.h"
25 #include "components/network_time/network_time_tracker.h" 25 #include "components/network_time/network_time_tracker.h"
26 #include "components/previews/core/previews_features.h" 26 #include "components/previews/core/previews_features.h"
27 #include "components/ukm/public/ukm_entry_builder.h"
28 #include "components/ukm/public/ukm_recorder.h"
29 #include "components/ukm/ukm_source.h"
27 #include "content/public/browser/render_frame_host.h" 30 #include "content/public/browser/render_frame_host.h"
28 #include "content/public/browser/web_contents.h" 31 #include "content/public/browser/web_contents.h"
29 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
30 33
31 #if defined(OS_ANDROID) 34 #if defined(OS_ANDROID)
32 #include "chrome/browser/ui/android/infobars/previews_infobar.h" 35 #include "chrome/browser/ui/android/infobars/previews_infobar.h"
33 #endif 36 #endif
34 37
35 namespace { 38 namespace {
36 39
40 const char kPreviewsName[] = "Previews";
41 const char kPreviewsOptOut[] = "opt_out";
42
37 void RecordPreviewsInfoBarAction( 43 void RecordPreviewsInfoBarAction(
38 previews::PreviewsType previews_type, 44 previews::PreviewsType previews_type,
39 PreviewsInfoBarDelegate::PreviewsInfoBarAction action) { 45 PreviewsInfoBarDelegate::PreviewsInfoBarAction action) {
40 int32_t max_limit = 46 int32_t max_limit =
41 static_cast<int32_t>(PreviewsInfoBarDelegate::INFOBAR_INDEX_BOUNDARY); 47 static_cast<int32_t>(PreviewsInfoBarDelegate::INFOBAR_INDEX_BOUNDARY);
42 base::LinearHistogram::FactoryGet( 48 base::LinearHistogram::FactoryGet(
43 base::StringPrintf("Previews.InfoBarAction.%s", 49 base::StringPrintf("Previews.InfoBarAction.%s",
44 GetStringNameForType(previews_type).c_str()), 50 GetStringNameForType(previews_type).c_str()),
45 1, max_limit, max_limit + 1, 51 1, max_limit, max_limit + 1,
46 base::HistogramBase::kUmaTargetedHistogramFlag) 52 base::HistogramBase::kUmaTargetedHistogramFlag)
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 infobar_dismissed_action_ = INFOBAR_LOAD_ORIGINAL_CLICKED; 224 infobar_dismissed_action_ = INFOBAR_LOAD_ORIGINAL_CLICKED;
219 if (!on_dismiss_callback_.is_null()) 225 if (!on_dismiss_callback_.is_null())
220 on_dismiss_callback_.Run(true); 226 on_dismiss_callback_.Run(true);
221 on_dismiss_callback_.Reset(); 227 on_dismiss_callback_.Reset();
222 228
223 content::WebContents* web_contents = 229 content::WebContents* web_contents =
224 InfoBarService::WebContentsFromInfoBar(infobar()); 230 InfoBarService::WebContentsFromInfoBar(infobar());
225 231
226 ReportPingbackInformation(web_contents); 232 ReportPingbackInformation(web_contents);
227 233
234 // TODO(ryansturm): Add support for Offline Previews in PLM UKM.
235 if (previews_type_ != previews::PreviewsType::OFFLINE)
236 RecordUKMOptOut();
237
228 if ((previews_type_ == previews::PreviewsType::LITE_PAGE || 238 if ((previews_type_ == previews::PreviewsType::LITE_PAGE ||
229 previews_type_ == previews::PreviewsType::LOFI) && 239 previews_type_ == previews::PreviewsType::LOFI) &&
230 !data_reduction_proxy::params::IsBlackListEnabledForServerPreviews()) { 240 !data_reduction_proxy::params::IsBlackListEnabledForServerPreviews()) {
231 IncrementDataReductionProxyPrefs(web_contents); 241 IncrementDataReductionProxyPrefs(web_contents);
232 } 242 }
233 243
234 ReloadWithoutPreviews(previews_type_, web_contents); 244 ReloadWithoutPreviews(previews_type_, web_contents);
235 245
236 return true; 246 return true;
237 } 247 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 IDS_PREVIEWS_INFOBAR_TIMESTAMP_MINUTES, 285 IDS_PREVIEWS_INFOBAR_TIMESTAMP_MINUTES,
276 base::IntToString16(staleness_in_minutes)); 286 base::IntToString16(staleness_in_minutes));
277 } else if (staleness_in_minutes < 120) { 287 } else if (staleness_in_minutes < 120) {
278 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_ONE_HOUR); 288 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_ONE_HOUR);
279 } else { 289 } else {
280 return l10n_util::GetStringFUTF16( 290 return l10n_util::GetStringFUTF16(
281 IDS_PREVIEWS_INFOBAR_TIMESTAMP_HOURS, 291 IDS_PREVIEWS_INFOBAR_TIMESTAMP_HOURS,
282 base::IntToString16(staleness_in_minutes / 60)); 292 base::IntToString16(staleness_in_minutes / 60));
283 } 293 }
284 } 294 }
295
296 void PreviewsInfoBarDelegate::RecordUKMOptOut() {
297 content::WebContents* web_contents =
298 InfoBarService::WebContentsFromInfoBar(infobar());
299 PreviewsInfoBarTabHelper* infobar_tab_helper =
300 PreviewsInfoBarTabHelper::FromWebContents(web_contents);
301 if (!infobar_tab_helper || !infobar_tab_helper->source_id()) {
302 return;
303 }
304
305 ukm::UkmRecorder* ukm_recorder = g_browser_process->ukm_recorder();
306 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_recorder->GetEntryBuilder(
307 infobar_tab_helper->source_id().value(), kPreviewsName);
308 builder->AddMetric(kPreviewsOptOut, true);
309 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698