Commit d2b94e32 authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Chromium LUCI CQ

Remove useless notifications if platform timezone is unchanged

On windows, the Timezone modifications is detected by listening
to WM_TIMECHANGE event but that event is emitted for any time
property change.

We are observing in slow-reports that on power suspend/resume
that event is always sent (one or more time) which is triggering
multiple Timezone notification to be sent to observers
(a.k.a renderers).

The proposed solution is to filter the time change by ensuring
the platform specific timezone has changed.

We do not rely on ICU timezone API since it's heavy to be
added on the startup path. The goal is to detect platform
changes to filter out the time change events.

R=gab@chromium.org,fdoray@chromium.org,mark@chromium.org

Bug: 1074036
Change-Id: I296e0735a04d6258a659688a987c58399d4c7ab7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2583012
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841366}
parent 5213b734
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/callback_helpers.h" #include "base/callback_helpers.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "third_party/icu/source/i18n/unicode/timezone.h" #include "third_party/icu/source/i18n/unicode/timezone.h"
#include "ui/gfx/win/singleton_hwnd_observer.h" #include "ui/gfx/win/singleton_hwnd_observer.h"
...@@ -24,7 +25,8 @@ class TimeZoneMonitorWin : public TimeZoneMonitor { ...@@ -24,7 +25,8 @@ class TimeZoneMonitorWin : public TimeZoneMonitor {
: TimeZoneMonitor(), : TimeZoneMonitor(),
singleton_hwnd_observer_(new gfx::SingletonHwndObserver( singleton_hwnd_observer_(new gfx::SingletonHwndObserver(
base::BindRepeating(&TimeZoneMonitorWin::OnWndProc, base::BindRepeating(&TimeZoneMonitorWin::OnWndProc,
base::Unretained(this)))) {} base::Unretained(this)))),
current_platform_timezone_(GetPlatformTimeZone()) {}
TimeZoneMonitorWin(const TimeZoneMonitorWin&) = delete; TimeZoneMonitorWin(const TimeZoneMonitorWin&) = delete;
TimeZoneMonitorWin& operator=(const TimeZoneMonitorWin&) = delete; TimeZoneMonitorWin& operator=(const TimeZoneMonitorWin&) = delete;
...@@ -52,14 +54,39 @@ class TimeZoneMonitorWin : public TimeZoneMonitor { ...@@ -52,14 +54,39 @@ class TimeZoneMonitorWin : public TimeZoneMonitor {
} }
} }
// Returns the platform specific string for the time zone. Do not rely on the
// ICU library since it's taking into account other sources for time zone like
// the TZ environment. This avoid loading the ICU library if not required.
std::string GetPlatformTimeZone() {
std::string timezone;
TIME_ZONE_INFORMATION time_zone_information;
if (::GetTimeZoneInformation(&time_zone_information)) {
// StandardName field may be empty.
timezone = base::WideToUTF8(time_zone_information.StandardName);
}
return timezone;
}
void OnWmTimechangeReceived() { void OnWmTimechangeReceived() {
TRACE_EVENT0("device", "TimeZoneMonitorWin::OnTimechangeReceived"); TRACE_EVENT0("device", "TimeZoneMonitorWin::OnTimechangeReceived");
UpdateIcuAndNotifyClients(DetectHostTimeZoneFromIcu());
// Only dispatch time zone notifications when the platform time zone has
// changed. Windows API is sending WM_TIMECHANGE messages each time a
// time property has changed which is common during a power suspend/resume
// transition even if the time zone stayed the same. As a good example, any
// NTP update may trigger a WM_TIMECHANGE message.
const std::string timezone = GetPlatformTimeZone();
if (timezone.empty() || current_platform_timezone_ != timezone) {
UpdateIcuAndNotifyClients(DetectHostTimeZoneFromIcu());
current_platform_timezone_ = timezone;
}
pending_update_notification_tasks_ = false; pending_update_notification_tasks_ = false;
} }
std::unique_ptr<gfx::SingletonHwndObserver> singleton_hwnd_observer_; std::unique_ptr<gfx::SingletonHwndObserver> singleton_hwnd_observer_;
bool pending_update_notification_tasks_ = false; bool pending_update_notification_tasks_ = false;
std::string current_platform_timezone_;
base::WeakPtrFactory<TimeZoneMonitorWin> weak_ptr_factory_{this}; base::WeakPtrFactory<TimeZoneMonitorWin> weak_ptr_factory_{this};
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment