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 "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 static TimeZoneMonitorClient* instance = nullptr; | |
|
haraken
2016/10/17 13:02:55
Use DEFINE_STATIC_LOCAL
leonhsl(Using Gerrit)
2016/10/18 10:03:52
Done.
| |
| 37 if (!instance) | |
| 38 instance = new TimeZoneMonitorClient(); | |
| 39 } | |
| 40 | |
| 41 TimeZoneMonitorClient::TimeZoneMonitorClient() : m_binding(this) { | |
| 42 DCHECK(isMainThread()); | |
| 43 | |
| 44 device::mojom::blink::TimeZoneMonitorPtr monitor; | |
| 45 Platform::current()->interfaceProvider()->getInterface( | |
| 46 mojo::GetProxy(&monitor)); | |
| 47 monitor->AddClient(m_binding.CreateInterfacePtrAndBind()); | |
| 48 } | |
| 49 | |
| 50 TimeZoneMonitorClient::~TimeZoneMonitorClient() {} | |
| 51 | |
| 52 void TimeZoneMonitorClient::OnTimeZoneChange(const WTF::String& timeZoneInfo) { | |
| 53 DCHECK(isMainThread()); | |
| 54 | |
| 55 if (!timeZoneInfo.isEmpty()) { | |
| 56 icu::TimeZone* zone = icu::TimeZone::createTimeZone( | |
| 57 icu::UnicodeString::fromUTF8(timeZoneInfo.utf8().data())); | |
| 58 icu::TimeZone::adoptDefault(zone); | |
| 59 VLOG(1) << "ICU default timezone is set to " << timeZoneInfo; | |
| 60 } | |
| 61 | |
| 62 NotifyTimezoneChangeToV8(V8PerIsolateData::mainThreadIsolate()); | |
| 63 | |
| 64 HashSet<WorkerThread*>& threads = WorkerThread::workerThreads(); | |
| 65 HashSet<WorkerBackingThread*> posted; | |
| 66 for (WorkerThread* thread : threads) { | |
| 67 if (posted.contains(&thread->workerBackingThread())) | |
|
haraken
2016/10/17 13:02:54
Add a comment about why we need this check.
leonhsl(Using Gerrit)
2016/10/18 10:03:52
Done.
| |
| 68 continue; | |
| 69 thread->postTask(BLINK_FROM_HERE, createCrossThreadTask( | |
| 70 &NotifyTimezoneChangeOnWorkerThread)); | |
| 71 posted.add(&thread->workerBackingThread()); | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 } // namespace blink | |
| OLD | NEW |