File: ephemeral_network_configuration_handler.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (111 lines) | stat: -rw-r--r-- 4,465 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_ASH_COMPONENTS_NETWORK_EPHEMERAL_NETWORK_CONFIGURATION_HANDLER_H_
#define CHROMEOS_ASH_COMPONENTS_NETWORK_EPHEMERAL_NETWORK_CONFIGURATION_HANDLER_H_

#include <string>

#include "base/component_export.h"
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "chromeos/ash/components/login/login_state/login_state.h"
#include "chromeos/ash/components/network/managed_network_configuration_handler.h"
#include "chromeos/ash/components/network/network_policy_observer.h"
#include "chromeos/dbus/power/power_manager_client.h"

namespace power_manager {
class ScreenIdleState;
}  // namespace power_manager

namespace ash {

// Triggers ephemeral network configuration actions on the sign-in screen when
// one of the ephemeral network policies is set to true and a one of the
// following triggers happen:
// - Initial policy application on startup IFF the device had already been
//   enterprise enrolled,
// - Device comes back from sleep,
// - Screen is turned off due to inactivity.
class COMPONENT_EXPORT(CHROMEOS_NETWORK) EphemeralNetworkConfigurationHandler
    : public LoginState::Observer,
      public NetworkPolicyObserver,
      public chromeos::PowerManagerClient::Observer {
 public:
  // Attempts to create an EphemeralNetworkConfigurationHandler.
  // Can return nullptr in tests if dependencies are not initialized.
  // `managed_network_configuration_handler` must outlive the lifetime of this
  // object.
  // `was_enterprise_managed_at_startup` should be true if the device was
  // already enterprise-enrolled at ash-chrome startup time.
  static std::unique_ptr<EphemeralNetworkConfigurationHandler> TryCreate(
      ManagedNetworkConfigurationHandler* managed_network_configuration_handler,
      bool was_enterprise_managed_at_startup);

  ~EphemeralNetworkConfigurationHandler() override;

  EphemeralNetworkConfigurationHandler(
      const EphemeralNetworkConfigurationHandler&) = delete;
  EphemeralNetworkConfigurationHandler& operator=(
      const EphemeralNetworkConfigurationHandler&) = delete;

  void TriggerPoliciesChangedForTesting(const std::string& userhash);

 private:
  EphemeralNetworkConfigurationHandler(
      ManagedNetworkConfigurationHandler* managed_network_configuration_handler,
      bool was_enterprise_managed_at_startup);

  // Re-evaluates if this EphemeralNetworkConfigurationHandler should be active
  // and call Active/Deactivate accordingly.
  void ReevaluateIsActive();

  // Activate this EphemeralNetworkConfigurationHandler (start watching for
  // triggers to trigger ephemeral network config actions) and also perform the
  // initial trigger if not yet done.
  void Activate();

  // Deactivate this EphemeralNetworkConfigurationHandler - it will not be
  // triggering ephemeral network config actions while deactivated.
  void Deactivate();

  // LoginState::Observer:
  void LoggedInStateChanged() override;

  // NetworkPolicyObserver:
  void PoliciesChanged(const std::string& userhash) override;

  // chromeos::PowerManagerClient::Observer:
  void SuspendDone(base::TimeDelta sleep_duration) override;
  void ScreenIdleStateChanged(
      const power_manager::ScreenIdleState& screen_idle_state) override;

  // Unowned.
  raw_ptr<ManagedNetworkConfigurationHandler>
      managed_network_configuration_handler_;

  base::ScopedObservation<LoginState, LoginState::Observer>
      login_state_observation_{this};
  base::ScopedObservation<ManagedNetworkConfigurationHandler,
                          NetworkPolicyObserver>
      network_policy_observation_{this};
  base::ScopedObservation<chromeos::PowerManagerClient,
                          chromeos::PowerManagerClient::Observer>
      power_manager_client_observation_{this};

  const bool was_enterprise_managed_at_startup_;

  // This is true when any ephemeral network settings are active - i.e. the
  // device is not in a user session and one of the ephemeral network
  // configuration ONC policies is enabled.
  bool active_ = false;

  // This is true if ephemeral policy application has been triggered at least
  // once by this class in `managed_network_configuration_handler_`.
  bool has_applied_ephemeral_policies_ = false;
};

}  // namespace ash

#endif  // CHROMEOS_ASH_COMPONENTS_NETWORK_EPHEMERAL_NETWORK_CONFIGURATION_HANDLER_H_