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

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: 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
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

Powered by Google App Engine
This is Rietveld 408576698