Update To 11.40.268.0
[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/callback_forward.h"
11 #include "base/memory/ref_counted.h"
12
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 AuthStatusConsumer;
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     // |browser_launched| will be true is browser has been launched, otherwise
33     // it will return false and client is responsible on launching browser.
34     virtual void OnProfilePrepared(Profile* profile,
35                                    bool browser_launched) = 0;
36
37 #if defined(ENABLE_RLZ)
38     // Called after post-profile RLZ initialization.
39     virtual void OnRlzInitialized() {}
40 #endif
41    protected:
42     virtual ~Delegate() {}
43   };
44
45   // Get LoginUtils singleton object. If it was not set before, new default
46   // instance will be created.
47   static LoginUtils* Get();
48
49   // Set LoginUtils singleton object for test purpose only!
50   static void Set(LoginUtils* ptr);
51
52   // Checks if the given username is whitelisted and allowed to sign-in to
53   // this device. |wildcard_match| may be NULL. If it's present, it'll be set to
54   // true if the whitelist check was satisfied via a wildcard.
55   static bool IsWhitelisted(const std::string& username, bool* wildcard_match);
56
57   virtual ~LoginUtils() {}
58
59   // Thin wrapper around StartupBrowserCreator::LaunchBrowser().  Meant to be
60   // used in a Task posted to the UI thread.  Once the browser is launched the
61   // login host is deleted.
62   virtual void DoBrowserLaunch(Profile* profile,
63                                LoginDisplayHost* login_host) = 0;
64
65   // Loads and prepares profile for the session. Fires |delegate| in the end.
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       bool has_auth_cookies,
73       bool has_active_session,
74       Delegate* delegate) = 0;
75
76   // Invalidates |delegate|, which was passed to PrepareProfile method call.
77   virtual void DelegateDeleted(Delegate* delegate) = 0;
78
79   // Creates and returns the authenticator to use.
80   // Before WebUI login (Up to R14) the caller owned the returned
81   // Authenticator instance and had to delete it when done.
82   // New instance was created on each new login attempt.
83   // Starting with WebUI login (R15) single Authenticator instance is used for
84   // entire login process, even for multiple retries. Authenticator instance
85   // holds reference to login profile and is later used during fetching of
86   // OAuth tokens.
87   // TODO(nkostylev): Cleanup after WebUI login migration is complete.
88   virtual scoped_refptr<Authenticator> CreateAuthenticator(
89       AuthStatusConsumer* consumer) = 0;
90
91   // Initiates process restart if needed.
92   // |early_restart| is true if this restart attempt happens before user profile
93   // is fully initialized.
94   // Might not return if restart is possible right now.
95   // Returns true if restart was scheduled.
96   // Returns false if no restart is needed,
97   virtual bool RestartToApplyPerSessionFlagsIfNeed(Profile* profile,
98                                                    bool early_restart) = 0;
99 };
100
101 }  // namespace chromeos
102
103 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_UTILS_H_