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

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

Issue 2949173002: UMA for the Stale Previews timestamp (Closed)
Patch Set: update tests 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/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"
(...skipping 25 matching lines...) Expand all
45 int32_t max_limit = 46 int32_t max_limit =
46 static_cast<int32_t>(PreviewsInfoBarDelegate::INFOBAR_INDEX_BOUNDARY); 47 static_cast<int32_t>(PreviewsInfoBarDelegate::INFOBAR_INDEX_BOUNDARY);
47 base::LinearHistogram::FactoryGet( 48 base::LinearHistogram::FactoryGet(
48 base::StringPrintf("Previews.InfoBarAction.%s", 49 base::StringPrintf("Previews.InfoBarAction.%s",
49 GetStringNameForType(previews_type).c_str()), 50 GetStringNameForType(previews_type).c_str()),
50 1, max_limit, max_limit + 1, 51 1, max_limit, max_limit + 1,
51 base::HistogramBase::kUmaTargetedHistogramFlag) 52 base::HistogramBase::kUmaTargetedHistogramFlag)
52 ->Add(static_cast<int32_t>(action)); 53 ->Add(static_cast<int32_t>(action));
53 } 54 }
54 55
56 void RecordStaleness(PreviewsInfoBarDelegate::PreviewsInfoBarTimestamp value) {
57 UMA_HISTOGRAM_ENUMERATION("Previews.InfoBarTimestamp", value,
58 PreviewsInfoBarDelegate::TIMESTAMP_INDEX_BOUNDARY);
59 }
60
55 // 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
56 // 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
57 // 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
58 // pingback. 64 // pingback.
59 void ReportPingbackInformation(content::WebContents* web_contents) { 65 void ReportPingbackInformation(content::WebContents* web_contents) {
60 auto* data_reduction_proxy_settings = 66 auto* data_reduction_proxy_settings =
61 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( 67 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
62 web_contents->GetBrowserContext()); 68 web_contents->GetBrowserContext());
63 PreviewsInfoBarTabHelper* infobar_tab_helper = 69 PreviewsInfoBarTabHelper* infobar_tab_helper =
64 PreviewsInfoBarTabHelper::FromWebContents(web_contents); 70 PreviewsInfoBarTabHelper::FromWebContents(web_contents);
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 return base::string16(); 255 return base::string16();
250 } 256 }
251 257
252 int min_staleness_in_minutes = base::GetFieldTrialParamByFeatureAsInt( 258 int min_staleness_in_minutes = base::GetFieldTrialParamByFeatureAsInt(
253 previews::features::kStalePreviewsTimestamp, kMinStalenessParamName, 259 previews::features::kStalePreviewsTimestamp, kMinStalenessParamName,
254 kMinStalenessParamDefaultValue); 260 kMinStalenessParamDefaultValue);
255 int max_staleness_in_minutes = base::GetFieldTrialParamByFeatureAsInt( 261 int max_staleness_in_minutes = base::GetFieldTrialParamByFeatureAsInt(
256 previews::features::kStalePreviewsTimestamp, kMaxStalenessParamName, 262 previews::features::kStalePreviewsTimestamp, kMaxStalenessParamName,
257 kMaxStalenessParamDefaultValue); 263 kMaxStalenessParamDefaultValue);
258 264
259 if (min_staleness_in_minutes <= 0 || max_staleness_in_minutes <= 0) 265 if (min_staleness_in_minutes <= 0 || max_staleness_in_minutes <= 0) {
266 RecordStaleness(TIMESTAMP_NOT_SHOWN_PARAMS_NOT_AVAILABLE);
tbansal1 2017/06/22 21:12:16 Can this be changed to: DCHECK(min_staleness_in_mi
megjablon 2017/06/22 23:40:11 Added NOTREACHED(); since we should still return o
260 return base::string16(); 267 return base::string16();
268 }
261 269
262 base::Time network_time; 270 base::Time network_time;
263 if (g_browser_process->network_time_tracker()->GetNetworkTime(&network_time, 271 if (g_browser_process->network_time_tracker()->GetNetworkTime(&network_time,
264 nullptr) != 272 nullptr) !=
265 network_time::NetworkTimeTracker::NETWORK_TIME_AVAILABLE) { 273 network_time::NetworkTimeTracker::NETWORK_TIME_AVAILABLE) {
266 // 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
267 // machine's current time. 275 // machine's current time.
268 network_time = base::Time::Now(); 276 network_time = base::Time::Now();
tbansal1 2017/06/22 21:12:16 Record separate UMA here? I guess if the time trac
megjablon 2017/06/22 23:40:11 I can add that separately if we decide we need it.
269 } 277 }
270 278
279 if (network_time < previews_freshness_) {
280 RecordStaleness(TIMESTAMP_NOT_SHOWN_STALENESS_NEGATIVE);
281 return base::string16();
282 }
283
271 int staleness_in_minutes = (network_time - previews_freshness_).InMinutes(); 284 int staleness_in_minutes = (network_time - previews_freshness_).InMinutes();
272 // TODO(megjablon): record metrics for out of bounds staleness. 285 if (staleness_in_minutes < min_staleness_in_minutes) {
273 if (staleness_in_minutes < min_staleness_in_minutes) 286 RecordStaleness(TIMESTAMP_NOT_SHOWN_PREVIEW_NOT_STALE);
274 return base::string16(); 287 return base::string16();
275 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);
276 return base::string16(); 291 return base::string16();
292 }
293
294 RecordStaleness(TIMESTAMP_SHOWN);
tbansal1 2017/06/22 21:12:16 Do we want to record exactly which text (among thr
megjablon 2017/06/22 23:40:11 We can, but if we just care about the number of st
277 295
278 if (staleness_in_minutes < 60) { 296 if (staleness_in_minutes < 60) {
279 return l10n_util::GetStringFUTF16( 297 return l10n_util::GetStringFUTF16(
280 IDS_PREVIEWS_INFOBAR_TIMESTAMP_MINUTES, 298 IDS_PREVIEWS_INFOBAR_TIMESTAMP_MINUTES,
281 base::IntToString16(staleness_in_minutes)); 299 base::IntToString16(staleness_in_minutes));
282 } else if (staleness_in_minutes < 120) { 300 } else if (staleness_in_minutes < 120) {
283 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_ONE_HOUR); 301 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_ONE_HOUR);
284 } else { 302 } else {
285 return l10n_util::GetStringFUTF16( 303 return l10n_util::GetStringFUTF16(
286 IDS_PREVIEWS_INFOBAR_TIMESTAMP_HOURS, 304 IDS_PREVIEWS_INFOBAR_TIMESTAMP_HOURS,
287 base::IntToString16(staleness_in_minutes / 60)); 305 base::IntToString16(staleness_in_minutes / 60));
288 } 306 }
289 } 307 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698