OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/chromeos/login/login_utils.h" | 5 #include "chrome/browser/chromeos/login/login_utils.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 public: | 100 public: |
101 LoginUtilsImpl() | 101 LoginUtilsImpl() |
102 : browser_launch_enabled_(true) { | 102 : browser_launch_enabled_(true) { |
103 } | 103 } |
104 | 104 |
105 // Invoked after the user has successfully logged in. This launches a browser | 105 // Invoked after the user has successfully logged in. This launches a browser |
106 // and does other bookkeeping after logging in. | 106 // and does other bookkeeping after logging in. |
107 virtual void CompleteLogin( | 107 virtual void CompleteLogin( |
108 const std::string& username, | 108 const std::string& username, |
109 const std::string& password, | 109 const std::string& password, |
110 const GaiaAuthConsumer::ClientLoginResult& credentials); | 110 const GaiaAuthConsumer::ClientLoginResult& credentials, |
111 bool pending_requests); | |
111 | 112 |
112 // Invoked after the tmpfs is successfully mounted. | 113 // Invoked after the tmpfs is successfully mounted. |
113 // Launches a browser in the off the record (incognito) mode. | 114 // Launches a browser in the off the record (incognito) mode. |
114 virtual void CompleteOffTheRecordLogin(const GURL& start_url); | 115 virtual void CompleteOffTheRecordLogin(const GURL& start_url); |
115 | 116 |
116 // Invoked when the user is logging in for the first time, or is logging in as | 117 // Invoked when the user is logging in for the first time, or is logging in as |
117 // a guest user. | 118 // a guest user. |
118 virtual void SetFirstLoginPrefs(PrefService* prefs); | 119 virtual void SetFirstLoginPrefs(PrefService* prefs); |
119 | 120 |
120 // Creates and returns the authenticator to use. The caller owns the returned | 121 // Creates and returns the authenticator to use. The caller owns the returned |
121 // Authenticator and must delete it when done. | 122 // Authenticator and must delete it when done. |
122 virtual Authenticator* CreateAuthenticator(LoginStatusConsumer* consumer); | 123 virtual Authenticator* CreateAuthenticator(LoginStatusConsumer* consumer); |
123 | 124 |
124 // Used to postpone browser launch via DoBrowserLaunch() if some post | 125 // Used to postpone browser launch via DoBrowserLaunch() if some post |
125 // login screen is to be shown. | 126 // login screen is to be shown. |
126 virtual void EnableBrowserLaunch(bool enable); | 127 virtual void EnableBrowserLaunch(bool enable); |
127 | 128 |
128 // Returns if browser launch enabled now or not. | 129 // Returns if browser launch enabled now or not. |
129 virtual bool IsBrowserLaunchEnabled() const; | 130 virtual bool IsBrowserLaunchEnabled() const; |
130 | 131 |
131 // Warms the url used by authentication. | 132 // Warms the url used by authentication. |
132 virtual void PrewarmAuthentication(); | 133 virtual void PrewarmAuthentication(); |
133 | 134 |
135 // Given the credentials try to exchange them for | |
136 // full-fledged Google authentication cookies. | |
137 virtual void FetchCookies( | |
138 Profile* profile, | |
139 const GaiaAuthConsumer::ClientLoginResult& credentials); | |
140 | |
141 // Supply credentials for sync and others to use. | |
142 virtual void FetchTokens( | |
143 Profile* profile, | |
144 const GaiaAuthConsumer::ClientLoginResult& credentials); | |
145 | |
134 private: | 146 private: |
135 // Check user's profile for kApplicationLocale setting. | 147 // Check user's profile for kApplicationLocale setting. |
136 void RespectLocalePreference(PrefService* pref); | 148 void RespectLocalePreference(PrefService* pref); |
137 | 149 |
138 // Indicates if DoBrowserLaunch will actually launch the browser or not. | 150 // Indicates if DoBrowserLaunch will actually launch the browser or not. |
139 bool browser_launch_enabled_; | 151 bool browser_launch_enabled_; |
140 | 152 |
141 DISALLOW_COPY_AND_ASSIGN(LoginUtilsImpl); | 153 DISALLOW_COPY_AND_ASSIGN(LoginUtilsImpl); |
142 }; | 154 }; |
143 | 155 |
(...skipping 15 matching lines...) Expand all Loading... | |
159 private: | 171 private: |
160 Lock create_lock_; | 172 Lock create_lock_; |
161 scoped_ptr<LoginUtils> ptr_; | 173 scoped_ptr<LoginUtils> ptr_; |
162 | 174 |
163 DISALLOW_COPY_AND_ASSIGN(LoginUtilsWrapper); | 175 DISALLOW_COPY_AND_ASSIGN(LoginUtilsWrapper); |
164 }; | 176 }; |
165 | 177 |
166 void LoginUtilsImpl::CompleteLogin( | 178 void LoginUtilsImpl::CompleteLogin( |
167 const std::string& username, | 179 const std::string& username, |
168 const std::string& password, | 180 const std::string& password, |
169 const GaiaAuthConsumer::ClientLoginResult& credentials) { | 181 const GaiaAuthConsumer::ClientLoginResult& credentials, |
182 bool pending_requests) { | |
170 BootTimesLoader* btl = BootTimesLoader::Get(); | 183 BootTimesLoader* btl = BootTimesLoader::Get(); |
171 | 184 |
172 VLOG(1) << "Completing login for " << username; | 185 VLOG(1) << "Completing login for " << username; |
173 btl->AddLoginTimeMarker("CompletingLogin", false); | 186 btl->AddLoginTimeMarker("CompletingLogin", false); |
174 | 187 |
175 if (CrosLibrary::Get()->EnsureLoaded()) { | 188 if (CrosLibrary::Get()->EnsureLoaded()) { |
176 CrosLibrary::Get()->GetLoginLibrary()->StartSession(username, ""); | 189 CrosLibrary::Get()->GetLoginLibrary()->StartSession(username, ""); |
177 btl->AddLoginTimeMarker("StartedSession", false); | 190 btl->AddLoginTimeMarker("StartedSession", false); |
178 } | 191 } |
179 | 192 |
(...skipping 30 matching lines...) Expand all Loading... | |
210 // device policy. | 223 // device policy. |
211 net::ProxyConfigService* proxy_config_service = | 224 net::ProxyConfigService* proxy_config_service = |
212 new PrefProxyConfigService( | 225 new PrefProxyConfigService( |
213 profile->GetProxyConfigTracker(), | 226 profile->GetProxyConfigTracker(), |
214 new chromeos::ProxyConfigService( | 227 new chromeos::ProxyConfigService( |
215 profile->GetChromeOSProxyConfigServiceImpl())); | 228 profile->GetChromeOSProxyConfigServiceImpl())); |
216 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 229 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
217 new ResetDefaultProxyConfigServiceTask( | 230 new ResetDefaultProxyConfigServiceTask( |
218 proxy_config_service)); | 231 proxy_config_service)); |
219 | 232 |
220 // Take the credentials passed in and try to exchange them for | 233 // Since we're doing parallel authentication, only new user sign in |
221 // full-fledged Google authentication cookies. This is | 234 // would perform online auth before calling CompleteLogin. |
222 // best-effort; it's possible that we'll fail due to network | 235 // For existing users there's usually a pending online auth request. |
223 // troubles or some such. Either way, |cf| will call | 236 // Cookies will be fetched after it's is succeeded. |
224 // DoBrowserLaunch on the UI thread when it's done, and then | 237 if (!pending_requests) { |
Nikita (slow)
2010/12/03 16:52:42
Note:
When network is not connected, only online a
Nikita (slow)
2010/12/03 16:53:25
only offline auth would pass and pending_requests
Chris Masone
2010/12/03 18:47:38
They would not work, no. I'm pretty sure they're
| |
225 // delete itself. | 238 FetchCookies(profile, credentials); |
226 CookieFetcher* cf = new CookieFetcher(profile); | 239 } |
227 cf->AttemptFetch(credentials.data); | |
228 btl->AddLoginTimeMarker("CookieFetchStarted", false); | |
229 | 240 |
230 // Init extension event routers; this normally happens in browser_main | 241 // Init extension event routers; this normally happens in browser_main |
231 // but on Chrome OS it has to be deferred until the user finishes | 242 // but on Chrome OS it has to be deferred until the user finishes |
232 // logging in and the profile is not OTR. | 243 // logging in and the profile is not OTR. |
233 if (profile->GetExtensionsService() && | 244 if (profile->GetExtensionsService() && |
234 profile->GetExtensionsService()->extensions_enabled()) { | 245 profile->GetExtensionsService()->extensions_enabled()) { |
235 profile->GetExtensionsService()->InitEventRouters(); | 246 profile->GetExtensionsService()->InitEventRouters(); |
236 } | 247 } |
237 btl->AddLoginTimeMarker("ExtensionsServiceStarted", false); | 248 btl->AddLoginTimeMarker("ExtensionsServiceStarted", false); |
238 | 249 |
239 // Supply credentials for sync and others to use. Load tokens from disk. | 250 // Supply credentials for sync and others to use. Load tokens from disk. |
240 TokenService* token_service = profile->GetTokenService(); | 251 TokenService* token_service = profile->GetTokenService(); |
241 token_service->Initialize(GaiaConstants::kChromeOSSource, | 252 token_service->Initialize(GaiaConstants::kChromeOSSource, |
242 profile); | 253 profile); |
243 token_service->LoadTokensFromDB(); | 254 token_service->LoadTokensFromDB(); |
244 token_service->UpdateCredentials(credentials); | 255 |
245 if (token_service->AreCredentialsValid()) { | 256 // For existing users there's usually a pending online auth request. |
246 token_service->StartFetchingTokens(); | 257 // Tokens will be fetched after it's is succeeded. |
258 if (!pending_requests) { | |
259 FetchTokens(profile, credentials); | |
247 } | 260 } |
248 btl->AddLoginTimeMarker("TokensGotten", false); | 261 btl->AddLoginTimeMarker("TokensGotten", false); |
249 | 262 |
250 // Set the CrOS user by getting this constructor run with the | 263 // Set the CrOS user by getting this constructor run with the |
251 // user's email on first retrieval. | 264 // user's email on first retrieval. |
252 profile->GetProfileSyncService(username)->SetPassphrase(password, false); | 265 profile->GetProfileSyncService(username)->SetPassphrase(password, false); |
253 btl->AddLoginTimeMarker("SyncStarted", false); | 266 btl->AddLoginTimeMarker("SyncStarted", false); |
254 | 267 |
255 // Attempt to take ownership; this will fail if device is already owned. | 268 // Attempt to take ownership; this will fail if device is already owned. |
256 OwnershipService::GetSharedInstance()->StartTakeOwnershipAttempt( | 269 OwnershipService::GetSharedInstance()->StartTakeOwnershipAttempt( |
(...skipping 23 matching lines...) Expand all Loading... | |
280 // out when we get that done properly. | 293 // out when we get that done properly. |
281 // TODO(xiyuan): Remove this once enterprise feature is ready. | 294 // TODO(xiyuan): Remove this once enterprise feature is ready. |
282 if (EndsWith(username, "@google.com", true)) { | 295 if (EndsWith(username, "@google.com", true)) { |
283 PrefService* pref_service = profile->GetPrefs(); | 296 PrefService* pref_service = profile->GetPrefs(); |
284 pref_service->SetBoolean(prefs::kEnableScreenLock, true); | 297 pref_service->SetBoolean(prefs::kEnableScreenLock, true); |
285 } | 298 } |
286 | 299 |
287 DoBrowserLaunch(profile); | 300 DoBrowserLaunch(profile); |
288 } | 301 } |
289 | 302 |
303 void LoginUtilsImpl::FetchCookies( | |
304 Profile* profile, | |
305 const GaiaAuthConsumer::ClientLoginResult& credentials) { | |
306 // Take the credentials passed in and try to exchange them for | |
307 // full-fledged Google authentication cookies. This is | |
308 // best-effort; it's possible that we'll fail due to network | |
309 // troubles or some such. | |
310 // CookieFetcher will delete itself once done. | |
311 CookieFetcher* cf = new CookieFetcher(profile); | |
312 cf->AttemptFetch(credentials.data); | |
313 BootTimesLoader::Get()->AddLoginTimeMarker("CookieFetchStarted", false); | |
314 } | |
315 | |
316 void LoginUtilsImpl::FetchTokens( | |
317 Profile* profile, | |
318 const GaiaAuthConsumer::ClientLoginResult& credentials) { | |
319 TokenService* token_service = profile->GetTokenService(); | |
320 token_service->UpdateCredentials(credentials); | |
321 if (token_service->AreCredentialsValid()) { | |
322 token_service->StartFetchingTokens(); | |
323 } | |
324 } | |
325 | |
290 void LoginUtilsImpl::RespectLocalePreference(PrefService* pref) { | 326 void LoginUtilsImpl::RespectLocalePreference(PrefService* pref) { |
291 std::string pref_locale = pref->GetString(prefs::kApplicationLocale); | 327 std::string pref_locale = pref->GetString(prefs::kApplicationLocale); |
292 if (pref_locale.empty()) { | 328 if (pref_locale.empty()) { |
293 // TODO(dilmah): current code will clobber existing setting in case | 329 // TODO(dilmah): current code will clobber existing setting in case |
294 // language preference was set via another device | 330 // language preference was set via another device |
295 // but still not synced yet. Profile is not synced at this point yet. | 331 // but still not synced yet. Profile is not synced at this point yet. |
296 pref->SetString(prefs::kApplicationLocale, | 332 pref->SetString(prefs::kApplicationLocale, |
297 g_browser_process->GetApplicationLocale()); | 333 g_browser_process->GetApplicationLocale()); |
298 } else { | 334 } else { |
299 LanguageSwitchMenu::SwitchLanguage(pref_locale); | 335 LanguageSwitchMenu::SwitchLanguage(pref_locale); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
475 BrowserInit browser_init; | 511 BrowserInit browser_init; |
476 int return_code; | 512 int return_code; |
477 browser_init.LaunchBrowser(*CommandLine::ForCurrentProcess(), | 513 browser_init.LaunchBrowser(*CommandLine::ForCurrentProcess(), |
478 profile, | 514 profile, |
479 FilePath(), | 515 FilePath(), |
480 true, | 516 true, |
481 &return_code); | 517 &return_code); |
482 } | 518 } |
483 | 519 |
484 } // namespace chromeos | 520 } // namespace chromeos |
OLD | NEW |