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

Side by Side Diff: content/browser/time_zone_monitor.cc

Issue 2304073003: Mojoify time zone update IPC from browser to renderer (Closed)
Patch Set: nits Created 4 years, 3 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
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);
21 bindings_.CloseAllBindings();
dcheng 2016/09/06 22:20:38 I thought this would implicitly happen as part of
blundell 2016/09/07 14:40:05 Ah yes, thanks for making me revisit this! I had m
dcheng 2016/09/07 20:59:27 I kind of feel like it would be nice to have expli
blundell 2016/09/12 14:30:33 Noted for the future, reasoning works for me. Afte
22 } 22 }
23 23
24 void TimeZoneMonitor::NotifyRenderers() { 24 void TimeZoneMonitor::Bind(device::mojom::TimeZoneMonitorRequest request) {
25 bindings_.AddBinding(this, std::move(request));
26 }
27
28 void TimeZoneMonitor::NotifyClients() {
25 DCHECK_CURRENTLY_ON(BrowserThread::UI); 29 DCHECK_CURRENTLY_ON(BrowserThread::UI);
26 #if defined(OS_CHROMEOS) 30 #if defined(OS_CHROMEOS)
27 // On CrOS, ICU's default tz is already set to a new zone. No 31 // On CrOS, ICU's default tz is already set to a new zone. No
28 // need to redetect it with detectHostTimeZone(). 32 // need to redetect it with detectHostTimeZone().
29 std::unique_ptr<icu::TimeZone> new_zone(icu::TimeZone::createDefault()); 33 std::unique_ptr<icu::TimeZone> new_zone(icu::TimeZone::createDefault());
30 #else 34 #else
31 icu::TimeZone* new_zone = icu::TimeZone::detectHostTimeZone(); 35 icu::TimeZone* new_zone = icu::TimeZone::detectHostTimeZone();
32 #if defined(OS_LINUX) 36 #if defined(OS_LINUX)
33 // We get here multiple times on Linux per a single tz change, but 37 // 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. 38 // want to update the ICU default zone and notify renderer only once.
35 std::unique_ptr<icu::TimeZone> current_zone(icu::TimeZone::createDefault()); 39 std::unique_ptr<icu::TimeZone> current_zone(icu::TimeZone::createDefault());
36 if (*current_zone == *new_zone) { 40 if (*current_zone == *new_zone) {
37 VLOG(1) << "timezone already updated"; 41 VLOG(1) << "timezone already updated";
38 delete new_zone; 42 delete new_zone;
39 return; 43 return;
40 } 44 }
41 #endif 45 #endif
42 icu::TimeZone::adoptDefault(new_zone); 46 icu::TimeZone::adoptDefault(new_zone);
43 #endif 47 #endif
44 icu::UnicodeString zone_id; 48 icu::UnicodeString zone_id;
45 std::string zone_id_str; 49 std::string zone_id_str;
46 new_zone->getID(zone_id).toUTF8String(zone_id_str); 50 new_zone->getID(zone_id).toUTF8String(zone_id_str);
47 VLOG(1) << "timezone reset to " << zone_id_str; 51 VLOG(1) << "timezone reset to " << zone_id_str;
48 for (RenderProcessHost::iterator iterator = 52
49 RenderProcessHost::AllHostsIterator(); 53 std::vector<device::mojom::TimeZoneMonitor::QueryNextTimeZoneChangeCallback>
50 !iterator.IsAtEnd(); 54 tasks;
51 iterator.Advance()) { 55 on_time_zone_change_tasks_.swap(tasks);
52 iterator.GetCurrentValue()->NotifyTimezoneChange(zone_id_str); 56 for (auto& task : tasks)
53 } 57 task.Run(zone_id_str);
58 }
59
60 void TimeZoneMonitor::QueryNextTimeZoneChange(
61 const device::mojom::TimeZoneMonitor::QueryNextTimeZoneChangeCallback&
62 callback) {
63 on_time_zone_change_tasks_.push_back(callback);
54 } 64 }
55 65
56 } // namespace content 66 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698