OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_UTILS_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_UTILS_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_UTILS_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_UTILS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 | 11 |
12 class GURL; | 12 class GURL; |
13 class PrefRegistrySimple; | |
14 class PrefService; | 13 class PrefService; |
15 class Profile; | 14 class Profile; |
16 | 15 |
17 namespace base { | 16 namespace base { |
18 class CommandLine; | 17 class CommandLine; |
19 } | 18 } |
20 | 19 |
21 namespace chromeos { | 20 namespace chromeos { |
22 | 21 |
23 class Authenticator; | 22 class Authenticator; |
24 class LoginDisplayHost; | 23 class LoginDisplayHost; |
25 class LoginStatusConsumer; | 24 class LoginStatusConsumer; |
26 class UserContext; | 25 class UserContext; |
27 | 26 |
28 class LoginUtils { | 27 class LoginUtils { |
29 public: | 28 public: |
30 class Delegate { | 29 class Delegate { |
31 public: | 30 public: |
32 // Called after profile is loaded and prepared for the session. | 31 // Called after profile is loaded and prepared for the session. |
33 virtual void OnProfilePrepared(Profile* profile) = 0; | 32 virtual void OnProfilePrepared(Profile* profile) = 0; |
34 | 33 |
35 #if defined(ENABLE_RLZ) | 34 #if defined(ENABLE_RLZ) |
36 // Called after post-profile RLZ initialization. | 35 // Called after post-profile RLZ initialization. |
37 virtual void OnRlzInitialized(Profile* profile) {} | 36 virtual void OnRlzInitialized() {} |
38 #endif | 37 #endif |
39 protected: | 38 protected: |
40 virtual ~Delegate() {} | 39 virtual ~Delegate() {} |
41 }; | 40 }; |
42 | 41 |
43 // Registers log-in related preferences. | |
44 static void RegisterPrefs(PrefRegistrySimple* registry); | |
45 | |
46 // Get LoginUtils singleton object. If it was not set before, new default | 42 // Get LoginUtils singleton object. If it was not set before, new default |
47 // instance will be created. | 43 // instance will be created. |
48 static LoginUtils* Get(); | 44 static LoginUtils* Get(); |
49 | 45 |
50 // Set LoginUtils singleton object for test purpose only! | 46 // Set LoginUtils singleton object for test purpose only! |
51 static void Set(LoginUtils* ptr); | 47 static void Set(LoginUtils* ptr); |
52 | 48 |
53 // Checks if the given username is whitelisted and allowed to sign-in to | 49 // Checks if the given username is whitelisted and allowed to sign-in to |
54 // this device. |wildcard_match| may be NULL. If it's present, it'll be set to | 50 // this device. |wildcard_match| may be NULL. If it's present, it'll be set to |
55 // true if the whitelist check was satisfied via a wildcard. | 51 // true if the whitelist check was satisfied via a wildcard. |
56 static bool IsWhitelisted(const std::string& username, bool* wildcard_match); | 52 static bool IsWhitelisted(const std::string& username, bool* wildcard_match); |
57 | 53 |
58 virtual ~LoginUtils() {} | 54 virtual ~LoginUtils() {} |
59 | 55 |
60 // Thin wrapper around StartupBrowserCreator::LaunchBrowser(). Meant to be | 56 // Thin wrapper around StartupBrowserCreator::LaunchBrowser(). Meant to be |
61 // used in a Task posted to the UI thread. Once the browser is launched the | 57 // used in a Task posted to the UI thread. Once the browser is launched the |
62 // login host is deleted. | 58 // login host is deleted. |
63 virtual void DoBrowserLaunch(Profile* profile, | 59 virtual void DoBrowserLaunch(Profile* profile, |
64 LoginDisplayHost* login_host) = 0; | 60 LoginDisplayHost* login_host) = 0; |
65 | 61 |
66 // Loads and prepares profile for the session. Fires |delegate| in the end. | 62 // Loads and prepares profile for the session. Fires |delegate| in the end. |
67 // If |display_email| is not empty, user's displayed email will be set to | |
68 // this value, shown in UI. | |
69 // |user_context.username_hash| defines when user homedir is mounted. | 63 // |user_context.username_hash| defines when user homedir is mounted. |
70 // Also see DelegateDeleted method. | 64 // Also see DelegateDeleted method. |
71 // If |has_active_session| is true than this is a case of restoring user | 65 // If |has_active_session| is true than this is a case of restoring user |
72 // session after browser crash so no need to start new session. | 66 // session after browser crash so no need to start new session. |
73 virtual void PrepareProfile( | 67 virtual void PrepareProfile( |
74 const UserContext& user_context, | 68 const UserContext& user_context, |
75 const std::string& display_email, | |
76 bool has_cookies, | 69 bool has_cookies, |
77 bool has_active_session, | 70 bool has_active_session, |
78 Delegate* delegate) = 0; | 71 Delegate* delegate) = 0; |
79 | 72 |
80 // Invalidates |delegate|, which was passed to PrepareProfile method call. | 73 // Invalidates |delegate|, which was passed to PrepareProfile method call. |
81 virtual void DelegateDeleted(Delegate* delegate) = 0; | 74 virtual void DelegateDeleted(Delegate* delegate) = 0; |
82 | 75 |
83 // Invoked after the tmpfs is successfully mounted. | 76 // Invoked after the tmpfs is successfully mounted. |
84 // Asks session manager to restart Chrome in Browse Without Sign In mode. | 77 // Asks session manager to restart Chrome in Browse Without Sign In mode. |
85 // |start_url| is url for launched browser to open. | 78 // |start_url| is url for launched browser to open. |
86 virtual void CompleteOffTheRecordLogin(const GURL& start_url) = 0; | 79 virtual void CompleteOffTheRecordLogin(const GURL& start_url) = 0; |
87 | 80 |
88 // Invoked when the user is logging in for the first time, or is logging in as | |
89 // a guest user. | |
90 virtual void SetFirstLoginPrefs(PrefService* prefs) = 0; | |
91 | |
92 // Creates and returns the authenticator to use. | 81 // Creates and returns the authenticator to use. |
93 // Before WebUI login (Up to R14) the caller owned the returned | 82 // Before WebUI login (Up to R14) the caller owned the returned |
94 // Authenticator instance and had to delete it when done. | 83 // Authenticator instance and had to delete it when done. |
95 // New instance was created on each new login attempt. | 84 // New instance was created on each new login attempt. |
96 // Starting with WebUI login (R15) single Authenticator instance is used for | 85 // Starting with WebUI login (R15) single Authenticator instance is used for |
97 // entire login process, even for multiple retries. Authenticator instance | 86 // entire login process, even for multiple retries. Authenticator instance |
98 // holds reference to login profile and is later used during fetching of | 87 // holds reference to login profile and is later used during fetching of |
99 // OAuth tokens. | 88 // OAuth tokens. |
100 // TODO(nkostylev): Cleanup after WebUI login migration is complete. | 89 // TODO(nkostylev): Cleanup after WebUI login migration is complete. |
101 virtual scoped_refptr<Authenticator> CreateAuthenticator( | 90 virtual scoped_refptr<Authenticator> CreateAuthenticator( |
102 LoginStatusConsumer* consumer) = 0; | 91 LoginStatusConsumer* consumer) = 0; |
103 | |
104 // Restores authentication session after crash. | |
105 virtual void RestoreAuthenticationSession(Profile* profile) = 0; | |
106 | |
107 // Initialize RLZ. | |
108 virtual void InitRlzDelayed(Profile* user_profile) = 0; | |
109 }; | 92 }; |
110 | 93 |
111 } // namespace chromeos | 94 } // namespace chromeos |
112 | 95 |
113 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_UTILS_H_ | 96 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_UTILS_H_ |
OLD | NEW |