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/callback_forward.h" 11#include "base/memory/ref_counted.h" 12 13class GURL; 14class PrefService; 15class Profile; 16 17namespace base { 18class CommandLine; 19} 20 21namespace chromeos { 22 23class Authenticator; 24class LoginDisplayHost; 25class AuthStatusConsumer; 26class UserContext; 27 28class LoginUtils { 29 public: 30 class Delegate { 31 public: 32 // Called after profile is loaded and prepared for the session. 33 virtual void OnProfilePrepared(Profile* profile) = 0; 34 35#if defined(ENABLE_RLZ) 36 // Called after post-profile RLZ initialization. 37 virtual void OnRlzInitialized() {} 38#endif 39 protected: 40 virtual ~Delegate() {} 41 }; 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 // Switch to the locale that |profile| wishes to use and invoke |callback|. 58 virtual void RespectLocalePreference(Profile* profile, 59 const base::Closure& callback) = 0; 60 61 // Thin wrapper around StartupBrowserCreator::LaunchBrowser(). Meant to be 62 // used in a Task posted to the UI thread. Once the browser is launched the 63 // login host is deleted. 64 virtual void DoBrowserLaunch(Profile* profile, 65 LoginDisplayHost* login_host) = 0; 66 67 // Loads and prepares profile for the session. Fires |delegate| in the end. 68 // |user_context.username_hash| defines when user homedir is mounted. 69 // Also see DelegateDeleted method. 70 // If |has_active_session| is true than this is a case of restoring user 71 // session after browser crash so no need to start new session. 72 virtual void PrepareProfile( 73 const UserContext& user_context, 74 bool has_auth_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 // Creates and returns the authenticator to use. 87 // Before WebUI login (Up to R14) the caller owned the returned 88 // Authenticator instance and had to delete it when done. 89 // New instance was created on each new login attempt. 90 // Starting with WebUI login (R15) single Authenticator instance is used for 91 // entire login process, even for multiple retries. Authenticator instance 92 // holds reference to login profile and is later used during fetching of 93 // OAuth tokens. 94 // TODO(nkostylev): Cleanup after WebUI login migration is complete. 95 virtual scoped_refptr<Authenticator> CreateAuthenticator( 96 AuthStatusConsumer* consumer) = 0; 97 98 // Initiates process restart if needed. 99 // |early_restart| is true if this restart attempt happens before user profile 100 // is fully initialized. 101 // Might not return if restart is possible right now. 102 // Returns true if restart was scheduled. 103 // Returns false if no restart is needed, 104 virtual bool RestartToApplyPerSessionFlagsIfNeed(Profile* profile, 105 bool early_restart) = 0; 106}; 107 108} // namespace chromeos 109 110#endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_UTILS_H_ 111