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