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