summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/webui/signin/login_ui_service.h
blob: d15efe7d2bc4b5a36166c796ae96e8f8aa01cf23 (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
// 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 "base/basictypes.h"
#include "base/observer_list.h"
#include "base/strings/string16.h"
#include "components/keyed_service/core/keyed_service.h"

class Browser;
class Profile;

// 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;

    // Invoked when the login UI should be closed. This can be invoked if the
    // user takes an action that should display new login UI.
    virtual void CloseUI() = 0;
   protected:
    virtual ~LoginUI() {}
  };

  // Interface for obervers of LoginUIService.
  class Observer {
   public:
    // Called when a new login UI is shown.
    // |ui| The login UI that was just shown. Will never be null.
    virtual void OnLoginUIShown(LoginUI* ui) {}

    // Called when a login UI is closed.
    // |ui| The login UI that was just closed; will never be null.
    virtual void OnLoginUIClosed(LoginUI* ui) {}

    // Called when the sync confirmation UI is closed. |configure_sync_first|
    // is true if the user has requested to configure the sync settings before
    // sync starts.
    virtual void OnSyncConfirmationUIClosed(bool configure_sync_first) {}

    // Called when a confirmation UI for untrusted signin is shown.
    virtual void OnUntrustedLoginUIShown() {}

   protected:
    virtual ~Observer() {}
  };

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

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

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

  // Sets the currently active login UI. It is illegal to call this if there is
  // already login UI visible.
  void SetLoginUI(LoginUI* ui);

  // Called when login UI is closed. If the passed UI is the current login UI,
  // sets current_login_ui() to null.
  void LoginUIClosed(LoginUI* ui);

  // Called when the sync settings confirmation UI is closed.
  void SyncConfirmationUIClosed(bool configure_sync_first);

  // Called when a confirmation UI for untrusted signin is shown.
  void UntrustedLoginUIShown();

  // 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.
  void DisplayLoginResult(Browser* browser, const base::string16& message);

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

 private:
  // Weak pointer to the currently active login UI, or null if none.
  LoginUI* ui_;
  Profile* profile_;

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

  base::string16 last_login_result_;

  DISALLOW_COPY_AND_ASSIGN(LoginUIService);
};

#endif  // CHROME_BROWSER_UI_WEBUI_SIGNIN_LOGIN_UI_SERVICE_H_