1// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_BROWSER_SIGNIN_H_ 6#define CHROME_BROWSER_BROWSER_SIGNIN_H_ 7#pragma once 8 9#include <string> 10 11#include "base/memory/scoped_ptr.h" 12#include "chrome/common/net/gaia/google_service_auth_error.h" 13#include "content/common/notification_observer.h" 14#include "content/common/notification_registrar.h" 15 16class BrowserSigninHtml; 17class Profile; 18class ProfileSyncService; 19class TabContents; 20 21// The BrowserSignin class provides a login screen which allows the 22// user to signin to the browser. Currently the signin is coordinated 23// through the Chrome Sync logic. 24// 25// TODO(johnnyg): Separate this from the sync logic and make it the 26// sole co-ordinator of browser signin. 27// 28// This class should only be accessed on the UI thread. 29class BrowserSignin : public NotificationObserver { 30 public: 31 explicit BrowserSignin(Profile* profile); 32 virtual ~BrowserSignin(); 33 34 // The delegate class is invoked on success and failure. 35 class SigninDelegate { 36 public: 37 virtual ~SigninDelegate() {} 38 39 // The login was successful. 40 virtual void OnLoginSuccess() = 0; 41 42 // The login failed. 43 virtual void OnLoginFailure(const GoogleServiceAuthError& error) = 0; 44 }; 45 46 // Request that the user signin, modal to TabContents provided. 47 // If a user is already signed in, this will show a login dialog where 48 // the username is not editable. 49 // 50 // A custom HTML string can be provided that will be displayed next 51 // to the signin dialog. 52 // 53 // Only one sign-in can be in process at a time; if there is one in 54 // progress already it will be canceled in favor of this one. 55 // 56 // The delegate will eventually be called with OnLoginSuccess() or 57 // OnLoginFailure(), but never both. virtual for test override. 58 virtual void RequestSignin(TabContents* tab_contents, 59 const string16& suggested_email, 60 const string16& login_message, 61 SigninDelegate* delegate); 62 63 // Returns the username of the user currently signed in. If no 64 // user is signed in, returns the empty string. virtual for test 65 // override. 66 virtual std::string GetSignedInUsername() const; 67 68 // NotificationObserver implementation. 69 virtual void Observe(NotificationType type, 70 const NotificationSource& source, 71 const NotificationDetails& details); 72 73 ProfileSyncService* GetProfileSyncService() const; 74 75 // Close the dialog. Delegate's OnLoginFailure method will be called. 76 void Cancel(); 77 78 private: 79 // Create the HTML Dialog content. 80 BrowserSigninHtml* CreateHtmlDialogUI(); 81 82 // When the dialog is closed. 83 void OnLoginFinished(); 84 85 // Turn auth notifications on. 86 void RegisterAuthNotifications(); 87 88 // Turn auth notifications off. 89 void UnregisterAuthNotifications(); 90 91 // Show the dialog Tab-Modal. 92 void ShowSigninTabModal(TabContents* tab_contents); 93 94 // Non-owned pointer to the profile (which owns this object). 95 Profile* profile_; 96 97 // Suggested email for the current login prompt. 98 string16 suggested_email_; 99 100 // Current login message. 101 string16 login_message_; 102 103 // Delegate for the current sign in request. 104 SigninDelegate* delegate_; 105 106 // Current HTML Dialog information. Pointer is owned by the WebUI it will be 107 // attached to. 108 BrowserSigninHtml* html_dialog_ui_delegate_; 109 110 NotificationRegistrar registrar_; 111 112 DISALLOW_COPY_AND_ASSIGN(BrowserSignin); 113}; 114 115 116#endif // CHROME_BROWSER_BROWSER_SIGNIN_H_ 117