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 TimeZoneMonitorClient& TimeZoneMonitorClient::Init() { | |
haraken
2016/10/26 11:21:59
The return value is unused.
leonhsl(Using Gerrit)
2016/10/26 11:45:48
Just want to create it as long-live singleton, and
haraken
2016/10/26 13:27:11
Can you just change the return type to void?
leonhsl(Using Gerrit)
2016/10/27 05:01:27
Done.
| |
36 DEFINE_STATIC_LOCAL(TimeZoneMonitorClient, instance, ()); | |
haraken
2016/10/26 11:21:59
Why do you need to use DEFINE_STATIC_LOCAL?
leonhsl(Using Gerrit)
2016/10/26 11:45:48
According your previous comment at: https://codere
haraken
2016/10/26 13:27:11
OK, you want to make it a singleton... Then DEFINE
| |
37 return instance; | |
38 } | |
39 | |
40 TimeZoneMonitorClient::TimeZoneMonitorClient() : m_binding(this) { | |
41 DCHECK(isMainThread()); | |
42 | |
43 device::mojom::blink::TimeZoneMonitorPtr monitor; | |
44 Platform::current()->interfaceProvider()->getInterface( | |
haraken
2016/10/26 12:02:12
I begin to wonder why you need to run these steps
leonhsl(Using Gerrit)
2016/10/26 12:13:00
Because TimeZoneMonitorClient needs to be able to
haraken
2016/10/26 13:27:11
ok
| |
45 mojo::GetProxy(&monitor)); | |
46 monitor->AddClient(m_binding.CreateInterfacePtrAndBind()); | |
47 } | |
48 | |
49 TimeZoneMonitorClient::~TimeZoneMonitorClient() {} | |
50 | |
51 void TimeZoneMonitorClient::OnTimeZoneChange(const WTF::String& timeZoneInfo) { | |
52 DCHECK(isMainThread()); | |
53 | |
54 if (!timeZoneInfo.isEmpty()) { | |
55 icu::TimeZone* zone = icu::TimeZone::createTimeZone( | |
56 icu::UnicodeString::fromUTF8(timeZoneInfo.utf8().data())); | |
57 icu::TimeZone::adoptDefault(zone); | |
58 VLOG(1) << "ICU default timezone is set to " << timeZoneInfo; | |
59 } | |
60 | |
61 NotifyTimezoneChangeToV8(V8PerIsolateData::mainThreadIsolate()); | |
62 | |
63 HashSet<WorkerThread*>& threads = WorkerThread::workerThreads(); | |
64 HashSet<WorkerBackingThread*> posted; | |
65 for (WorkerThread* thread : threads) { | |
66 // Ensure every WorkerBackingThread(holding one platform thread) only get | |
67 // the task posted once, because one WorkerBackingThread could be shared | |
68 // among multiple WorkerThreads. | |
69 if (posted.contains(&thread->workerBackingThread())) | |
70 continue; | |
71 thread->postTask(BLINK_FROM_HERE, createCrossThreadTask( | |
72 &NotifyTimezoneChangeOnWorkerThread)); | |
73 posted.add(&thread->workerBackingThread()); | |
74 } | |
75 } | |
76 | |
77 } // namespace blink | |
OLD | NEW |