File: profile_picker_signed_in_flow_controller.h

package info (click to toggle)
chromium 139.0.7258.138-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,120,676 kB
  • sloc: cpp: 35,100,869; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (173 lines) | stat: -rw-r--r-- 7,341 bytes parent folder | download | duplicates (4)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_PICKER_SIGNED_IN_FLOW_CONTROLLER_H_
#define CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_PICKER_SIGNED_IN_FLOW_CONTROLLER_H_

#include <optional>

#include "base/files/file_path.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/profiles/keep_alive/scoped_profile_keep_alive.h"
#include "chrome/browser/ui/views/profiles/profile_management_types.h"
#include "chrome/browser/ui/views/profiles/profile_picker_web_contents_host.h"
#include "chrome/browser/ui/webui/signin/managed_user_profile_notice_ui.h"
#include "chrome/browser/ui/webui/signin/signin_utils.h"
#include "components/signin/public/base/signin_metrics.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "content/public/browser/web_contents_delegate.h"
#include "third_party/skia/include/core/SkColor.h"

class Profile;

namespace content {
struct ContextMenuParams;
class RenderFrameHost;
class WebContents;
}  // namespace content

// Class triggering the signed-in section of the profile management flow, most
// notably featuring the sync confirmation. This class:
// - Expects a primary account to be set with `ConsentLevel::kSignin`.
// - Runs the `TurnSyncOnHelper` and provides it a delegate to interact with
//   `host`.
// - At the end of the flow we are in one of these cases:
//   - The host is closed and a browser is opened, via `FinishAndOpenBrowser()`;
//   - The host is not closed and the profile switch screen is shown, via
//     `SwitchToProfileSwitch()`.
class ProfilePickerSignedInFlowController
    : public content::WebContentsDelegate {
 public:
  ProfilePickerSignedInFlowController(
      ProfilePickerWebContentsHost* host,
      Profile* profile,
      const CoreAccountInfo& account_info,
      std::unique_ptr<content::WebContents> contents,
      signin_metrics::AccessPoint signin_access_point,
      std::optional<SkColor> profile_color);
  ~ProfilePickerSignedInFlowController() override;
  ProfilePickerSignedInFlowController(
      const ProfilePickerSignedInFlowController&) = delete;
  ProfilePickerSignedInFlowController& operator=(
      const ProfilePickerSignedInFlowController&) = delete;

  // Inits the flow, must be called before any other calls below.
  virtual void Init(StepSwitchFinishedCallback step_switch_callback);

  // Cancels the flow explicitly.
  // By default does not do anything, in the flow it will be as if the dialog
  // was closed.
  virtual void Cancel();
  // Resets the host by redirecting to the main profile picker screen and
  // canceling the ongoing signed in flow. Shows an error dialog when the reset
  // is done.
  void ResetHostAndShowErrorDialog(const ForceSigninUIError& error);

  // Finishes the creation flow for `profile_`: marks it fully created,
  // transitions from `host_` to a new browser window and calls `callback` if
  // the browser window was successfully opened.
  // TODO(crbug.com/40242414): Tighten this contract by notifying the caller if
  // the browser open was not possible.
  void FinishAndOpenBrowser(PostHostClearedCallback callback);

  // Finishes the sign-in process by moving to the sync confirmation screen.
  virtual void SwitchToSyncConfirmation();

  // Finishes the sign-in process by moving to the managed user profile notice
  // screen.
  virtual void SwitchToManagedUserProfileNotice(
      ManagedUserProfileNoticeUI::ScreenType type,
      signin::SigninChoiceCallback proceed_callback);

  // When the sign-in flow cannot be completed because another profile at
  // `profile_path` is already syncing with a chosen account, shows the profile
  // switch screen. It uses the system profile for showing the switch screen.
  void SwitchToProfileSwitch(const base::FilePath& profile_path);

  base::WeakPtr<ProfilePickerSignedInFlowController> GetWeakPtr() {
    return weak_ptr_factory_.GetWeakPtr();
  }

  // Getter of the path of profile which is displayed on the profile switch
  // screen. Returns an empty path if no such screen has been displayed.
  base::FilePath switch_profile_path() const { return switch_profile_path_; }

  content::WebContents* contents() const { return contents_.get(); }

 protected:
  virtual void FinishAndOpenBrowserInternal(PostHostClearedCallback callback,
                                            bool is_continue_callback) = 0;

  // Returns the profile color, taking into account current policies.
  std::optional<SkColor> GetProfileColor() const;

  // Returns the URL for sync confirmation screen (or for the "is-loading"
  // version of it, if `loading` is true).
  GURL GetSyncConfirmationURL(bool loading);

  ProfilePickerWebContentsHost* host() const { return host_; }
  Profile* profile() const { return profile_; }
  std::unique_ptr<content::WebContents> ReleaseContents();
  const CoreAccountInfo& account_info() const { return account_info_; }

 private:
  // content::WebContentsDelegate:
  bool HandleContextMenu(content::RenderFrameHost& render_frame_host,
                         const content::ContextMenuParams& params) override;
  bool HandleKeyboardEvent(content::WebContents* source,
                           const input::NativeWebKeyboardEvent& event) override;

  // Callbacks that finalize initialization of WebUI pages.
  void SwitchToSyncConfirmationFinished();
  void SwitchToManagedUserProfileNoticeFinished(
      ManagedUserProfileNoticeUI::ScreenType type,
      signin::SigninChoiceCallback process_user_choice_callback);

  // Returns whether the flow is initialized (i.e. whether `Init()` has been
  // called).
  bool IsInitialized() const;

  // The host object, must outlive this object.
  raw_ptr<ProfilePickerWebContentsHost> host_;

  raw_ptr<Profile> profile_ = nullptr;

  // Account ID for the profile. Note that it may not be set as primary account
  // yet.
  const CoreAccountInfo account_info_;

  // Prevent |profile_| from being destroyed first.
  std::unique_ptr<ScopedProfileKeepAlive> profile_keep_alive_;

  // The web contents backed by `profile`. This is used for displaying the
  // sign-in flow.
  std::unique_ptr<content::WebContents> contents_;

  const signin_metrics::AccessPoint signin_access_point_;

  // Set for the profile at the very end to avoid coloring the simple toolbar
  // for GAIA sign-in (that uses the ThemeProvider of the current profile).
  // std::nullopt if the profile should use the default theme.
  std::optional<SkColor> profile_color_;

  // This callback will only return once the content of the step decided if it
  // should be shown or not. E.g: Sync confirmation screen, profile switch, or
  // enterprise management.
  StepSwitchFinishedCallback step_switch_callback_;

  // Email of the signed-in account. It is set after the user finishes the
  // sign-in flow on GAIA and Chrome receives the account info.
  std::string email_;

  // Path to a profile that should be displayed on the profile switch screen.
  base::FilePath switch_profile_path_;

  GURL url_to_open_;

  base::WeakPtrFactory<ProfilePickerSignedInFlowController> weak_ptr_factory_{
      this};
};

#endif  // CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_PICKER_SIGNED_IN_FLOW_CONTROLLER_H_