| Index: chrome/browser/previews/previews_infobar_delegate.cc
|
| diff --git a/chrome/browser/previews/previews_infobar_delegate.cc b/chrome/browser/previews/previews_infobar_delegate.cc
|
| index e5947ca3c35ad4baeb0f3003794dd1bc6d61e27d..110f20885eda515966c239a227430ac53c795f2d 100644
|
| --- a/chrome/browser/previews/previews_infobar_delegate.cc
|
| +++ b/chrome/browser/previews/previews_infobar_delegate.cc
|
| @@ -4,9 +4,15 @@
|
|
|
| #include "chrome/browser/previews/previews_infobar_delegate.h"
|
|
|
| +#include "base/feature_list.h"
|
| +#include "base/metrics/field_trial_params.h"
|
| #include "base/metrics/histogram.h"
|
| #include "base/optional.h"
|
| +#include "base/strings/string16.h"
|
| +#include "base/strings/string_number_conversions.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| #include "chrome/browser/android/android_theme_resources.h"
|
| +#include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/infobars/infobar_service.h"
|
| #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
|
| #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
|
| @@ -16,6 +22,8 @@
|
| #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
|
| #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
|
| #include "components/infobars/core/infobar.h"
|
| +#include "components/network_time/network_time_tracker.h"
|
| +#include "components/previews/core/previews_features.h"
|
| #include "content/public/browser/render_frame_host.h"
|
| #include "content/public/browser/web_contents.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| @@ -101,6 +109,7 @@ PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() {
|
| void PreviewsInfoBarDelegate::Create(
|
| content::WebContents* web_contents,
|
| previews::PreviewsType previews_type,
|
| + base::Time previews_freshness,
|
| bool is_data_saver_user,
|
| const OnDismissPreviewsInfobarCallback& on_dismiss_callback) {
|
| PreviewsInfoBarTabHelper* infobar_tab_helper =
|
| @@ -116,7 +125,8 @@ void PreviewsInfoBarDelegate::Create(
|
| return;
|
|
|
| std::unique_ptr<PreviewsInfoBarDelegate> delegate(new PreviewsInfoBarDelegate(
|
| - web_contents, previews_type, is_data_saver_user, on_dismiss_callback));
|
| + web_contents, previews_type, previews_freshness, is_data_saver_user,
|
| + on_dismiss_callback));
|
|
|
| #if defined(OS_ANDROID)
|
| std::unique_ptr<infobars::InfoBar> infobar_ptr(
|
| @@ -144,10 +154,12 @@ void PreviewsInfoBarDelegate::Create(
|
| PreviewsInfoBarDelegate::PreviewsInfoBarDelegate(
|
| content::WebContents* web_contents,
|
| previews::PreviewsType previews_type,
|
| + base::Time previews_freshness,
|
| bool is_data_saver_user,
|
| const OnDismissPreviewsInfobarCallback& on_dismiss_callback)
|
| : ConfirmInfoBarDelegate(),
|
| previews_type_(previews_type),
|
| + previews_freshness_(previews_freshness),
|
| infobar_dismissed_action_(INFOBAR_DISMISSED_BY_TAB_CLOSURE),
|
| message_text_(l10n_util::GetStringUTF16(
|
| is_data_saver_user ? IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE
|
| @@ -180,7 +192,18 @@ void PreviewsInfoBarDelegate::InfoBarDismissed() {
|
| }
|
|
|
| base::string16 PreviewsInfoBarDelegate::GetMessageText() const {
|
| +// Android has a custom infobar that calls GetTimestampText() and adds the
|
| +// timestamp in a separate description view. Other OS's can enable previews
|
| +// for debugging purposes and don't have a custom infobar with a description
|
| +// view, so the timestamp should be appended to the message.
|
| +#if defined(OS_ANDROID)
|
| return message_text_;
|
| +#else
|
| + base::string16 timestamp = GetTimestampText();
|
| + if (timestamp.empty())
|
| + return message_text_;
|
| + return message_text_ + base::ASCIIToUTF16(" ") + timestamp;
|
| +#endif
|
| }
|
|
|
| int PreviewsInfoBarDelegate::GetButtons() const {
|
| @@ -214,5 +237,48 @@ bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
|
| }
|
|
|
| base::string16 PreviewsInfoBarDelegate::GetTimestampText() const {
|
| - return base::string16();
|
| + if (previews_freshness_.is_null())
|
| + return base::string16();
|
| + if (!base::FeatureList::IsEnabled(
|
| + previews::features::kStalePreviewsTimestamp)) {
|
| + return base::string16();
|
| + }
|
| +
|
| + int min_staleness_in_minutes = base::GetFieldTrialParamByFeatureAsInt(
|
| + previews::features::kStalePreviewsTimestamp, "min_staleness_in_minutes",
|
| + 0);
|
| + int max_staleness_in_minutes = base::GetFieldTrialParamByFeatureAsInt(
|
| + previews::features::kStalePreviewsTimestamp, "max_staleness_in_minutes",
|
| + 0);
|
| +
|
| + if (min_staleness_in_minutes == 0 || max_staleness_in_minutes == 0)
|
| + return base::string16();
|
| +
|
| + base::Time network_time;
|
| + if (g_browser_process->network_time_tracker()->GetNetworkTime(&network_time,
|
| + nullptr) !=
|
| + network_time::NetworkTimeTracker::NETWORK_TIME_AVAILABLE) {
|
| + // When network time has not been initialized yet, simply rely on the
|
| + // machine's current time.
|
| + network_time = base::Time::Now();
|
| + }
|
| +
|
| + int staleness_in_minutes = (network_time - previews_freshness_).InMinutes();
|
| + // TODO(megjablon): record metrics for out of bounds staleness.
|
| + if (staleness_in_minutes < min_staleness_in_minutes)
|
| + return base::string16();
|
| + if (staleness_in_minutes > max_staleness_in_minutes)
|
| + return base::string16();
|
| +
|
| + if (staleness_in_minutes < 60) {
|
| + return l10n_util::GetStringFUTF16(
|
| + IDS_PREVIEWS_INFOBAR_TIMESTAMP_MINUTES,
|
| + base::IntToString16(staleness_in_minutes));
|
| + } else if (staleness_in_minutes < 120) {
|
| + return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_TIMESTAMP_ONE_HOUR);
|
| + } else {
|
| + return l10n_util::GetStringFUTF16(
|
| + IDS_PREVIEWS_INFOBAR_TIMESTAMP_HOURS,
|
| + base::IntToString16(staleness_in_minutes / 60));
|
| + }
|
| }
|
|
|