File: auth_panel.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
file content (104 lines) | stat: -rw-r--r-- 3,719 bytes parent folder | download
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
// 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_AUTH_PANEL_IMPL_AUTH_PANEL_H_
#define CHROMEOS_ASH_COMPONENTS_AUTH_PANEL_IMPL_AUTH_PANEL_H_

#include <vector>

#include "ash/login/ui/non_accessible_view.h"
#include "base/containers/flat_map.h"
#include "base/functional/callback_forward.h"
#include "chromeos/ash/components/auth_panel/public/shared_types.h"
#include "chromeos/ash/components/osauth/public/auth_factor_status_consumer.h"
#include "chromeos/ash/components/osauth/public/auth_hub.h"
#include "chromeos/ash/components/osauth/public/common_types.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/view.h"

namespace ash {

class AuthHubConnector;
class AuthPanelEventDispatcher;
class AuthPanelEventDispatcherFactory;
class AuthFactorStore;
class AuthFactorStoreFactory;
class FactorAuthView;
class FactorAuthViewFactory;
class PasswordAuthView;

// Controller class that orchestrates the several `FactorAuthView` objects.
// Responsible for :
// - Listening for changes in auth factor state, auth attempt
// results, and propagating them to the respective `FactorAuthView` objects.
// - The general layout of the authentication UI, hiding and
// showing UI elements for particular auth factors when their status change.
// - Tracking selected factors, in the event where a factor can be toggled,
// for instance, with password/pin.
class AuthPanel : public NonAccessibleView, public AuthFactorStatusConsumer {
  METADATA_HEADER(AuthPanel, views::View)

 public:
  class TestApi {
   public:
    explicit TestApi(AuthPanel*);
    ~TestApi();
    TestApi(const TestApi&) = delete;
    TestApi& operator=(const TestApi&) = delete;

    PasswordAuthView* GetPasswordAuthView();

    AuthHubConnector* GetAuthHubConnector();

    void SetSubmitPasswordCallback(auth_panel::SubmitPasswordCallback);

   private:
    raw_ptr<AuthPanel> auth_panel_;
  };

  AuthPanel(
      std::unique_ptr<FactorAuthViewFactory> view_factory,
      std::unique_ptr<AuthFactorStoreFactory> store_factory,
      std::unique_ptr<AuthPanelEventDispatcherFactory> event_dispatcher_factory,
      base::OnceClosure on_end_authentication,
      base::RepeatingClosure on_ui_initialized,
      AuthHubConnector* connector);
  AuthPanel(const AuthPanel&) = delete;
  AuthPanel(AuthPanel&&) = delete;
  AuthPanel& operator=(const AuthPanel&) = delete;
  AuthPanel& operator=(AuthPanel&&) = delete;
  ~AuthPanel() override;

  // AuthFactorStatusConsumer:
  void InitializeUi(AuthFactorsSet factors,
                    AuthHubConnector* connector) override;
  void OnFactorListChanged(FactorsStatusMap factors_with_status) override;
  void OnFactorStatusesChanged(FactorsStatusMap incremental_update) override;
  void OnFactorCustomSignal(AshAuthFactor factor) override;
  void OnFactorAuthFailure(AshAuthFactor factor) override;
  void OnFactorAuthSuccess(AshAuthFactor factor) override;
  void OnEndAuthentication() override;

 private:
  friend class TestApi;

  void InitializeViewPlaceholders();

  base::flat_map<AshAuthFactor, raw_ptr<views::View>> views_;
  std::unique_ptr<AuthPanelEventDispatcherFactory> event_dispatcher_factory_;
  std::unique_ptr<FactorAuthViewFactory> view_factory_;
  std::unique_ptr<AuthFactorStoreFactory> store_factory_;

  std::unique_ptr<AuthFactorStore> store_;
  std::unique_ptr<AuthPanelEventDispatcher> event_dispatcher_;

  base::OnceClosure on_end_authentication_;
  base::RepeatingClosure on_ui_changed_;

  raw_ptr<AuthHubConnector> auth_hub_connector_;
};

}  // namespace ash

#endif  // CHROMEOS_ASH_COMPONENTS_AUTH_PANEL_IMPL_AUTH_PANEL_H_