Index: third_party/WebKit/Source/modules/time_zone_monitor/TimeZoneMonitorClient.cpp |
diff --git a/third_party/WebKit/Source/modules/time_zone_monitor/TimeZoneMonitorClient.cpp b/third_party/WebKit/Source/modules/time_zone_monitor/TimeZoneMonitorClient.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2f08b2a31fd8507dd6a9a080b96ebec9db541eb6 |
--- /dev/null |
+++ b/third_party/WebKit/Source/modules/time_zone_monitor/TimeZoneMonitorClient.cpp |
@@ -0,0 +1,57 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "modules/time_zone_monitor/TimeZoneMonitorClient.h" |
+ |
+#include "base/bind.h" |
+#include "core/workers/WorkerBackingThread.h" |
+#include "public/platform/InterfaceProvider.h" |
+#include "public/platform/Platform.h" |
+#include "third_party/icu/source/i18n/unicode/timezone.h" |
+#include <v8.h> |
+ |
+namespace { |
+ |
+// Notify V8 that the date/time configuration of the system might have changed. |
+void NotifyTimezoneChangeOnThisThread() { |
+ v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
haraken
2016/10/11 11:45:06
v8::Isolate::GetCurrent() is deprecated and should
leonhsl(Using Gerrit)
2016/10/12 03:55:55
Acknowledged and will investigate around how to do
|
+ if (!isolate) |
+ return; |
+ v8::Date::DateTimeConfigurationChangeNotification(isolate); |
+} |
+ |
+} // namespace |
+ |
+namespace blink { |
+ |
+// static |
+void TimeZoneMonitorClient::Init() { |
+ static TimeZoneMonitorClient* instance = nullptr; |
+ if (!instance) |
+ instance = new TimeZoneMonitorClient(); |
+} |
+ |
+TimeZoneMonitorClient::TimeZoneMonitorClient() : m_binding(this) { |
+ device::mojom::blink::TimeZoneMonitorPtr monitor; |
+ Platform::current()->interfaceProvider()->getInterface( |
+ mojo::GetProxy(&monitor)); |
+ monitor->AddClient(m_binding.CreateInterfacePtrAndBind()); |
+} |
+ |
+TimeZoneMonitorClient::~TimeZoneMonitorClient() {} |
+ |
+void TimeZoneMonitorClient::OnTimeZoneChange(const WTF::String& tzInfo) { |
haraken
2016/10/11 11:45:06
timeZoneInfo
Blink prefers a fully qualified name
leonhsl(Using Gerrit)
2016/10/12 03:55:55
Acknowledged.
|
+ if (!tzInfo.isEmpty()) { |
+ icu::TimeZone* zone = icu::TimeZone::createTimeZone( |
+ icu::UnicodeString::fromUTF8(tzInfo.utf8().data())); |
+ icu::TimeZone::adoptDefault(zone); |
+ VLOG(1) << "ICU default timezone is set to " << tzInfo; |
+ } |
+ |
+ NotifyTimezoneChangeOnThisThread(); |
+ WorkerBackingThread::PostTaskToAllThreads( |
+ base::Bind(&NotifyTimezoneChangeOnThisThread)); |
blundell
2016/10/11 11:47:56
What's the WTF equivalent of the base::Bind infras
haraken
2016/10/11 11:50:47
WTF::bind.
leonhsl(Using Gerrit)
2016/10/12 03:55:55
Acknowledged.
|
+} |
+ |
+} // namespace blink |