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

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

Issue 2353283002: [TimeZoneMonitor] Decouple //content/browser/time_zone_monitor* to //device/. (Closed)
Patch Set: Do not set output_name in gn Created 4 years, 2 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 "device/time_zone_monitor/time_zone_monitor.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 9
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/files/file_path_watcher.h" 14 #include "base/files/file_path_watcher.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/sequenced_task_runner.h" 17 #include "base/sequenced_task_runner.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "base/threading/thread_restrictions.h" 19 #include "base/threading/thread_restrictions.h"
20 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
21 #include "build/build_config.h" 21 #include "build/build_config.h"
22 22
23 #if !defined(OS_CHROMEOS) 23 #if !defined(OS_CHROMEOS)
24 24
25 namespace content { 25 namespace device {
26 26
27 namespace { 27 namespace {
28 class TimeZoneMonitorLinuxImpl; 28 class TimeZoneMonitorLinuxImpl;
29 } // namespace 29 } // namespace
30 30
31 class TimeZoneMonitorLinux : public TimeZoneMonitor { 31 class TimeZoneMonitorLinux : public TimeZoneMonitor {
32 public: 32 public:
33 TimeZoneMonitorLinux( 33 TimeZoneMonitorLinux(
34 scoped_refptr<base::SequencedTaskRunner> file_task_runner); 34 scoped_refptr<base::SequencedTaskRunner> file_task_runner);
35 ~TimeZoneMonitorLinux() override; 35 ~TimeZoneMonitorLinux() override;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); 85 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
86 86
87 // There is no true standard for where time zone information is actually 87 // There is no true standard for where time zone information is actually
88 // stored. glibc uses /etc/localtime, uClibc uses /etc/TZ, and some older 88 // stored. glibc uses /etc/localtime, uClibc uses /etc/TZ, and some older
89 // systems store the name of the time zone file within /usr/share/zoneinfo 89 // systems store the name of the time zone file within /usr/share/zoneinfo
90 // in /etc/timezone. Different libraries and custom builds may mean that 90 // in /etc/timezone. Different libraries and custom builds may mean that
91 // still more paths are used. Just watch all three of these paths, because 91 // still more paths are used. Just watch all three of these paths, because
92 // false positives are harmless, assuming the false positive rate is 92 // false positives are harmless, assuming the false positive rate is
93 // reasonable. 93 // reasonable.
94 const char* const kFilesToWatch[] = { 94 const char* const kFilesToWatch[] = {
95 "/etc/localtime", 95 "/etc/localtime", "/etc/timezone", "/etc/TZ",
96 "/etc/timezone",
97 "/etc/TZ",
98 }; 96 };
99 97
100 for (size_t index = 0; index < arraysize(kFilesToWatch); ++index) { 98 for (size_t index = 0; index < arraysize(kFilesToWatch); ++index) {
101 file_path_watchers_.push_back(new base::FilePathWatcher()); 99 file_path_watchers_.push_back(new base::FilePathWatcher());
102 file_path_watchers_.back()->Watch( 100 file_path_watchers_.back()->Watch(
103 base::FilePath(kFilesToWatch[index]), 101 base::FilePath(kFilesToWatch[index]), false,
104 false,
105 base::Bind(&TimeZoneMonitorLinuxImpl::OnTimeZoneFileChanged, this)); 102 base::Bind(&TimeZoneMonitorLinuxImpl::OnTimeZoneFileChanged, this));
106 } 103 }
107 } 104 }
108 105
109 void StopWatchingOnFileThread() { 106 void StopWatchingOnFileThread() {
110 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); 107 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
111 base::STLDeleteElements(&file_path_watchers_); 108 base::STLDeleteElements(&file_path_watchers_);
112 } 109 }
113 110
114 void OnTimeZoneFileChanged(const base::FilePath& path, bool error) { 111 void OnTimeZoneFileChanged(const base::FilePath& path, bool error) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 161 }
165 } 162 }
166 163
167 // static 164 // static
168 std::unique_ptr<TimeZoneMonitor> TimeZoneMonitor::Create( 165 std::unique_ptr<TimeZoneMonitor> TimeZoneMonitor::Create(
169 scoped_refptr<base::SequencedTaskRunner> file_task_runner) { 166 scoped_refptr<base::SequencedTaskRunner> file_task_runner) {
170 return std::unique_ptr<TimeZoneMonitor>( 167 return std::unique_ptr<TimeZoneMonitor>(
171 new TimeZoneMonitorLinux(file_task_runner)); 168 new TimeZoneMonitorLinux(file_task_runner));
172 } 169 }
173 170
174 } // namespace content 171 } // namespace device
175 172
176 #endif // !OS_CHROMEOS 173 #endif // !OS_CHROMEOS
OLDNEW
« no previous file with comments | « device/time_zone_monitor/time_zone_monitor_export.h ('k') | device/time_zone_monitor/time_zone_monitor_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698