Home | History | Annotate | Download | only in login
      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 Profile;
     15 class PrefRegistrySimple;
     16 class PrefService;
     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.
     52   static bool IsWhitelisted(const std::string& username);
     53 
     54   virtual ~LoginUtils() {}
     55 
     56   // Thin wrapper around StartupBrowserCreator::LaunchBrowser().  Meant to be
     57   // used in a Task posted to the UI thread.  Once the browser is launched the
     58   // login host is deleted.
     59   virtual void DoBrowserLaunch(Profile* profile,
     60                                LoginDisplayHost* login_host) = 0;
     61 
     62   // Loads and prepares profile for the session. Fires |delegate| in the end.
     63   // If |pending_requests| is true, there's a pending online auth request.
     64   // If |display_email| is not empty, user's displayed email will be set to
     65   // this value, shown in UI.
     66   // |user_context.username_hash| defines when user homedir is mounted.
     67   // Also see DelegateDeleted method.
     68   // If |has_active_session| is true than this is a case of restoring user
     69   // session after browser crash so no need to start new session.
     70   virtual void PrepareProfile(
     71       const UserContext& user_context,
     72       const std::string& display_email,
     73       bool using_oauth,
     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   // Stops background fetchers.
    106   virtual void StopBackgroundFetchers() = 0;
    107 
    108   // Initialize RLZ.
    109   virtual void InitRlzDelayed(Profile* user_profile) = 0;
    110 };
    111 
    112 }  // namespace chromeos
    113 
    114 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_UTILS_H_
    115