OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/time_zone_monitor.h" | 5 #include "content/browser/time_zone_monitor.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
10 #include "content/public/browser/render_process_host.h" | |
11 #include "third_party/icu/source/common/unicode/unistr.h" | 10 #include "third_party/icu/source/common/unicode/unistr.h" |
12 #include "third_party/icu/source/i18n/unicode/timezone.h" | 11 #include "third_party/icu/source/i18n/unicode/timezone.h" |
13 | 12 |
14 namespace content { | 13 namespace content { |
15 | 14 |
16 TimeZoneMonitor::TimeZoneMonitor() { | 15 TimeZoneMonitor::TimeZoneMonitor() { |
17 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 16 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
18 } | 17 } |
19 | 18 |
20 TimeZoneMonitor::~TimeZoneMonitor() { | 19 TimeZoneMonitor::~TimeZoneMonitor() { |
21 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 20 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
22 } | 21 } |
23 | 22 |
24 void TimeZoneMonitor::NotifyRenderers() { | 23 void TimeZoneMonitor::Bind(device::mojom::TimeZoneMonitorRequest request) { |
| 24 bindings_.AddBinding(this, std::move(request)); |
| 25 } |
| 26 |
| 27 void TimeZoneMonitor::NotifyClients() { |
25 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 28 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
26 #if defined(OS_CHROMEOS) | 29 #if defined(OS_CHROMEOS) |
27 // On CrOS, ICU's default tz is already set to a new zone. No | 30 // On CrOS, ICU's default tz is already set to a new zone. No |
28 // need to redetect it with detectHostTimeZone(). | 31 // need to redetect it with detectHostTimeZone(). |
29 std::unique_ptr<icu::TimeZone> new_zone(icu::TimeZone::createDefault()); | 32 std::unique_ptr<icu::TimeZone> new_zone(icu::TimeZone::createDefault()); |
30 #else | 33 #else |
31 icu::TimeZone* new_zone = icu::TimeZone::detectHostTimeZone(); | 34 icu::TimeZone* new_zone = icu::TimeZone::detectHostTimeZone(); |
32 #if defined(OS_LINUX) | 35 #if defined(OS_LINUX) |
33 // We get here multiple times on Linux per a single tz change, but | 36 // We get here multiple times on Linux per a single tz change, but |
34 // want to update the ICU default zone and notify renderer only once. | 37 // want to update the ICU default zone and notify renderer only once. |
35 std::unique_ptr<icu::TimeZone> current_zone(icu::TimeZone::createDefault()); | 38 std::unique_ptr<icu::TimeZone> current_zone(icu::TimeZone::createDefault()); |
36 if (*current_zone == *new_zone) { | 39 if (*current_zone == *new_zone) { |
37 VLOG(1) << "timezone already updated"; | 40 VLOG(1) << "timezone already updated"; |
38 delete new_zone; | 41 delete new_zone; |
39 return; | 42 return; |
40 } | 43 } |
41 #endif | 44 #endif |
42 icu::TimeZone::adoptDefault(new_zone); | 45 icu::TimeZone::adoptDefault(new_zone); |
43 #endif | 46 #endif |
44 icu::UnicodeString zone_id; | 47 icu::UnicodeString zone_id; |
45 std::string zone_id_str; | 48 std::string zone_id_str; |
46 new_zone->getID(zone_id).toUTF8String(zone_id_str); | 49 new_zone->getID(zone_id).toUTF8String(zone_id_str); |
47 VLOG(1) << "timezone reset to " << zone_id_str; | 50 VLOG(1) << "timezone reset to " << zone_id_str; |
48 for (RenderProcessHost::iterator iterator = | 51 |
49 RenderProcessHost::AllHostsIterator(); | 52 clients_.ForAllPtrs( |
50 !iterator.IsAtEnd(); | 53 [&zone_id_str](device::mojom::TimeZoneMonitorClient* client) { |
51 iterator.Advance()) { | 54 client->OnTimeZoneChange(zone_id_str); |
52 iterator.GetCurrentValue()->NotifyTimezoneChange(zone_id_str); | 55 }); |
53 } | 56 } |
| 57 |
| 58 void TimeZoneMonitor::AddClient( |
| 59 device::mojom::TimeZoneMonitorClientPtr client) { |
| 60 clients_.AddPtr(std::move(client)); |
54 } | 61 } |
55 | 62 |
56 } // namespace content | 63 } // namespace content |
OLD | NEW |