| 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 #ifndef CONTENT_BROWSER_TIME_ZONE_MONITOR_H_ | 5 #ifndef CONTENT_BROWSER_TIME_ZONE_MONITOR_H_ |
| 6 #define CONTENT_BROWSER_TIME_ZONE_MONITOR_H_ | 6 #define CONTENT_BROWSER_TIME_ZONE_MONITOR_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
| 12 #include "device/time_zone_monitor/public/interfaces/time_zone_monitor.mojom.h" | 12 #include "device/time_zone_monitor/public/interfaces/time_zone_monitor.mojom.h" |
| 13 #include "device/time_zone_monitor/time_zone_monitor_export.h" |
| 13 #include "mojo/public/cpp/bindings/binding_set.h" | 14 #include "mojo/public/cpp/bindings/binding_set.h" |
| 14 #include "mojo/public/cpp/bindings/interface_ptr_set.h" | 15 #include "mojo/public/cpp/bindings/interface_ptr_set.h" |
| 15 | 16 |
| 16 template <class T> | 17 template <class T> |
| 17 class scoped_refptr; | 18 class scoped_refptr; |
| 18 | 19 |
| 19 namespace base { | 20 namespace base { |
| 20 class SequencedTaskRunner; | 21 class SequencedTaskRunner; |
| 21 } | 22 } |
| 22 | 23 |
| 23 namespace content { | 24 namespace device { |
| 24 | 25 |
| 25 // TimeZoneMonitor watches the system time zone, and notifies renderers | 26 // TimeZoneMonitor watches the system time zone, and notifies renderers |
| 26 // when it changes. Some renderer code caches the system time zone, so | 27 // when it changes. Some renderer code caches the system time zone, so |
| 27 // this notification is necessary to inform such code that cached | 28 // this notification is necessary to inform such code that cached |
| 28 // timezone data may have become invalid. Due to sandboxing, it is not | 29 // timezone data may have become invalid. Due to sandboxing, it is not |
| 29 // possible for renderer processes to monitor for system time zone | 30 // possible for renderer processes to monitor for system time zone |
| 30 // changes themselves, so this must happen in the browser process. | 31 // changes themselves, so this must happen in the browser process. |
| 31 // | 32 // |
| 32 // Sandboxing also may prevent renderer processes from reading the time | 33 // Sandboxing also may prevent renderer processes from reading the time |
| 33 // zone when it does change, so platforms may have to deal with this in | 34 // zone when it does change, so platforms may have to deal with this in |
| 34 // platform-specific ways: | 35 // platform-specific ways: |
| 35 // - Mac uses a sandbox hole defined in content/renderer/renderer.sb. | 36 // - Mac uses a sandbox hole defined in content/renderer/renderer.sb. |
| 36 // - Linux-based platforms use ProxyLocaltimeCallToBrowser in | 37 // - Linux-based platforms use ProxyLocaltimeCallToBrowser in |
| 37 // content/zygote/zygote_main_linux.cc and HandleLocaltime in | 38 // content/zygote/zygote_main_linux.cc and HandleLocaltime in |
| 38 // content/browser/renderer_host/sandbox_ipc_linux.cc to override | 39 // content/browser/renderer_host/sandbox_ipc_linux.cc to override |
| 39 // localtime in renderer processes with custom code that calls | 40 // localtime in renderer processes with custom code that calls |
| 40 // localtime in the browser process via Chrome IPC. | 41 // localtime in the browser process via Chrome IPC. |
| 41 | 42 |
| 42 class TimeZoneMonitor : public device::mojom::TimeZoneMonitor { | 43 class TimeZoneMonitor : public device::mojom::TimeZoneMonitor { |
| 43 public: | 44 public: |
| 44 // Returns a new TimeZoneMonitor object (likely a subclass) specific to the | 45 // Returns a new TimeZoneMonitor object (likely a subclass) specific to the |
| 45 // platform. Inject |file_task_runner| to enable running blocking file | 46 // platform. Inject |file_task_runner| to enable running blocking file |
| 46 // operations on it when necessary. | 47 // operations on it when necessary. |
| 47 static std::unique_ptr<TimeZoneMonitor> Create( | 48 DEVICE_TIME_ZONE_MONITOR_EXPORT static std::unique_ptr<TimeZoneMonitor> |
| 48 scoped_refptr<base::SequencedTaskRunner> file_task_runner); | 49 Create(scoped_refptr<base::SequencedTaskRunner> file_task_runner); |
| 49 | 50 |
| 50 ~TimeZoneMonitor() override; | 51 ~TimeZoneMonitor() override; |
| 51 | 52 |
| 52 void Bind(device::mojom::TimeZoneMonitorRequest request); | 53 DEVICE_TIME_ZONE_MONITOR_EXPORT void Bind( |
| 54 device::mojom::TimeZoneMonitorRequest request); |
| 53 | 55 |
| 54 protected: | 56 protected: |
| 55 TimeZoneMonitor(); | 57 TimeZoneMonitor(); |
| 56 | 58 |
| 57 // Notify all callbacks that the system time zone may have changed. | 59 // Notify all callbacks that the system time zone may have changed. |
| 58 void NotifyClients(); | 60 void NotifyClients(); |
| 59 | 61 |
| 60 private: | 62 private: |
| 61 base::ThreadChecker thread_checker_; | 63 base::ThreadChecker thread_checker_; |
| 62 | 64 |
| 63 // device::mojom::device::mojom::TimeZoneMonitor: | 65 // device::mojom::device::mojom::TimeZoneMonitor: |
| 64 void AddClient(device::mojom::TimeZoneMonitorClientPtr client) override; | 66 void AddClient(device::mojom::TimeZoneMonitorClientPtr client) override; |
| 65 | 67 |
| 66 mojo::BindingSet<device::mojom::TimeZoneMonitor> bindings_; | 68 mojo::BindingSet<device::mojom::TimeZoneMonitor> bindings_; |
| 67 mojo::InterfacePtrSet<device::mojom::TimeZoneMonitorClient> clients_; | 69 mojo::InterfacePtrSet<device::mojom::TimeZoneMonitorClient> clients_; |
| 68 DISALLOW_COPY_AND_ASSIGN(TimeZoneMonitor); | 70 DISALLOW_COPY_AND_ASSIGN(TimeZoneMonitor); |
| 69 }; | 71 }; |
| 70 | 72 |
| 71 } // namespace content | 73 } // namespace device |
| 72 | 74 |
| 73 #endif // CONTENT_BROWSER_TIME_ZONE_MONITOR_H_ | 75 #endif // CONTENT_BROWSER_TIME_ZONE_MONITOR_H_ |
| OLD | NEW |