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

Side by Side Diff: device/time_zone_monitor/time_zone_monitor.cc

Issue 2690963002: [DeviceService] Move //device/time_zone_monitor to //services/device (Closed)
Patch Set: Enable device service to register JNI Created 3 years, 10 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 2014 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 "device/time_zone_monitor/time_zone_monitor.h"
6
7 #include "base/logging.h"
8 #include "build/build_config.h"
9 #include "third_party/icu/source/common/unicode/unistr.h"
10 #include "third_party/icu/source/i18n/unicode/timezone.h"
11
12 namespace device {
13
14 TimeZoneMonitor::TimeZoneMonitor() {
15 DCHECK(thread_checker_.CalledOnValidThread());
16 }
17
18 TimeZoneMonitor::~TimeZoneMonitor() {
19 DCHECK(thread_checker_.CalledOnValidThread());
20 }
21
22 void TimeZoneMonitor::Bind(device::mojom::TimeZoneMonitorRequest request) {
23 bindings_.AddBinding(this, std::move(request));
24 }
25
26 void TimeZoneMonitor::NotifyClients() {
27 DCHECK(thread_checker_.CalledOnValidThread());
28 #if defined(OS_CHROMEOS)
29 // On CrOS, ICU's default tz is already set to a new zone. No
30 // need to redetect it with detectHostTimeZone().
31 std::unique_ptr<icu::TimeZone> new_zone(icu::TimeZone::createDefault());
32 #else
33 icu::TimeZone* new_zone = icu::TimeZone::detectHostTimeZone();
34 #if defined(OS_LINUX)
35 // We get here multiple times on Linux per a single tz change, but
36 // want to update the ICU default zone and notify renderer only once.
37 std::unique_ptr<icu::TimeZone> current_zone(icu::TimeZone::createDefault());
38 if (*current_zone == *new_zone) {
39 VLOG(1) << "timezone already updated";
40 delete new_zone;
41 return;
42 }
43 #endif
44 icu::TimeZone::adoptDefault(new_zone);
45 #endif
46 icu::UnicodeString zone_id;
47 std::string zone_id_str;
48 new_zone->getID(zone_id).toUTF8String(zone_id_str);
49 VLOG(1) << "timezone reset to " << zone_id_str;
50
51 clients_.ForAllPtrs(
52 [&zone_id_str](device::mojom::TimeZoneMonitorClient* client) {
53 client->OnTimeZoneChange(zone_id_str);
54 });
55 }
56
57 void TimeZoneMonitor::AddClient(
58 device::mojom::TimeZoneMonitorClientPtr client) {
59 clients_.AddPtr(std::move(client));
60 }
61
62 } // namespace device
OLDNEW
« no previous file with comments | « device/time_zone_monitor/time_zone_monitor.h ('k') | device/time_zone_monitor/time_zone_monitor_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698