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