| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/time_zone_monitor/TimeZoneMonitorClient.h" | 5 #include "modules/time_zone_monitor/TimeZoneMonitorClient.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/V8Binding.h" | 7 #include "bindings/core/v8/V8Binding.h" |
| 8 #include "bindings/core/v8/V8PerIsolateData.h" | 8 #include "bindings/core/v8/V8PerIsolateData.h" |
| 9 #include "core/dom/ExecutionContext.h" | 9 #include "core/dom/ExecutionContext.h" |
| 10 #include "core/dom/ExecutionContextTask.h" | |
| 11 #include "core/workers/WorkerBackingThread.h" | 10 #include "core/workers/WorkerBackingThread.h" |
| 11 #include "core/workers/WorkerOrWorkletGlobalScope.h" |
| 12 #include "core/workers/WorkerThread.h" | 12 #include "core/workers/WorkerThread.h" |
| 13 #include "platform/CrossThreadFunctional.h" |
| 13 #include "platform/ServiceConnector.h" | 14 #include "platform/ServiceConnector.h" |
| 14 #include "public/platform/Platform.h" | 15 #include "public/platform/Platform.h" |
| 15 #include "services/device/public/interfaces/constants.mojom-blink.h" | 16 #include "services/device/public/interfaces/constants.mojom-blink.h" |
| 16 #include "third_party/icu/source/i18n/unicode/timezone.h" | 17 #include "third_party/icu/source/i18n/unicode/timezone.h" |
| 17 #include <v8.h> | 18 #include <v8.h> |
| 18 | 19 |
| 19 namespace blink { | 20 namespace blink { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // Notify V8 that the date/time configuration of the system might have changed. | 24 // Notify V8 that the date/time configuration of the system might have changed. |
| 24 void NotifyTimezoneChangeToV8(v8::Isolate* isolate) { | 25 void NotifyTimezoneChangeToV8(v8::Isolate* isolate) { |
| 25 DCHECK(isolate); | 26 DCHECK(isolate); |
| 26 v8::Date::DateTimeConfigurationChangeNotification(isolate); | 27 v8::Date::DateTimeConfigurationChangeNotification(isolate); |
| 27 } | 28 } |
| 28 | 29 |
| 29 void NotifyTimezoneChangeOnWorkerThread(ExecutionContext* context) { | 30 void NotifyTimezoneChangeOnWorkerThread(WorkerThread* workerThread) { |
| 30 NotifyTimezoneChangeToV8(toIsolate(context)); | 31 DCHECK(workerThread->isCurrentThread()); |
| 32 NotifyTimezoneChangeToV8(toIsolate(workerThread->globalScope())); |
| 31 } | 33 } |
| 32 | 34 |
| 33 } // namespace | 35 } // namespace |
| 34 | 36 |
| 35 // static | 37 // static |
| 36 void TimeZoneMonitorClient::Init() { | 38 void TimeZoneMonitorClient::Init() { |
| 37 DEFINE_STATIC_LOCAL(TimeZoneMonitorClient, instance, ()); | 39 DEFINE_STATIC_LOCAL(TimeZoneMonitorClient, instance, ()); |
| 38 | 40 |
| 39 device::mojom::blink::TimeZoneMonitorPtr monitor; | 41 device::mojom::blink::TimeZoneMonitorPtr monitor; |
| 40 ServiceConnector::instance().connectToInterface( | 42 ServiceConnector::instance().connectToInterface( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 61 NotifyTimezoneChangeToV8(V8PerIsolateData::mainThreadIsolate()); | 63 NotifyTimezoneChangeToV8(V8PerIsolateData::mainThreadIsolate()); |
| 62 | 64 |
| 63 HashSet<WorkerThread*>& threads = WorkerThread::workerThreads(); | 65 HashSet<WorkerThread*>& threads = WorkerThread::workerThreads(); |
| 64 HashSet<WorkerBackingThread*> posted; | 66 HashSet<WorkerBackingThread*> posted; |
| 65 for (WorkerThread* thread : threads) { | 67 for (WorkerThread* thread : threads) { |
| 66 // Ensure every WorkerBackingThread(holding one platform thread) only get | 68 // Ensure every WorkerBackingThread(holding one platform thread) only get |
| 67 // the task posted once, because one WorkerBackingThread could be shared | 69 // the task posted once, because one WorkerBackingThread could be shared |
| 68 // among multiple WorkerThreads. | 70 // among multiple WorkerThreads. |
| 69 if (posted.contains(&thread->workerBackingThread())) | 71 if (posted.contains(&thread->workerBackingThread())) |
| 70 continue; | 72 continue; |
| 71 thread->postTask(BLINK_FROM_HERE, createCrossThreadTask( | 73 thread->postTask(BLINK_FROM_HERE, |
| 72 &NotifyTimezoneChangeOnWorkerThread)); | 74 crossThreadBind(&NotifyTimezoneChangeOnWorkerThread, |
| 75 WTF::crossThreadUnretained(thread))); |
| 73 posted.add(&thread->workerBackingThread()); | 76 posted.add(&thread->workerBackingThread()); |
| 74 } | 77 } |
| 75 } | 78 } |
| 76 | 79 |
| 77 } // namespace blink | 80 } // namespace blink |
| OLD | NEW |