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

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

Issue 2952343004: Adding previews information to PLM UKM (Closed)
Patch Set: comment on BroadcastEventToObservers Created 3 years, 5 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/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "base/optional.h" 11 #include "base/optional.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/android/android_theme_resources.h" 15 #include "chrome/browser/android/android_theme_resources.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/infobars/infobar_service.h" 17 #include "chrome/browser/infobars/infobar_service.h"
18 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" 18 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
19 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" 19 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h"
20 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h"
20 #include "chrome/browser/previews/previews_infobar_tab_helper.h" 21 #include "chrome/browser/previews/previews_infobar_tab_helper.h"
21 #include "chrome/grit/generated_resources.h" 22 #include "chrome/grit/generated_resources.h"
22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping back_client.h" 23 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping back_client.h"
23 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h" 24 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h"
24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" 25 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h"
25 #include "components/infobars/core/infobar.h" 26 #include "components/infobars/core/infobar.h"
26 #include "components/network_time/network_time_tracker.h" 27 #include "components/network_time/network_time_tracker.h"
27 #include "components/previews/core/previews_features.h" 28 #include "components/previews/core/previews_features.h"
28 #include "content/public/browser/render_frame_host.h" 29 #include "content/public/browser/render_frame_host.h"
29 #include "content/public/browser/web_contents.h" 30 #include "content/public/browser/web_contents.h"
30 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
31 32
32 #if defined(OS_ANDROID) 33 #if defined(OS_ANDROID)
33 #include "chrome/browser/ui/android/infobars/previews_infobar.h" 34 #include "chrome/browser/ui/android/infobars/previews_infobar.h"
34 #endif 35 #endif
35 36
36 namespace { 37 namespace {
37 38
39 const void* const kOptOutEventKey = 0;
40
38 const char kMinStalenessParamName[] = "min_staleness_in_minutes"; 41 const char kMinStalenessParamName[] = "min_staleness_in_minutes";
39 const char kMaxStalenessParamName[] = "max_staleness_in_minutes"; 42 const char kMaxStalenessParamName[] = "max_staleness_in_minutes";
40 const int kMinStalenessParamDefaultValue = 2; 43 const int kMinStalenessParamDefaultValue = 2;
41 const int kMaxStalenessParamDefaultValue = 1440; 44 const int kMaxStalenessParamDefaultValue = 1440;
42 45
43 void RecordPreviewsInfoBarAction( 46 void RecordPreviewsInfoBarAction(
44 previews::PreviewsType previews_type, 47 previews::PreviewsType previews_type,
45 PreviewsInfoBarDelegate::PreviewsInfoBarAction action) { 48 PreviewsInfoBarDelegate::PreviewsInfoBarAction action) {
46 int32_t max_limit = 49 int32_t max_limit =
47 static_cast<int32_t>(PreviewsInfoBarDelegate::INFOBAR_INDEX_BOUNDARY); 50 static_cast<int32_t>(PreviewsInfoBarDelegate::INFOBAR_INDEX_BOUNDARY);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 break; 103 break;
101 case previews::PreviewsType::LOFI: 104 case previews::PreviewsType::LOFI:
102 web_contents->ReloadLoFiImages(); 105 web_contents->ReloadLoFiImages();
103 break; 106 break;
104 case previews::PreviewsType::NONE: 107 case previews::PreviewsType::NONE:
105 case previews::PreviewsType::LAST: 108 case previews::PreviewsType::LAST:
106 break; 109 break;
107 } 110 }
108 } 111 }
109 112
113 void NotifyPLMOfOptOut(content::WebContents* web_contents) {
114 page_load_metrics::MetricsWebContentsObserver* metrics_web_contents_observer =
115 page_load_metrics::MetricsWebContentsObserver::FromWebContents(
116 web_contents);
117 if (!metrics_web_contents_observer)
118 return;
119
120 metrics_web_contents_observer->BroadcastEventToObservers(
121 PreviewsInfoBarDelegate::OptOutEventKey());
dougarnett 2017/07/13 16:02:18 Should we be able to correlate this event somehow
RyanSturm 2017/07/17 18:48:30 That detection is done in the observer itself. Sin
dougarnett 2017/07/17 20:41:21 I'm asking a question not (yet) asking for a chang
122 }
123
110 } // namespace 124 } // namespace
111 125
112 PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() { 126 PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() {
113 if (!on_dismiss_callback_.is_null()) 127 if (!on_dismiss_callback_.is_null())
114 on_dismiss_callback_.Run(false); 128 on_dismiss_callback_.Run(false);
115 129
116 RecordPreviewsInfoBarAction(previews_type_, infobar_dismissed_action_); 130 RecordPreviewsInfoBarAction(previews_type_, infobar_dismissed_action_);
117 } 131 }
118 132
119 // static 133 // static
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 infobar_dismissed_action_ = INFOBAR_LOAD_ORIGINAL_CLICKED; 247 infobar_dismissed_action_ = INFOBAR_LOAD_ORIGINAL_CLICKED;
234 if (!on_dismiss_callback_.is_null()) 248 if (!on_dismiss_callback_.is_null())
235 on_dismiss_callback_.Run(true); 249 on_dismiss_callback_.Run(true);
236 on_dismiss_callback_.Reset(); 250 on_dismiss_callback_.Reset();
237 251
238 content::WebContents* web_contents = 252 content::WebContents* web_contents =
239 InfoBarService::WebContentsFromInfoBar(infobar()); 253 InfoBarService::WebContentsFromInfoBar(infobar());
240 254
241 ReportPingbackInformation(web_contents); 255 ReportPingbackInformation(web_contents);
242 256
257 NotifyPLMOfOptOut(web_contents);
tbansal1 2017/07/12 21:58:45 Does this class live on UI thread or IO thread?
RyanSturm 2017/07/17 18:48:30 It's all UI thread. I renamed this to "InformPLMOf
258
243 if ((previews_type_ == previews::PreviewsType::LITE_PAGE || 259 if ((previews_type_ == previews::PreviewsType::LITE_PAGE ||
244 previews_type_ == previews::PreviewsType::LOFI) && 260 previews_type_ == previews::PreviewsType::LOFI) &&
245 !data_reduction_proxy::params::IsBlackListEnabledForServerPreviews()) { 261 !data_reduction_proxy::params::IsBlackListEnabledForServerPreviews()) {
246 IncrementDataReductionProxyPrefs(web_contents); 262 IncrementDataReductionProxyPrefs(web_contents);
247 } 263 }
248 264
249 ReloadWithoutPreviews(previews_type_, web_contents); 265 ReloadWithoutPreviews(previews_type_, web_contents);
250 266
251 return true; 267 return true;
252 } 268 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 IDS_PREVIEWS_INFOBAR_TIMESTAMP_MINUTES, 327 IDS_PREVIEWS_INFOBAR_TIMESTAMP_MINUTES,
312 base::IntToString16(staleness_in_minutes)); 328 base::IntToString16(staleness_in_minutes));
313 } else if (staleness_in_minutes < 120) { 329 } else if (staleness_in_minutes < 120) {
314 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_ONE_HOUR); 330 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_ONE_HOUR);
315 } else { 331 } else {
316 return l10n_util::GetStringFUTF16( 332 return l10n_util::GetStringFUTF16(
317 IDS_PREVIEWS_INFOBAR_TIMESTAMP_HOURS, 333 IDS_PREVIEWS_INFOBAR_TIMESTAMP_HOURS,
318 base::IntToString16(staleness_in_minutes / 60)); 334 base::IntToString16(staleness_in_minutes / 60));
319 } 335 }
320 } 336 }
337
338 // static
339 const void* PreviewsInfoBarDelegate::OptOutEventKey() {
340 return &kOptOutEventKey;
341 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698