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..6a895e5109dae6b5f42c80fe4b4da2e1feefcc08 |
--- /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(); |
+ 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::TimeZoneMonitorPtr monitor; |
+ Platform::current()->interfaceProvider()->getInterface( |
+ mojo::GetProxy(&monitor)); |
+ monitor->AddClient(m_binding.CreateInterfacePtrAndBind()); |
+} |
+ |
+TimeZoneMonitorClient::~TimeZoneMonitorClient() {} |
+ |
+void TimeZoneMonitorClient::OnTimeZoneChange(const std::string& tzInfo) { |
+ if (!tzInfo.empty()) { |
+ icu::TimeZone* zone = |
+ icu::TimeZone::createTimeZone(icu::UnicodeString::fromUTF8(tzInfo)); |
+ icu::TimeZone::adoptDefault(zone); |
+ VLOG(1) << "ICU default timezone is set to " << tzInfo; |
+ } |
+ |
+ NotifyTimezoneChangeOnThisThread(); |
+ WorkerBackingThread::PostTaskToAllThreads( |
+ base::Bind(&NotifyTimezoneChangeOnThisThread)); |
leonhsl(Using Gerrit)
2016/10/10 12:56:02
Presubmit ERRORS: Do not use Chromium class from n
|
+} |
+ |
+} // namespace blink |