Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: third_party/WebKit/Source/modules/time_zone_monitor/TimeZoneMonitorClient.cpp

Issue 2402983002: [TimeZoneMonitor] Decouple renderer side impl from content to blink. (Closed)
Patch Set: content_unittests does not need to init mojo edk any more by itself Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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() {
36 DEFINE_STATIC_LOCAL(TimeZoneMonitorClient, instance, ());
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(
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(
blundell 2016/10/18 12:32:11 To be totally explicit about this issue: This beh
leonhsl(Using Gerrit) 2016/10/18 14:34:48 Acknowledged.
nhiroki 2016/10/19 02:13:47 Yes, that's right.
leonhsl(Using Gerrit) 2016/10/19 08:47:23 Done. Updated cl description.
72 &NotifyTimezoneChangeOnWorkerThread));
73 posted.add(&thread->workerBackingThread());
74 }
75 }
76
77 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698