OLD | NEW |
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/optional.h" | 11 #include "base/optional.h" |
11 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/android/android_theme_resources.h" | 15 #include "chrome/browser/android/android_theme_resources.h" |
15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/infobars/infobar_service.h" | 17 #include "chrome/browser/infobars/infobar_service.h" |
17 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 18 #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" | 19 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" |
19 #include "chrome/browser/previews/previews_infobar_tab_helper.h" | 20 #include "chrome/browser/previews/previews_infobar_tab_helper.h" |
20 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.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_ping
back_client.h" |
22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv
ice.h" | 23 #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" | 24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" |
24 #include "components/infobars/core/infobar.h" | 25 #include "components/infobars/core/infobar.h" |
25 #include "components/network_time/network_time_tracker.h" | 26 #include "components/network_time/network_time_tracker.h" |
26 #include "components/previews/core/previews_features.h" | 27 #include "components/previews/core/previews_features.h" |
27 #include "content/public/browser/render_frame_host.h" | 28 #include "content/public/browser/render_frame_host.h" |
28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
29 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
30 | 31 |
31 #if defined(OS_ANDROID) | 32 #if defined(OS_ANDROID) |
32 #include "chrome/browser/ui/android/infobars/previews_infobar.h" | 33 #include "chrome/browser/ui/android/infobars/previews_infobar.h" |
33 #endif | 34 #endif |
34 | 35 |
35 namespace { | 36 namespace { |
36 | 37 |
| 38 const char kMinStalenessParamName[] = "min_staleness_in_minutes"; |
| 39 const char kMaxStalenessParamName[] = "max_staleness_in_minutes"; |
| 40 const int kMinStalenessParamDefaultValue = 2; |
| 41 const int kMaxStalenessParamDefaultValue = 1440; |
| 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) |
47 ->Add(static_cast<int32_t>(action)); | 53 ->Add(static_cast<int32_t>(action)); |
48 } | 54 } |
49 | 55 |
| 56 void RecordStaleness(PreviewsInfoBarDelegate::PreviewsInfoBarTimestamp value) { |
| 57 UMA_HISTOGRAM_ENUMERATION("Previews.InfoBarTimestamp", value, |
| 58 PreviewsInfoBarDelegate::TIMESTAMP_INDEX_BOUNDARY); |
| 59 } |
| 60 |
50 // Sends opt out information to the pingback service based on a key value in the | 61 // Sends opt out information to the pingback service based on a key value in the |
51 // infobar tab helper. Sending this information in the case of a navigation that | 62 // infobar tab helper. Sending this information in the case of a navigation that |
52 // should not send a pingback (or is not a server preview) will not alter the | 63 // should not send a pingback (or is not a server preview) will not alter the |
53 // pingback. | 64 // pingback. |
54 void ReportPingbackInformation(content::WebContents* web_contents) { | 65 void ReportPingbackInformation(content::WebContents* web_contents) { |
55 auto* data_reduction_proxy_settings = | 66 auto* data_reduction_proxy_settings = |
56 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 67 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
57 web_contents->GetBrowserContext()); | 68 web_contents->GetBrowserContext()); |
58 PreviewsInfoBarTabHelper* infobar_tab_helper = | 69 PreviewsInfoBarTabHelper* infobar_tab_helper = |
59 PreviewsInfoBarTabHelper::FromWebContents(web_contents); | 70 PreviewsInfoBarTabHelper::FromWebContents(web_contents); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 249 |
239 base::string16 PreviewsInfoBarDelegate::GetTimestampText() const { | 250 base::string16 PreviewsInfoBarDelegate::GetTimestampText() const { |
240 if (previews_freshness_.is_null()) | 251 if (previews_freshness_.is_null()) |
241 return base::string16(); | 252 return base::string16(); |
242 if (!base::FeatureList::IsEnabled( | 253 if (!base::FeatureList::IsEnabled( |
243 previews::features::kStalePreviewsTimestamp)) { | 254 previews::features::kStalePreviewsTimestamp)) { |
244 return base::string16(); | 255 return base::string16(); |
245 } | 256 } |
246 | 257 |
247 int min_staleness_in_minutes = base::GetFieldTrialParamByFeatureAsInt( | 258 int min_staleness_in_minutes = base::GetFieldTrialParamByFeatureAsInt( |
248 previews::features::kStalePreviewsTimestamp, "min_staleness_in_minutes", | 259 previews::features::kStalePreviewsTimestamp, kMinStalenessParamName, |
249 0); | 260 kMinStalenessParamDefaultValue); |
250 int max_staleness_in_minutes = base::GetFieldTrialParamByFeatureAsInt( | 261 int max_staleness_in_minutes = base::GetFieldTrialParamByFeatureAsInt( |
251 previews::features::kStalePreviewsTimestamp, "max_staleness_in_minutes", | 262 previews::features::kStalePreviewsTimestamp, kMaxStalenessParamName, |
252 0); | 263 kMaxStalenessParamDefaultValue); |
253 | 264 |
254 if (min_staleness_in_minutes == 0 || max_staleness_in_minutes == 0) | 265 if (min_staleness_in_minutes <= 0 || max_staleness_in_minutes <= 0) { |
| 266 NOTREACHED(); |
255 return base::string16(); | 267 return base::string16(); |
| 268 } |
256 | 269 |
257 base::Time network_time; | 270 base::Time network_time; |
258 if (g_browser_process->network_time_tracker()->GetNetworkTime(&network_time, | 271 if (g_browser_process->network_time_tracker()->GetNetworkTime(&network_time, |
259 nullptr) != | 272 nullptr) != |
260 network_time::NetworkTimeTracker::NETWORK_TIME_AVAILABLE) { | 273 network_time::NetworkTimeTracker::NETWORK_TIME_AVAILABLE) { |
261 // When network time has not been initialized yet, simply rely on the | 274 // When network time has not been initialized yet, simply rely on the |
262 // machine's current time. | 275 // machine's current time. |
263 network_time = base::Time::Now(); | 276 network_time = base::Time::Now(); |
264 } | 277 } |
265 | 278 |
| 279 if (network_time < previews_freshness_) { |
| 280 RecordStaleness(TIMESTAMP_NOT_SHOWN_STALENESS_NEGATIVE); |
| 281 return base::string16(); |
| 282 } |
| 283 |
266 int staleness_in_minutes = (network_time - previews_freshness_).InMinutes(); | 284 int staleness_in_minutes = (network_time - previews_freshness_).InMinutes(); |
267 // TODO(megjablon): record metrics for out of bounds staleness. | 285 if (staleness_in_minutes < min_staleness_in_minutes) { |
268 if (staleness_in_minutes < min_staleness_in_minutes) | 286 RecordStaleness(TIMESTAMP_NOT_SHOWN_PREVIEW_NOT_STALE); |
269 return base::string16(); | 287 return base::string16(); |
270 if (staleness_in_minutes > max_staleness_in_minutes) | 288 } |
| 289 if (staleness_in_minutes > max_staleness_in_minutes) { |
| 290 RecordStaleness(TIMESTAMP_NOT_SHOWN_STALENESS_GREATER_THAN_MAX); |
271 return base::string16(); | 291 return base::string16(); |
| 292 } |
| 293 |
| 294 RecordStaleness(TIMESTAMP_SHOWN); |
272 | 295 |
273 if (staleness_in_minutes < 60) { | 296 if (staleness_in_minutes < 60) { |
274 return l10n_util::GetStringFUTF16( | 297 return l10n_util::GetStringFUTF16( |
275 IDS_PREVIEWS_INFOBAR_TIMESTAMP_MINUTES, | 298 IDS_PREVIEWS_INFOBAR_TIMESTAMP_MINUTES, |
276 base::IntToString16(staleness_in_minutes)); | 299 base::IntToString16(staleness_in_minutes)); |
277 } else if (staleness_in_minutes < 120) { | 300 } else if (staleness_in_minutes < 120) { |
278 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_ONE_HOUR); | 301 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_ONE_HOUR); |
279 } else { | 302 } else { |
280 return l10n_util::GetStringFUTF16( | 303 return l10n_util::GetStringFUTF16( |
281 IDS_PREVIEWS_INFOBAR_TIMESTAMP_HOURS, | 304 IDS_PREVIEWS_INFOBAR_TIMESTAMP_HOURS, |
282 base::IntToString16(staleness_in_minutes / 60)); | 305 base::IntToString16(staleness_in_minutes / 60)); |
283 } | 306 } |
284 } | 307 } |
OLD | NEW |