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 "base/bind.h" | |
| 8 #include "core/workers/WorkerBackingThread.h" | |
| 9 #include "public/platform/InterfaceProvider.h" | |
| 10 #include "public/platform/Platform.h" | |
| 11 #include "third_party/icu/source/i18n/unicode/timezone.h" | |
| 12 #include <v8.h> | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 // Notify V8 that the date/time configuration of the system might have changed. | |
| 17 void NotifyTimezoneChangeOnThisThread() { | |
| 18 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
| 19 if (!isolate) | |
| 20 return; | |
| 21 v8::Date::DateTimeConfigurationChangeNotification(isolate); | |
| 22 } | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 namespace blink { | |
| 27 | |
| 28 // static | |
| 29 void TimeZoneMonitorClient::Init() { | |
| 30 static TimeZoneMonitorClient* instance = nullptr; | |
| 31 if (!instance) | |
| 32 instance = new TimeZoneMonitorClient(); | |
| 33 } | |
| 34 | |
| 35 TimeZoneMonitorClient::TimeZoneMonitorClient() : m_binding(this) { | |
| 36 device::mojom::TimeZoneMonitorPtr monitor; | |
| 37 Platform::current()->interfaceProvider()->getInterface( | |
| 38 mojo::GetProxy(&monitor)); | |
| 39 monitor->AddClient(m_binding.CreateInterfacePtrAndBind()); | |
| 40 } | |
| 41 | |
| 42 TimeZoneMonitorClient::~TimeZoneMonitorClient() {} | |
| 43 | |
| 44 void TimeZoneMonitorClient::OnTimeZoneChange(const std::string& tzInfo) { | |
| 45 if (!tzInfo.empty()) { | |
| 46 icu::TimeZone* zone = | |
| 47 icu::TimeZone::createTimeZone(icu::UnicodeString::fromUTF8(tzInfo)); | |
| 48 icu::TimeZone::adoptDefault(zone); | |
| 49 VLOG(1) << "ICU default timezone is set to " << tzInfo; | |
| 50 } | |
| 51 | |
| 52 NotifyTimezoneChangeOnThisThread(); | |
| 53 WorkerBackingThread::PostTaskToAllThreads( | |
| 54 base::Bind(&NotifyTimezoneChangeOnThisThread)); | |
|
leonhsl(Using Gerrit)
2016/10/10 12:56:02
Presubmit ERRORS: Do not use Chromium class from n
| |
| 55 } | |
| 56 | |
| 57 } // namespace blink | |
| OLD | NEW |