| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 BrowserThread::FILE, | 67 BrowserThread::FILE, |
| 68 FROM_HERE, | 68 FROM_HERE, |
| 69 base::Bind(&TimeZoneMonitorLinuxImpl::StopWatchingOnFileThread, this)); | 69 base::Bind(&TimeZoneMonitorLinuxImpl::StopWatchingOnFileThread, this)); |
| 70 } | 70 } |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 friend class base::RefCountedThreadSafe<TimeZoneMonitorLinuxImpl>; | 73 friend class base::RefCountedThreadSafe<TimeZoneMonitorLinuxImpl>; |
| 74 | 74 |
| 75 ~TimeZoneMonitorLinuxImpl() { | 75 ~TimeZoneMonitorLinuxImpl() { |
| 76 DCHECK(!owner_); | 76 DCHECK(!owner_); |
| 77 STLDeleteElements(&file_path_watchers_); | 77 base::STLDeleteElements(&file_path_watchers_); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void StartWatchingOnFileThread() { | 80 void StartWatchingOnFileThread() { |
| 81 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 81 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 82 | 82 |
| 83 // There is no true standard for where time zone information is actually | 83 // There is no true standard for where time zone information is actually |
| 84 // stored. glibc uses /etc/localtime, uClibc uses /etc/TZ, and some older | 84 // stored. glibc uses /etc/localtime, uClibc uses /etc/TZ, and some older |
| 85 // systems store the name of the time zone file within /usr/share/zoneinfo | 85 // systems store the name of the time zone file within /usr/share/zoneinfo |
| 86 // in /etc/timezone. Different libraries and custom builds may mean that | 86 // in /etc/timezone. Different libraries and custom builds may mean that |
| 87 // still more paths are used. Just watch all three of these paths, because | 87 // still more paths are used. Just watch all three of these paths, because |
| 88 // false positives are harmless, assuming the false positive rate is | 88 // false positives are harmless, assuming the false positive rate is |
| 89 // reasonable. | 89 // reasonable. |
| 90 const char* const kFilesToWatch[] = { | 90 const char* const kFilesToWatch[] = { |
| 91 "/etc/localtime", | 91 "/etc/localtime", |
| 92 "/etc/timezone", | 92 "/etc/timezone", |
| 93 "/etc/TZ", | 93 "/etc/TZ", |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 for (size_t index = 0; index < arraysize(kFilesToWatch); ++index) { | 96 for (size_t index = 0; index < arraysize(kFilesToWatch); ++index) { |
| 97 file_path_watchers_.push_back(new base::FilePathWatcher()); | 97 file_path_watchers_.push_back(new base::FilePathWatcher()); |
| 98 file_path_watchers_.back()->Watch( | 98 file_path_watchers_.back()->Watch( |
| 99 base::FilePath(kFilesToWatch[index]), | 99 base::FilePath(kFilesToWatch[index]), |
| 100 false, | 100 false, |
| 101 base::Bind(&TimeZoneMonitorLinuxImpl::OnTimeZoneFileChanged, this)); | 101 base::Bind(&TimeZoneMonitorLinuxImpl::OnTimeZoneFileChanged, this)); |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 void StopWatchingOnFileThread() { | 105 void StopWatchingOnFileThread() { |
| 106 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 106 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 107 STLDeleteElements(&file_path_watchers_); | 107 base::STLDeleteElements(&file_path_watchers_); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void OnTimeZoneFileChanged(const base::FilePath& path, bool error) { | 110 void OnTimeZoneFileChanged(const base::FilePath& path, bool error) { |
| 111 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 111 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 112 BrowserThread::PostTask( | 112 BrowserThread::PostTask( |
| 113 BrowserThread::UI, | 113 BrowserThread::UI, |
| 114 FROM_HERE, | 114 FROM_HERE, |
| 115 base::Bind(&TimeZoneMonitorLinuxImpl::OnTimeZoneFileChangedOnUIThread, | 115 base::Bind(&TimeZoneMonitorLinuxImpl::OnTimeZoneFileChangedOnUIThread, |
| 116 this)); | 116 this)); |
| 117 } | 117 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } | 159 } |
| 160 | 160 |
| 161 // static | 161 // static |
| 162 std::unique_ptr<TimeZoneMonitor> TimeZoneMonitor::Create() { | 162 std::unique_ptr<TimeZoneMonitor> TimeZoneMonitor::Create() { |
| 163 return std::unique_ptr<TimeZoneMonitor>(new TimeZoneMonitorLinux()); | 163 return std::unique_ptr<TimeZoneMonitor>(new TimeZoneMonitorLinux()); |
| 164 } | 164 } |
| 165 | 165 |
| 166 } // namespace content | 166 } // namespace content |
| 167 | 167 |
| 168 #endif // !OS_CHROMEOS | 168 #endif // !OS_CHROMEOS |
| OLD | NEW |