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 GURL;
     13 class PrefService;
     14 class Profile;
     15 
     16 namespace base {
     17 class CommandLine;
     18 }
     19 
     20 namespace chromeos {
     21 
     22 class Authenticator;
     23 class LoginDisplayHost;
     24 class LoginStatusConsumer;
     25 class UserContext;
     26 
     27 class LoginUtils {
     28  public:
     29   class Delegate {
     30    public:
     31     // Called after profile is loaded and prepared for the session.
     32     virtual void OnProfilePrepared(Profile* profile) = 0;
     33 
     34 #if defined(ENABLE_RLZ)
     35     // Called after post-profile RLZ initialization.
     36     virtual void OnRlzInitialized() {}
     37 #endif
     38    protected:
     39     virtual ~Delegate() {}
     40   };
     41 
     42   // Get LoginUtils singleton object. If it was not set before, new default
     43   // instance will be created.
     44   static LoginUtils* Get();
     45 
     46   // Set LoginUtils singleton object for test purpose only!
     47   static void Set(LoginUtils* ptr);
     48 
     49   // Checks if the given username is whitelisted and allowed to sign-in to
     50   // this device. |wildcard_match| may be NULL. If it's present, it'll be set to
     51   // true if the whitelist check was satisfied via a wildcard.
     52   static bool IsWhitelisted(const std::string& username, bool* wildcard_match);
     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   // |user_context.username_hash| defines when user homedir is mounted.
     64   // Also see DelegateDeleted method.
     65   // If |has_active_session| is true than this is a case of restoring user
     66   // session after browser crash so no need to start new session.
     67   virtual void PrepareProfile(
     68       const UserContext& user_context,
     69       bool has_cookies,
     70       bool has_active_session,
     71       Delegate* delegate) = 0;
     72 
     73   // Invalidates |delegate|, which was passed to PrepareProfile method call.
     74   virtual void DelegateDeleted(Delegate* delegate) = 0;
     75 
     76   // Invoked after the tmpfs is successfully mounted.
     77   // Asks session manager to restart Chrome in Browse Without Sign In mode.
     78   // |start_url| is url for launched browser to open.
     79   virtual void CompleteOffTheRecordLogin(const GURL& start_url) = 0;
     80 
     81   // Creates and returns the authenticator to use.
     82   // Before WebUI login (Up to R14) the caller owned the returned
     83   // Authenticator instance and had to delete it when done.
     84   // New instance was created on each new login attempt.
     85   // Starting with WebUI login (R15) single Authenticator instance is used for
     86   // entire login process, even for multiple retries. Authenticator instance
     87   // holds reference to login profile and is later used during fetching of
     88   // OAuth tokens.
     89   // TODO(nkostylev): Cleanup after WebUI login migration is complete.
     90   virtual scoped_refptr<Authenticator> CreateAuthenticator(
     91       LoginStatusConsumer* consumer) = 0;
     92 };
     93 
     94 }  // namespace chromeos
     95 
     96 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_UTILS_H_
     97