1 // Copyright (c) 2012 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_CHROMEOS_LOGIN_LOGIN_UTILS_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_UTILS_H_ 7 8 #include <string> 9 10 #include "base/memory/ref_counted.h" 11 12 class CommandLine; 13 class GURL; 14 class PrefRegistrySimple; 15 class PrefService; 16 class Profile; 17 18 namespace chromeos { 19 20 class Authenticator; 21 class LoginDisplayHost; 22 class LoginStatusConsumer; 23 struct UserContext; 24 25 class LoginUtils { 26 public: 27 class Delegate { 28 public: 29 // Called after profile is loaded and prepared for the session. 30 virtual void OnProfilePrepared(Profile* profile) = 0; 31 32 #if defined(ENABLE_RLZ) 33 // Called after post-profile RLZ initialization. 34 virtual void OnRlzInitialized(Profile* profile) {} 35 #endif 36 protected: 37 virtual ~Delegate() {} 38 }; 39 40 // Registers log-in related preferences. 41 static void RegisterPrefs(PrefRegistrySimple* registry); 42 43 // Get LoginUtils singleton object. If it was not set before, new default 44 // instance will be created. 45 static LoginUtils* Get(); 46 47 // Set LoginUtils singleton object for test purpose only! 48 static void Set(LoginUtils* ptr); 49 50 // Checks if the given username is whitelisted and allowed to sign-in to 51 // this device. |wildcard_match| may be NULL. If it's present, it'll be set to 52 // true if the whitelist check was satisfied via a wildcard. 53 static bool IsWhitelisted(const std::string& username, bool* wildcard_match); 54 55 virtual ~LoginUtils() {} 56 57 // Thin wrapper around StartupBrowserCreator::LaunchBrowser(). Meant to be 58 // used in a Task posted to the UI thread. Once the browser is launched the 59 // login host is deleted. 60 virtual void DoBrowserLaunch(Profile* profile, 61 LoginDisplayHost* login_host) = 0; 62 63 // Loads and prepares profile for the session. Fires |delegate| in the end. 64 // If |pending_requests| is true, there's a pending online auth request. 65 // If |display_email| is not empty, user's displayed email will be set to 66 // this value, shown in UI. 67 // |user_context.username_hash| defines when user homedir is mounted. 68 // Also see DelegateDeleted method. 69 // If |has_active_session| is true than this is a case of restoring user 70 // session after browser crash so no need to start new session. 71 virtual void PrepareProfile( 72 const UserContext& user_context, 73 const std::string& display_email, 74 bool has_cookies, 75 bool has_active_session, 76 Delegate* delegate) = 0; 77 78 // Invalidates |delegate|, which was passed to PrepareProfile method call. 79 virtual void DelegateDeleted(Delegate* delegate) = 0; 80 81 // Invoked after the tmpfs is successfully mounted. 82 // Asks session manager to restart Chrome in Browse Without Sign In mode. 83 // |start_url| is url for launched browser to open. 84 virtual void CompleteOffTheRecordLogin(const GURL& start_url) = 0; 85 86 // Invoked when the user is logging in for the first time, or is logging in as 87 // a guest user. 88 virtual void SetFirstLoginPrefs(PrefService* prefs) = 0; 89 90 // Creates and returns the authenticator to use. 91 // Before WebUI login (Up to R14) the caller owned the returned 92 // Authenticator instance and had to delete it when done. 93 // New instance was created on each new login attempt. 94 // Starting with WebUI login (R15) single Authenticator instance is used for 95 // entire login process, even for multiple retries. Authenticator instance 96 // holds reference to login profile and is later used during fetching of 97 // OAuth tokens. 98 // TODO(nkostylev): Cleanup after WebUI login migration is complete. 99 virtual scoped_refptr<Authenticator> CreateAuthenticator( 100 LoginStatusConsumer* consumer) = 0; 101 102 // Restores authentication session after crash. 103 virtual void RestoreAuthenticationSession(Profile* profile) = 0; 104 105 // Initialize RLZ. 106 virtual void InitRlzDelayed(Profile* user_profile) = 0; 107 }; 108 109 } // namespace chromeos 110 111 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_UTILS_H_ 112