- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / login_utils.h
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 has_cookies,
74       bool has_active_session,
75       Delegate* delegate) = 0;
76
77   // Invalidates |delegate|, which was passed to PrepareProfile method call.
78   virtual void DelegateDeleted(Delegate* delegate) = 0;
79
80   // Invoked after the tmpfs is successfully mounted.
81   // Asks session manager to restart Chrome in Browse Without Sign In mode.
82   // |start_url| is url for launched browser to open.
83   virtual void CompleteOffTheRecordLogin(const GURL& start_url) = 0;
84
85   // Invoked when the user is logging in for the first time, or is logging in as
86   // a guest user.
87   virtual void SetFirstLoginPrefs(PrefService* prefs) = 0;
88
89   // Creates and returns the authenticator to use.
90   // Before WebUI login (Up to R14) the caller owned the returned
91   // Authenticator instance and had to delete it when done.
92   // New instance was created on each new login attempt.
93   // Starting with WebUI login (R15) single Authenticator instance is used for
94   // entire login process, even for multiple retries. Authenticator instance
95   // holds reference to login profile and is later used during fetching of
96   // OAuth tokens.
97   // TODO(nkostylev): Cleanup after WebUI login migration is complete.
98   virtual scoped_refptr<Authenticator> CreateAuthenticator(
99       LoginStatusConsumer* consumer) = 0;
100
101   // Restores authentication session after crash.
102   virtual void RestoreAuthenticationSession(Profile* profile) = 0;
103
104   // Initialize RLZ.
105   virtual void InitRlzDelayed(Profile* user_profile) = 0;
106 };
107
108 }  // namespace chromeos
109
110 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_UTILS_H_