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..811f42ce83809398994843f9b0a1ce70d979fedd |
--- /dev/null |
+++ b/third_party/WebKit/Source/modules/time_zone_monitor/TimeZoneMonitorClient.cpp |
@@ -0,0 +1,59 @@ |
+// 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 "bindings/core/v8/V8Binding.h" |
+#include "core/dom/ExecutionContext.h" |
+#include "core/dom/ExecutionContextTask.h" |
+#include "core/workers/WorkerThread.h" |
+#include "public/platform/InterfaceProvider.h" |
+#include "public/platform/Platform.h" |
+#include "third_party/icu/source/i18n/unicode/timezone.h" |
+#include <v8.h> |
+ |
+namespace blink { |
+ |
+namespace { |
+ |
+// Notify V8 that the date/time configuration of the system might have changed. |
+void NotifyTimezoneChange(ExecutionContext* context) { |
+ v8::Isolate* isolate = toIsolate(context); |
+ if (!isolate) |
haraken
2016/10/17 03:59:49
This shouldn't happen.
leonhsl(Using Gerrit)
2016/10/17 07:30:01
Got it, changed to DCHECK(isolate).
|
+ return; |
+ v8::Date::DateTimeConfigurationChangeNotification(isolate); |
+} |
+ |
+} // namespace |
+ |
+// 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& timeZoneInfo) { |
nhiroki
2016/10/13 10:24:12
Is this called only from the main thread?
I'm con
leonhsl(Using Gerrit)
2016/10/14 03:12:00
Yeah mojo binding is thread hostile and the mojo m
nhiroki
2016/10/17 03:56:37
OK, then we can safely access WorkerThread::worker
leonhsl(Using Gerrit)
2016/10/17 07:30:01
Got it.
|
+ if (!timeZoneInfo.isEmpty()) { |
+ icu::TimeZone* zone = icu::TimeZone::createTimeZone( |
+ icu::UnicodeString::fromUTF8(timeZoneInfo.utf8().data())); |
+ icu::TimeZone::adoptDefault(zone); |
+ VLOG(1) << "ICU default timezone is set to " << timeZoneInfo; |
+ } |
+ |
+ NotifyTimezoneChange(nullptr); |
nhiroki
2016/10/13 10:24:12
Does this call make sense?
leonhsl(Using Gerrit)
2016/10/14 03:12:00
This is to notify the V8 isolate for current threa
nhiroki
2016/10/17 03:56:37
Thank you for the explanation. I don't know whethe
haraken
2016/10/17 03:59:49
Can you make NotifyTimezoneChange take an Isolate
leonhsl(Using Gerrit)
2016/10/17 07:30:01
Done and thanks!
|
+ WorkerThread::PostTaskToAllWorkerThreads( |
+ BLINK_FROM_HERE, createCrossThreadTask(&NotifyTimezoneChange)); |
+} |
+ |
+} // namespace blink |