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

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

Issue 2304073003: Mojoify time zone update IPC from browser to renderer (Closed)
Patch Set: Response to reviews 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
22 // Explicitly tear down the connections so that the callbacks in
23 // |on_time_zone_change_tasks_| can safely be destroyed (otherwise they
24 // can DCHECK due to being destroyed unfilled while their connection is
25 // still active).
26 bindings_.CloseAllBindings();
22 } 27 }
23 28
24 void TimeZoneMonitor::NotifyRenderers() { 29 void TimeZoneMonitor::Bind(device::mojom::TimeZoneMonitorRequest request) {
30 bindings_.AddBinding(this, std::move(request));
31 }
32
33 void TimeZoneMonitor::NotifyClients() {
25 DCHECK_CURRENTLY_ON(BrowserThread::UI); 34 DCHECK_CURRENTLY_ON(BrowserThread::UI);
26 #if defined(OS_CHROMEOS) 35 #if defined(OS_CHROMEOS)
27 // On CrOS, ICU's default tz is already set to a new zone. No 36 // On CrOS, ICU's default tz is already set to a new zone. No
28 // need to redetect it with detectHostTimeZone(). 37 // need to redetect it with detectHostTimeZone().
29 std::unique_ptr<icu::TimeZone> new_zone(icu::TimeZone::createDefault()); 38 std::unique_ptr<icu::TimeZone> new_zone(icu::TimeZone::createDefault());
30 #else 39 #else
31 icu::TimeZone* new_zone = icu::TimeZone::detectHostTimeZone(); 40 icu::TimeZone* new_zone = icu::TimeZone::detectHostTimeZone();
32 #if defined(OS_LINUX) 41 #if defined(OS_LINUX)
33 // We get here multiple times on Linux per a single tz change, but 42 // 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. 43 // want to update the ICU default zone and notify renderer only once.
35 std::unique_ptr<icu::TimeZone> current_zone(icu::TimeZone::createDefault()); 44 std::unique_ptr<icu::TimeZone> current_zone(icu::TimeZone::createDefault());
36 if (*current_zone == *new_zone) { 45 if (*current_zone == *new_zone) {
37 VLOG(1) << "timezone already updated"; 46 VLOG(1) << "timezone already updated";
38 delete new_zone; 47 delete new_zone;
39 return; 48 return;
40 } 49 }
41 #endif 50 #endif
42 icu::TimeZone::adoptDefault(new_zone); 51 icu::TimeZone::adoptDefault(new_zone);
43 #endif 52 #endif
44 icu::UnicodeString zone_id; 53 icu::UnicodeString zone_id;
45 std::string zone_id_str; 54 std::string zone_id_str;
46 new_zone->getID(zone_id).toUTF8String(zone_id_str); 55 new_zone->getID(zone_id).toUTF8String(zone_id_str);
47 VLOG(1) << "timezone reset to " << zone_id_str; 56 VLOG(1) << "timezone reset to " << zone_id_str;
48 for (RenderProcessHost::iterator iterator = 57
49 RenderProcessHost::AllHostsIterator(); 58 std::vector<device::mojom::TimeZoneMonitor::QueryNextTimeZoneChangeCallback>
50 !iterator.IsAtEnd(); 59 tasks;
51 iterator.Advance()) { 60 on_time_zone_change_tasks_.swap(tasks);
52 iterator.GetCurrentValue()->NotifyTimezoneChange(zone_id_str); 61 for (auto& task : tasks)
53 } 62 task.Run(zone_id_str);
63 }
64
65 void TimeZoneMonitor::QueryNextTimeZoneChange(
66 const device::mojom::TimeZoneMonitor::QueryNextTimeZoneChangeCallback&
67 callback) {
68 on_time_zone_change_tasks_.push_back(callback);
54 } 69 }
55 70
56 } // namespace content 71 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698