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

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

Issue 2947073002: Add chrome://flag to enable the Stale Previews timestamp (Closed)
Patch Set: add default values 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
« no previous file with comments | « chrome/browser/flag_descriptions.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 16 matching lines...) Expand all
27 #include "content/public/browser/render_frame_host.h" 27 #include "content/public/browser/render_frame_host.h"
28 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
29 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
30 30
31 #if defined(OS_ANDROID) 31 #if defined(OS_ANDROID)
32 #include "chrome/browser/ui/android/infobars/previews_infobar.h" 32 #include "chrome/browser/ui/android/infobars/previews_infobar.h"
33 #endif 33 #endif
34 34
35 namespace { 35 namespace {
36 36
37 const char kMinStalenessParamName[] = "min_staleness_in_minutes";
38 const char kMaxStalenessParamName[] = "max_staleness_in_minutes";
39 const int kMinStalenessParamDefaultValue = 2;
40 const int kMaxStalenessParamDefaultValue = 1440;
41
37 void RecordPreviewsInfoBarAction( 42 void RecordPreviewsInfoBarAction(
38 previews::PreviewsType previews_type, 43 previews::PreviewsType previews_type,
39 PreviewsInfoBarDelegate::PreviewsInfoBarAction action) { 44 PreviewsInfoBarDelegate::PreviewsInfoBarAction action) {
40 int32_t max_limit = 45 int32_t max_limit =
41 static_cast<int32_t>(PreviewsInfoBarDelegate::INFOBAR_INDEX_BOUNDARY); 46 static_cast<int32_t>(PreviewsInfoBarDelegate::INFOBAR_INDEX_BOUNDARY);
42 base::LinearHistogram::FactoryGet( 47 base::LinearHistogram::FactoryGet(
43 base::StringPrintf("Previews.InfoBarAction.%s", 48 base::StringPrintf("Previews.InfoBarAction.%s",
44 GetStringNameForType(previews_type).c_str()), 49 GetStringNameForType(previews_type).c_str()),
45 1, max_limit, max_limit + 1, 50 1, max_limit, max_limit + 1,
46 base::HistogramBase::kUmaTargetedHistogramFlag) 51 base::HistogramBase::kUmaTargetedHistogramFlag)
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 243
239 base::string16 PreviewsInfoBarDelegate::GetTimestampText() const { 244 base::string16 PreviewsInfoBarDelegate::GetTimestampText() const {
240 if (previews_freshness_.is_null()) 245 if (previews_freshness_.is_null())
241 return base::string16(); 246 return base::string16();
242 if (!base::FeatureList::IsEnabled( 247 if (!base::FeatureList::IsEnabled(
243 previews::features::kStalePreviewsTimestamp)) { 248 previews::features::kStalePreviewsTimestamp)) {
244 return base::string16(); 249 return base::string16();
245 } 250 }
246 251
247 int min_staleness_in_minutes = base::GetFieldTrialParamByFeatureAsInt( 252 int min_staleness_in_minutes = base::GetFieldTrialParamByFeatureAsInt(
248 previews::features::kStalePreviewsTimestamp, "min_staleness_in_minutes", 253 previews::features::kStalePreviewsTimestamp, kMinStalenessParamName,
249 0); 254 kMinStalenessParamDefaultValue);
250 int max_staleness_in_minutes = base::GetFieldTrialParamByFeatureAsInt( 255 int max_staleness_in_minutes = base::GetFieldTrialParamByFeatureAsInt(
251 previews::features::kStalePreviewsTimestamp, "max_staleness_in_minutes", 256 previews::features::kStalePreviewsTimestamp, kMaxStalenessParamName,
252 0); 257 kMaxStalenessParamDefaultValue);
253 258
254 if (min_staleness_in_minutes == 0 || max_staleness_in_minutes == 0) 259 if (min_staleness_in_minutes <= 0 || max_staleness_in_minutes <= 0)
255 return base::string16(); 260 return base::string16();
256 261
257 base::Time network_time; 262 base::Time network_time;
258 if (g_browser_process->network_time_tracker()->GetNetworkTime(&network_time, 263 if (g_browser_process->network_time_tracker()->GetNetworkTime(&network_time,
259 nullptr) != 264 nullptr) !=
260 network_time::NetworkTimeTracker::NETWORK_TIME_AVAILABLE) { 265 network_time::NetworkTimeTracker::NETWORK_TIME_AVAILABLE) {
261 // When network time has not been initialized yet, simply rely on the 266 // When network time has not been initialized yet, simply rely on the
262 // machine's current time. 267 // machine's current time.
263 network_time = base::Time::Now(); 268 network_time = base::Time::Now();
264 } 269 }
(...skipping 10 matching lines...) Expand all
275 IDS_PREVIEWS_INFOBAR_TIMESTAMP_MINUTES, 280 IDS_PREVIEWS_INFOBAR_TIMESTAMP_MINUTES,
276 base::IntToString16(staleness_in_minutes)); 281 base::IntToString16(staleness_in_minutes));
277 } else if (staleness_in_minutes < 120) { 282 } else if (staleness_in_minutes < 120) {
278 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_ONE_HOUR); 283 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_ONE_HOUR);
279 } else { 284 } else {
280 return l10n_util::GetStringFUTF16( 285 return l10n_util::GetStringFUTF16(
281 IDS_PREVIEWS_INFOBAR_TIMESTAMP_HOURS, 286 IDS_PREVIEWS_INFOBAR_TIMESTAMP_HOURS,
282 base::IntToString16(staleness_in_minutes / 60)); 287 base::IntToString16(staleness_in_minutes / 60));
283 } 288 }
284 } 289 }
OLDNEW
« no previous file with comments | « chrome/browser/flag_descriptions.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698