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 instance.Bind(); | |
38 } | |
39 | |
40 TimeZoneMonitorClient::TimeZoneMonitorClient() : m_binding(this) { | |
41 DCHECK(isMainThread()); | |
42 } | |
43 | |
44 TimeZoneMonitorClient::~TimeZoneMonitorClient() {} | |
45 | |
46 void TimeZoneMonitorClient::Bind() { | |
47 DCHECK(isMainThread()); | |
48 if (m_binding.is_bound()) | |
blundell
2016/10/27 15:31:19
Do you expect this method to be called more than o
leonhsl(Using Gerrit)
2016/10/28 05:59:06
This should happen only once, so I added the guard
blundell
2016/10/28 14:36:13
You could presumably just inline the code and use
leonhsl(Using Gerrit)
2016/10/30 13:24:18
Done.
| |
49 return; | |
50 | |
51 device::mojom::blink::TimeZoneMonitorPtr monitor; | |
52 Platform::current()->interfaceProvider()->getInterface( | |
53 mojo::GetProxy(&monitor)); | |
54 monitor->AddClient(m_binding.CreateInterfacePtrAndBind()); | |
55 } | |
56 | |
57 void TimeZoneMonitorClient::OnTimeZoneChange(const WTF::String& timeZoneInfo) { | |
dcheng
2016/10/27 22:34:50
Nit: omit WTF::
leonhsl(Using Gerrit)
2016/10/28 05:59:06
Done.
| |
58 DCHECK(isMainThread()); | |
59 | |
60 if (!timeZoneInfo.isEmpty()) { | |
61 icu::TimeZone* zone = icu::TimeZone::createTimeZone( | |
62 icu::UnicodeString::fromUTF8(timeZoneInfo.utf8().data())); | |
63 icu::TimeZone::adoptDefault(zone); | |
64 VLOG(1) << "ICU default timezone is set to " << timeZoneInfo; | |
65 } | |
66 | |
67 NotifyTimezoneChangeToV8(V8PerIsolateData::mainThreadIsolate()); | |
68 | |
69 HashSet<WorkerThread*>& threads = WorkerThread::workerThreads(); | |
70 HashSet<WorkerBackingThread*> posted; | |
71 for (WorkerThread* thread : threads) { | |
72 // Ensure every WorkerBackingThread(holding one platform thread) only get | |
73 // the task posted once, because one WorkerBackingThread could be shared | |
74 // among multiple WorkerThreads. | |
75 if (posted.contains(&thread->workerBackingThread())) | |
76 continue; | |
77 thread->postTask(BLINK_FROM_HERE, createCrossThreadTask( | |
78 &NotifyTimezoneChangeOnWorkerThread)); | |
79 posted.add(&thread->workerBackingThread()); | |
80 } | |
81 } | |
82 | |
83 } // namespace blink | |
OLD | NEW |