blob: d12187a7ba20853193d9db04c5b850f6d201c64f [file] [log] [blame]
Garrick Evans72578212021-05-12 13:57:11 +09001// 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
14namespace dns_proxy {
15
16// Monitors session manager for session state (login/logout) changes.
17class SessionMonitor {
18 public:
19 explicit SessionMonitor(scoped_refptr<dbus::Bus> bus);
20 SessionMonitor(const SessionMonitor&) = delete;
21 SessionMonitor& operator=(const SessionMonitor&) = delete;
Garrick Evans77e9a132021-05-13 10:51:13 +090022 virtual ~SessionMonitor() = default;
Garrick Evans72578212021-05-12 13:57:11 +090023
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 Evans77e9a132021-05-13 10:51:13 +090029 protected:
Garrick Evans72578212021-05-12 13:57:11 +090030 // Handles the SessionStateChanged DBus signal.
31 void OnSessionStateChanged(const std::string& state);
32
Garrick Evans77e9a132021-05-13 10:51:13 +090033 private:
Garrick Evans72578212021-05-12 13:57:11 +090034 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_