Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: chrome/browser/chromeos/login/login_utils.cc

Issue 5641001: [cros] Fetch cookies after online authentication is successful. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 21 matching lines...) Expand all
165 177
166 Lock create_lock_; 178 Lock create_lock_;
167 scoped_ptr<LoginUtils> ptr_; 179 scoped_ptr<LoginUtils> ptr_;
168 180
169 DISALLOW_COPY_AND_ASSIGN(LoginUtilsWrapper); 181 DISALLOW_COPY_AND_ASSIGN(LoginUtilsWrapper);
170 }; 182 };
171 183
172 void LoginUtilsImpl::CompleteLogin( 184 void LoginUtilsImpl::CompleteLogin(
173 const std::string& username, 185 const std::string& username,
174 const std::string& password, 186 const std::string& password,
175 const GaiaAuthConsumer::ClientLoginResult& credentials) { 187 const GaiaAuthConsumer::ClientLoginResult& credentials,
188 bool pending_requests) {
176 BootTimesLoader* btl = BootTimesLoader::Get(); 189 BootTimesLoader* btl = BootTimesLoader::Get();
177 190
178 VLOG(1) << "Completing login for " << username; 191 VLOG(1) << "Completing login for " << username;
179 btl->AddLoginTimeMarker("CompletingLogin", false); 192 btl->AddLoginTimeMarker("CompletingLogin", false);
180 193
181 if (CrosLibrary::Get()->EnsureLoaded()) { 194 if (CrosLibrary::Get()->EnsureLoaded()) {
182 CrosLibrary::Get()->GetLoginLibrary()->StartSession(username, ""); 195 CrosLibrary::Get()->GetLoginLibrary()->StartSession(username, "");
183 btl->AddLoginTimeMarker("StartedSession", false); 196 btl->AddLoginTimeMarker("StartedSession", false);
184 } 197 }
185 198
(...skipping 30 matching lines...) Expand all
216 // device policy. 229 // device policy.
217 net::ProxyConfigService* proxy_config_service = 230 net::ProxyConfigService* proxy_config_service =
218 new PrefProxyConfigService( 231 new PrefProxyConfigService(
219 profile->GetProxyConfigTracker(), 232 profile->GetProxyConfigTracker(),
220 new chromeos::ProxyConfigService( 233 new chromeos::ProxyConfigService(
221 profile->GetChromeOSProxyConfigServiceImpl())); 234 profile->GetChromeOSProxyConfigServiceImpl()));
222 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 235 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
223 new ResetDefaultProxyConfigServiceTask( 236 new ResetDefaultProxyConfigServiceTask(
224 proxy_config_service)); 237 proxy_config_service));
225 238
226 // Take the credentials passed in and try to exchange them for 239 // Since we're doing parallel authentication, only new user sign in
227 // full-fledged Google authentication cookies. This is 240 // would perform online auth before calling CompleteLogin.
228 // best-effort; it's possible that we'll fail due to network 241 // For existing users there's usually a pending online auth request.
229 // troubles or some such. Either way, |cf| will call 242 // Cookies will be fetched after it's is succeeded.
230 // DoBrowserLaunch on the UI thread when it's done, and then 243 if (!pending_requests) {
231 // delete itself. 244 FetchCookies(profile, credentials);
232 CookieFetcher* cf = new CookieFetcher(profile); 245 }
233 cf->AttemptFetch(credentials.data);
234 btl->AddLoginTimeMarker("CookieFetchStarted", false);
235 246
236 // Init extension event routers; this normally happens in browser_main 247 // Init extension event routers; this normally happens in browser_main
237 // but on Chrome OS it has to be deferred until the user finishes 248 // but on Chrome OS it has to be deferred until the user finishes
238 // logging in and the profile is not OTR. 249 // logging in and the profile is not OTR.
239 if (profile->GetExtensionsService() && 250 if (profile->GetExtensionsService() &&
240 profile->GetExtensionsService()->extensions_enabled()) { 251 profile->GetExtensionsService()->extensions_enabled()) {
241 profile->GetExtensionsService()->InitEventRouters(); 252 profile->GetExtensionsService()->InitEventRouters();
242 } 253 }
243 btl->AddLoginTimeMarker("ExtensionsServiceStarted", false); 254 btl->AddLoginTimeMarker("ExtensionsServiceStarted", false);
244 255
245 // Supply credentials for sync and others to use. Load tokens from disk. 256 // Supply credentials for sync and others to use. Load tokens from disk.
246 TokenService* token_service = profile->GetTokenService(); 257 TokenService* token_service = profile->GetTokenService();
247 token_service->Initialize(GaiaConstants::kChromeOSSource, 258 token_service->Initialize(GaiaConstants::kChromeOSSource,
248 profile); 259 profile);
249 token_service->LoadTokensFromDB(); 260 token_service->LoadTokensFromDB();
250 token_service->UpdateCredentials(credentials); 261
251 if (token_service->AreCredentialsValid()) { 262 // For existing users there's usually a pending online auth request.
252 token_service->StartFetchingTokens(); 263 // Tokens will be fetched after it's is succeeded.
264 if (!pending_requests) {
265 FetchTokens(profile, credentials);
253 } 266 }
254 btl->AddLoginTimeMarker("TokensGotten", false); 267 btl->AddLoginTimeMarker("TokensGotten", false);
255 268
256 // Set the CrOS user by getting this constructor run with the 269 // Set the CrOS user by getting this constructor run with the
257 // user's email on first retrieval. 270 // user's email on first retrieval.
258 profile->GetProfileSyncService(username)->SetPassphrase(password, false); 271 profile->GetProfileSyncService(username)->SetPassphrase(password, false);
259 btl->AddLoginTimeMarker("SyncStarted", false); 272 btl->AddLoginTimeMarker("SyncStarted", false);
260 273
261 // Attempt to take ownership; this will fail if device is already owned. 274 // Attempt to take ownership; this will fail if device is already owned.
262 OwnershipService::GetSharedInstance()->StartTakeOwnershipAttempt( 275 OwnershipService::GetSharedInstance()->StartTakeOwnershipAttempt(
(...skipping 23 matching lines...) Expand all
286 // out when we get that done properly. 299 // out when we get that done properly.
287 // TODO(xiyuan): Remove this once enterprise feature is ready. 300 // TODO(xiyuan): Remove this once enterprise feature is ready.
288 if (EndsWith(username, "@google.com", true)) { 301 if (EndsWith(username, "@google.com", true)) {
289 PrefService* pref_service = profile->GetPrefs(); 302 PrefService* pref_service = profile->GetPrefs();
290 pref_service->SetBoolean(prefs::kEnableScreenLock, true); 303 pref_service->SetBoolean(prefs::kEnableScreenLock, true);
291 } 304 }
292 305
293 DoBrowserLaunch(profile); 306 DoBrowserLaunch(profile);
294 } 307 }
295 308
309 void LoginUtilsImpl::FetchCookies(
310 Profile* profile,
311 const GaiaAuthConsumer::ClientLoginResult& credentials) {
312 // Take the credentials passed in and try to exchange them for
313 // full-fledged Google authentication cookies. This is
314 // best-effort; it's possible that we'll fail due to network
315 // troubles or some such.
316 // CookieFetcher will delete itself once done.
317 CookieFetcher* cf = new CookieFetcher(profile);
318 cf->AttemptFetch(credentials.data);
319 BootTimesLoader::Get()->AddLoginTimeMarker("CookieFetchStarted", false);
320 }
321
322 void LoginUtilsImpl::FetchTokens(
323 Profile* profile,
324 const GaiaAuthConsumer::ClientLoginResult& credentials) {
325 TokenService* token_service = profile->GetTokenService();
326 token_service->UpdateCredentials(credentials);
327 if (token_service->AreCredentialsValid()) {
328 token_service->StartFetchingTokens();
329 }
330 }
331
296 void LoginUtilsImpl::RespectLocalePreference(PrefService* pref) { 332 void LoginUtilsImpl::RespectLocalePreference(PrefService* pref) {
297 std::string pref_locale = pref->GetString(prefs::kApplicationLocale); 333 std::string pref_locale = pref->GetString(prefs::kApplicationLocale);
298 if (pref_locale.empty()) { 334 if (pref_locale.empty()) {
299 // TODO(dilmah): current code will clobber existing setting in case 335 // TODO(dilmah): current code will clobber existing setting in case
300 // language preference was set via another device 336 // language preference was set via another device
301 // but still not synced yet. Profile is not synced at this point yet. 337 // but still not synced yet. Profile is not synced at this point yet.
302 pref->SetString(prefs::kApplicationLocale, 338 pref->SetString(prefs::kApplicationLocale,
303 g_browser_process->GetApplicationLocale()); 339 g_browser_process->GetApplicationLocale());
304 } else { 340 } else {
305 LanguageSwitchMenu::SwitchLanguage(pref_locale); 341 LanguageSwitchMenu::SwitchLanguage(pref_locale);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 BrowserInit browser_init; 517 BrowserInit browser_init;
482 int return_code; 518 int return_code;
483 browser_init.LaunchBrowser(*CommandLine::ForCurrentProcess(), 519 browser_init.LaunchBrowser(*CommandLine::ForCurrentProcess(),
484 profile, 520 profile,
485 FilePath(), 521 FilePath(),
486 true, 522 true,
487 &return_code); 523 &return_code);
488 } 524 }
489 525
490 } // namespace chromeos 526 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/login_utils.h ('k') | chrome/browser/chromeos/login/mock_authenticator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698