Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(660)

Unified Diff: third_party/WebKit/Source/modules/time_zone_monitor/TimeZoneMonitorClient.cpp

Issue 2402983002: [TimeZoneMonitor] Decouple renderer side impl from content to blink. (Closed)
Patch Set: Create blink::WorkerThread::PostTaskToAllWorkerThreads helper function Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/time_zone_monitor/TimeZoneMonitorClient.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..6c7afd8b10049a13c7948be81098d4c6e6dd6f73
--- /dev/null
+++ b/third_party/WebKit/Source/modules/time_zone_monitor/TimeZoneMonitorClient.cpp
@@ -0,0 +1,58 @@
+// 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 "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 = v8::Isolate::GetCurrent();
leonhsl(Using Gerrit) 2016/10/12 13:54:44 As haraken@ commented, v8::Isolate::GetCurrent() i
haraken 2016/10/12 14:13:19 We have toIsolate(ExecutionContext*).
leonhsl(Using Gerrit) 2016/10/13 09:28:53 Got it and thanks!
+ if (!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) {
+ 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);
leonhsl(Using Gerrit) 2016/10/12 13:54:44 For the main thread, how could we get the v8::Isol
+ WorkerThread::PostTaskToAllWorkerThreads(
+ BLINK_FROM_HERE, createCrossThreadTask(&NotifyTimezoneChange));
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/modules/time_zone_monitor/TimeZoneMonitorClient.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698