summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/ui/webui/signin/login_ui_service.h
blob: 7b154a3037e68ae9887d37650ffeb87e7be26c4d (plain)
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
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_WEBUI_SIGNIN_LOGIN_UI_SERVICE_H_
#define CHROME_BROWSER_UI_WEBUI_SIGNIN_LOGIN_UI_SERVICE_H_

#include <list>
#include <memory>

#include "base/macros.h"
#include "base/observer_list.h"
#include "base/strings/string16.h"
#include "components/keyed_service/core/keyed_service.h"

class Browser;
class Profile;
class ConsentBumpActivator;

// The LoginUIService helps track per-profile information for the login related
// UIs - for example, whether there is login UI currently on-screen.
class LoginUIService : public KeyedService {
 public:
  // Various UI components implement this API to allow LoginUIService to
  // manipulate their associated login UI.
  class LoginUI {
   public:
    // Invoked when the login UI should be brought to the foreground.
    virtual void FocusUI() = 0;

   protected:
    virtual ~LoginUI() {}
  };

  // Used when the sync confirmation UI is closed to signify which option was
  // selected by the user.
  enum SyncConfirmationUIClosedResult {
    // Start sync immediately.
    SYNC_WITH_DEFAULT_SETTINGS,
    // Show the user the sync settings before starting sync.
    CONFIGURE_SYNC_FIRST,
    // The signing process was aborted, don't start sync or show settings.
    ABORT_SIGNIN,
  };

  // Interface for obervers of LoginUIService.
  class Observer {
   public:
    // Called when the sync confirmation UI is closed. |result| indicates the
    // option chosen by the user in the confirmation UI.
    virtual void OnSyncConfirmationUIClosed(
        SyncConfirmationUIClosedResult result) {}

   protected:
    virtual ~Observer() {}
  };

  explicit LoginUIService(Profile* profile);
  ~LoginUIService() override;

  // |observer| The observer to add or remove; cannot be NULL.
  void AddObserver(Observer* observer);
  void RemoveObserver(Observer* observer);

  // Gets the currently active login UI, or null if no login UI is active.
  LoginUI* current_login_ui() const;

  // Sets the currently active login UI. Callers must call LoginUIClosed when
  // |ui| is no longer valid.
  void SetLoginUI(LoginUI* ui);

  // Called when login UI is closed.
  void LoginUIClosed(LoginUI* ui);

  // Called when the sync confirmation UI is closed. |result| indicates the
  // option chosen by the user in the confirmation UI.
  void SyncConfirmationUIClosed(SyncConfirmationUIClosedResult result);

  // Delegate to an existing login dialog if one exists.
  // If not, we make a new popup dialog window, and set it to
  // chrome://signin to ask the user to sign in to chrome.
  void ShowLoginPopup();

  // Displays login results. This is either the Modal Signin Error dialog if
  // |error_message| is a non-empty string, or the User Menu with a blue header
  // toast otherwise.
  virtual void DisplayLoginResult(Browser* browser,
                                  const base::string16& error_message,
                                  const base::string16& email);

  // Set the profile blocking modal error dialog message.
  virtual void SetProfileBlockingErrorMessage();

  // Gets whether the Modal Signin Error dialog should display profile blocking
  // error message.
  bool IsDisplayingProfileBlockedErrorMessage() const;

  // Gets the last login result set through |DisplayLoginResult|.
  const base::string16& GetLastLoginResult() const;

  // Gets the last email used for signing in when a signin error occured; set
  // through |DisplayLoginResult|.
  const base::string16& GetLastLoginErrorEmail() const;

 private:
  // Weak pointers to the recently opened UIs, with the most recent in front.
  std::list<LoginUI*> ui_list_;
#if !defined(OS_CHROMEOS)
  Profile* profile_;
  std::unique_ptr<ConsentBumpActivator> consent_bump_activator_;
#endif

  // List of observers.
  base::ObserverList<Observer>::Unchecked observer_list_;

  base::string16 last_login_result_;
  base::string16 last_login_error_email_;
  bool is_displaying_profile_blocking_error_message_ = false;

  DISALLOW_COPY_AND_ASSIGN(LoginUIService);
};

#endif  // CHROME_BROWSER_UI_WEBUI_SIGNIN_LOGIN_UI_SERVICE_H_