Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "modules/time_zone_monitor/TimeZoneMonitorClient.h" | |
| 6 | |
| 7 #include "core/dom/ExecutionContext.h" | |
| 8 #include "core/dom/ExecutionContextTask.h" | |
| 9 #include "core/workers/WorkerThread.h" | |
| 10 #include "public/platform/InterfaceProvider.h" | |
| 11 #include "public/platform/Platform.h" | |
| 12 #include "third_party/icu/source/i18n/unicode/timezone.h" | |
| 13 #include <v8.h> | |
| 14 | |
| 15 namespace blink { | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 // Notify V8 that the date/time configuration of the system might have changed. | |
| 20 void NotifyTimezoneChange(ExecutionContext* context) { | |
| 21 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!
| |
| 22 if (!isolate) | |
| 23 return; | |
| 24 v8::Date::DateTimeConfigurationChangeNotification(isolate); | |
| 25 } | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 // static | |
| 30 void TimeZoneMonitorClient::Init() { | |
| 31 static TimeZoneMonitorClient* instance = nullptr; | |
| 32 if (!instance) | |
| 33 instance = new TimeZoneMonitorClient(); | |
| 34 } | |
| 35 | |
| 36 TimeZoneMonitorClient::TimeZoneMonitorClient() : m_binding(this) { | |
| 37 device::mojom::blink::TimeZoneMonitorPtr monitor; | |
| 38 Platform::current()->interfaceProvider()->getInterface( | |
| 39 mojo::GetProxy(&monitor)); | |
| 40 monitor->AddClient(m_binding.CreateInterfacePtrAndBind()); | |
| 41 } | |
| 42 | |
| 43 TimeZoneMonitorClient::~TimeZoneMonitorClient() {} | |
| 44 | |
| 45 void TimeZoneMonitorClient::OnTimeZoneChange(const WTF::String& timeZoneInfo) { | |
| 46 if (!timeZoneInfo.isEmpty()) { | |
| 47 icu::TimeZone* zone = icu::TimeZone::createTimeZone( | |
| 48 icu::UnicodeString::fromUTF8(timeZoneInfo.utf8().data())); | |
| 49 icu::TimeZone::adoptDefault(zone); | |
| 50 VLOG(1) << "ICU default timezone is set to " << timeZoneInfo; | |
| 51 } | |
| 52 | |
| 53 NotifyTimezoneChange(nullptr); | |
|
leonhsl(Using Gerrit)
2016/10/12 13:54:44
For the main thread, how could we get the v8::Isol
| |
| 54 WorkerThread::PostTaskToAllWorkerThreads( | |
| 55 BLINK_FROM_HERE, createCrossThreadTask(&NotifyTimezoneChange)); | |
| 56 } | |
| 57 | |
| 58 } // namespace blink | |
| OLD | NEW |