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