Garrick Evans | 7257821 | 2021-05-12 13:57:11 +0900 | [diff] [blame] | 1 | // Copyright 2021 The Chromium OS 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 DNS_PROXY_SESSION_MONITOR_H_ |
| 6 | #define DNS_PROXY_SESSION_MONITOR_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | |
| 11 | #include <base/callback_helpers.h> |
| 12 | #include <session_manager/dbus-proxies.h> |
| 13 | |
| 14 | namespace dns_proxy { |
| 15 | |
| 16 | // Monitors session manager for session state (login/logout) changes. |
| 17 | class SessionMonitor { |
| 18 | public: |
| 19 | explicit SessionMonitor(scoped_refptr<dbus::Bus> bus); |
| 20 | SessionMonitor(const SessionMonitor&) = delete; |
| 21 | SessionMonitor& operator=(const SessionMonitor&) = delete; |
Garrick Evans | 77e9a13 | 2021-05-13 10:51:13 +0900 | [diff] [blame] | 22 | virtual ~SessionMonitor() = default; |
Garrick Evans | 7257821 | 2021-05-12 13:57:11 +0900 | [diff] [blame] | 23 | |
| 24 | // Attaches a handler to be called whenever the session state changes. |
| 25 | // A parameter value of |true| indicates a user is logging in, and |false| |
| 26 | // indicates a user is logging out. |
| 27 | void RegisterSessionStateHandler(base::RepeatingCallback<void(bool)> handler); |
| 28 | |
Garrick Evans | 77e9a13 | 2021-05-13 10:51:13 +0900 | [diff] [blame] | 29 | protected: |
Garrick Evans | 7257821 | 2021-05-12 13:57:11 +0900 | [diff] [blame] | 30 | // Handles the SessionStateChanged DBus signal. |
| 31 | void OnSessionStateChanged(const std::string& state); |
| 32 | |
Garrick Evans | 77e9a13 | 2021-05-13 10:51:13 +0900 | [diff] [blame] | 33 | private: |
Garrick Evans | 7257821 | 2021-05-12 13:57:11 +0900 | [diff] [blame] | 34 | org::chromium::SessionManagerInterfaceProxy proxy_; |
| 35 | base::RepeatingCallback<void(bool)> handler_; |
| 36 | base::WeakPtrFactory<SessionMonitor> weak_ptr_factory_; |
| 37 | }; |
| 38 | |
| 39 | } // namespace dns_proxy |
| 40 | |
| 41 | #endif // DNS_PROXY_SESSION_MONITOR_H_ |