summaryrefslogtreecommitdiffstats
path: root/chrome/browser/browser_signin.h
blob: a250d3b2c4a1b8c068a85b221a9042c272ab2c39 (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
// Copyright (c) 2011 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_BROWSER_SIGNIN_H_
#define CHROME_BROWSER_BROWSER_SIGNIN_H_
#pragma once

#include <string>

#include "base/memory/scoped_ptr.h"
#include "chrome/common/net/gaia/google_service_auth_error.h"
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"

class BrowserSigninHtml;
class Profile;
class ProfileSyncService;
class TabContents;

// The BrowserSignin class provides a login screen which allows the
// user to signin to the browser.  Currently the signin is coordinated
// through the Chrome Sync logic.
//
// TODO(johnnyg): Separate this from the sync logic and make it the
// sole co-ordinator of browser signin.
//
// This class should only be accessed on the UI thread.
class BrowserSignin : public NotificationObserver {
 public:
  explicit BrowserSignin(Profile* profile);
  virtual ~BrowserSignin();

  // The delegate class is invoked on success and failure.
  class SigninDelegate {
   public:
    virtual ~SigninDelegate() {}

    // The login was successful.
    virtual void OnLoginSuccess() = 0;

    // The login failed.
    virtual void OnLoginFailure(const GoogleServiceAuthError& error) = 0;
  };

  // Request that the user signin, modal to TabContents provided.
  // If a user is already signed in, this will show a login dialog where
  // the username is not editable.
  //
  // A custom HTML string can be provided that will be displayed next
  // to the signin dialog.
  //
  // Only one sign-in can be in process at a time; if there is one in
  // progress already it will be canceled in favor of this one.
  //
  // The delegate will eventually be called with OnLoginSuccess() or
  // OnLoginFailure(), but never both.  virtual for test override.
  virtual void RequestSignin(TabContents* tab_contents,
                             const string16& suggested_email,
                             const string16& login_message,
                             SigninDelegate* delegate);

  // Returns the username of the user currently signed in.  If no
  // user is signed in, returns the empty string.  virtual for test
  // override.
  virtual std::string GetSignedInUsername() const;

  // NotificationObserver implementation.
  virtual void Observe(int type,
                       const NotificationSource& source,
                       const NotificationDetails& details);

  ProfileSyncService* GetProfileSyncService() const;

  // Close the dialog.  Delegate's OnLoginFailure method will be called.
  void Cancel();

 private:
  // Create the HTML Dialog content.
  BrowserSigninHtml* CreateHtmlDialogUI();

  // When the dialog is closed.
  void OnLoginFinished();

  // Turn auth notifications on.
  void RegisterAuthNotifications();

  // Turn auth notifications off.
  void UnregisterAuthNotifications();

  // Show the dialog Tab-Modal.
  void ShowSigninTabModal(TabContents* tab_contents);

  // Non-owned pointer to the profile (which owns this object).
  Profile* profile_;

  // Suggested email for the current login prompt.
  string16 suggested_email_;

  // Current login message.
  string16 login_message_;

  // Delegate for the current sign in request.
  SigninDelegate* delegate_;

  // Current HTML Dialog information.  Pointer is owned by the WebUI it will be
  // attached to.
  BrowserSigninHtml* html_dialog_ui_delegate_;

  NotificationRegistrar registrar_;

  DISALLOW_COPY_AND_ASSIGN(BrowserSignin);
};


#endif  // CHROME_BROWSER_BROWSER_SIGNIN_H_