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 "bindings/core/v8/V8Binding.h" |
| 8 #include "bindings/core/v8/V8PerIsolateData.h" |
| 9 #include "core/dom/ExecutionContext.h" |
| 10 #include "core/dom/ExecutionContextTask.h" |
| 11 #include "core/workers/WorkerBackingThread.h" |
| 12 #include "core/workers/WorkerThread.h" |
| 13 #include "public/platform/InterfaceProvider.h" |
| 14 #include "public/platform/Platform.h" |
| 15 #include "third_party/icu/source/i18n/unicode/timezone.h" |
| 16 #include <v8.h> |
| 17 |
| 18 namespace blink { |
| 19 |
| 20 namespace { |
| 21 |
| 22 // Notify V8 that the date/time configuration of the system might have changed. |
| 23 void NotifyTimezoneChangeToV8(v8::Isolate* isolate) { |
| 24 DCHECK(isolate); |
| 25 v8::Date::DateTimeConfigurationChangeNotification(isolate); |
| 26 } |
| 27 |
| 28 void NotifyTimezoneChangeOnWorkerThread(ExecutionContext* context) { |
| 29 NotifyTimezoneChangeToV8(toIsolate(context)); |
| 30 } |
| 31 |
| 32 } // namespace |
| 33 |
| 34 // static |
| 35 void TimeZoneMonitorClient::Init() { |
| 36 DEFINE_STATIC_LOCAL(TimeZoneMonitorClient, instance, ()); |
| 37 |
| 38 device::mojom::blink::TimeZoneMonitorPtr monitor; |
| 39 Platform::current()->interfaceProvider()->getInterface( |
| 40 mojo::GetProxy(&monitor)); |
| 41 monitor->AddClient(instance.m_binding.CreateInterfacePtrAndBind()); |
| 42 } |
| 43 |
| 44 TimeZoneMonitorClient::TimeZoneMonitorClient() : m_binding(this) { |
| 45 DCHECK(isMainThread()); |
| 46 } |
| 47 |
| 48 TimeZoneMonitorClient::~TimeZoneMonitorClient() {} |
| 49 |
| 50 void TimeZoneMonitorClient::OnTimeZoneChange(const String& timeZoneInfo) { |
| 51 DCHECK(isMainThread()); |
| 52 |
| 53 if (!timeZoneInfo.isEmpty()) { |
| 54 icu::TimeZone* zone = icu::TimeZone::createTimeZone( |
| 55 icu::UnicodeString::fromUTF8(timeZoneInfo.utf8().data())); |
| 56 icu::TimeZone::adoptDefault(zone); |
| 57 VLOG(1) << "ICU default timezone is set to " << timeZoneInfo; |
| 58 } |
| 59 |
| 60 NotifyTimezoneChangeToV8(V8PerIsolateData::mainThreadIsolate()); |
| 61 |
| 62 HashSet<WorkerThread*>& threads = WorkerThread::workerThreads(); |
| 63 HashSet<WorkerBackingThread*> posted; |
| 64 for (WorkerThread* thread : threads) { |
| 65 // Ensure every WorkerBackingThread(holding one platform thread) only get |
| 66 // the task posted once, because one WorkerBackingThread could be shared |
| 67 // among multiple WorkerThreads. |
| 68 if (posted.contains(&thread->workerBackingThread())) |
| 69 continue; |
| 70 thread->postTask(BLINK_FROM_HERE, createCrossThreadTask( |
| 71 &NotifyTimezoneChangeOnWorkerThread)); |
| 72 posted.add(&thread->workerBackingThread()); |
| 73 } |
| 74 } |
| 75 |
| 76 } // namespace blink |
OLD | NEW |