1 // Copyright 2020 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 CHROME_BROWSER_CHROMEOS_LOGIN_SECURITY_TOKEN_SESSION_CONTROLLER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SECURITY_TOKEN_SESSION_CONTROLLER_H_
7 
8 #include "components/keyed_service/core/keyed_service.h"
9 #include "components/prefs/pref_change_registrar.h"
10 #include "components/prefs/pref_registry_simple.h"
11 #include "components/prefs/pref_service.h"
12 
13 namespace chromeos {
14 namespace login {
15 
16 // A controller that implements the combined behavior of the
17 // SecurityTokenSessionBehavior and SecurityTokenSessionNotificationSeconds
18 // preferences. When a user is authenticating via a security token (e.g., with a
19 // smart card), SecurityTokenSessionBehavior dictates what should happen if the
20 // certificate ceases to be present while the user is logged in.
21 // SecurityTokenSessionNotificationSeconds determines if and how long the user
22 // is getting informed what is going to happen when the certificate vanishes.
23 class SecurityTokenSessionController : public KeyedService {
24  public:
25   enum class Behavior { kIgnore, kLogout, kLock };
26 
27   explicit SecurityTokenSessionController(PrefService* pref_service);
28   SecurityTokenSessionController(const SecurityTokenSessionController& other) =
29       delete;
30   SecurityTokenSessionController& operator=(
31       const SecurityTokenSessionController& other) = delete;
32   ~SecurityTokenSessionController() override;
33 
34   // KeyedService
35   void Shutdown() override;
36 
37   static void RegisterPrefs(PrefRegistrySimple* registry);
38 
39  private:
40   Behavior GetBehaviorFromPref() const;
41 
42   void UpdateBehaviorPref();
43   void UpdateNotificationPref();
44 
45   PrefService* const pref_service_;
46   PrefChangeRegistrar pref_change_registrar_;
47   Behavior behavior_ = Behavior::kIgnore;
48   base::TimeDelta notification_seconds_;
49 };
50 
51 }  // namespace login
52 }  // namespace chromeos
53 
54 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_SECURITY_TOKEN_SESSION_CONTROLLER_H_
55