OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | 1 // Use of this source code is governed by a BSD-style license that can be |
xiyuan
2011/11/17 22:34:58
Restore the license?
zel
2011/11/18 03:53:39
Done.
| |
3 // found in the LICENSE file. | 2 // found in the LICENSE file. |
4 | 3 |
5 #include "chrome/browser/chromeos/login/login_utils.h" | 4 #include "chrome/browser/chromeos/login/login_utils.h" |
6 | 5 |
7 #include <vector> | 6 #include <vector> |
8 | 7 |
9 #include "base/command_line.h" | 8 #include "base/command_line.h" |
10 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
11 #include "base/file_path.h" | 10 #include "base/file_path.h" |
12 #include "base/file_util.h" | 11 #include "base/file_util.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 // The service scope of the OAuth v2 token that ChromeOS login will be | 91 // The service scope of the OAuth v2 token that ChromeOS login will be |
93 // requesting. | 92 // requesting. |
94 // TODO(zelidrag): Figure out if we need to add more services here. | 93 // TODO(zelidrag): Figure out if we need to add more services here. |
95 const char kServiceScopeChromeOS[] = | 94 const char kServiceScopeChromeOS[] = |
96 "https://www.googleapis.com/auth/chromesync"; | 95 "https://www.googleapis.com/auth/chromesync"; |
97 | 96 |
98 const char kServiceScopeChromeOSDeviceManagement[] = | 97 const char kServiceScopeChromeOSDeviceManagement[] = |
99 "https://www.googleapis.com/auth/chromeosdevicemanagement"; | 98 "https://www.googleapis.com/auth/chromeosdevicemanagement"; |
100 } // namespace | 99 } // namespace |
101 | 100 |
102 // Task for fetching tokens from UI thread. | |
103 class StartSyncOnUIThreadTask : public Task { | |
104 public: | |
105 explicit StartSyncOnUIThreadTask( | |
106 const GaiaAuthConsumer::ClientLoginResult& credentials) | |
107 : credentials_(credentials) {} | |
108 virtual ~StartSyncOnUIThreadTask() {} | |
109 | |
110 // Task override. | |
111 virtual void Run() OVERRIDE { | |
112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
113 LoginUtils::Get()->FetchCookies(ProfileManager::GetDefaultProfile(), | |
114 credentials_); | |
115 LoginUtils::Get()->StartSync(ProfileManager::GetDefaultProfile(), | |
116 credentials_); | |
117 } | |
118 | |
119 private: | |
120 GaiaAuthConsumer::ClientLoginResult credentials_; | |
121 | |
122 DISALLOW_COPY_AND_ASSIGN(StartSyncOnUIThreadTask); | |
123 }; | |
124 | |
125 // Transfers initial set of Profile cookies from the default profile. | 101 // Transfers initial set of Profile cookies from the default profile. |
126 class TransferDefaultCookiesOnIOThreadTask : public Task { | 102 class TransferDefaultCookiesOnIOThreadTask : public Task { |
127 public: | 103 public: |
128 TransferDefaultCookiesOnIOThreadTask( | 104 TransferDefaultCookiesOnIOThreadTask( |
129 net::URLRequestContextGetter* auth_context, | 105 net::URLRequestContextGetter* auth_context, |
130 net::URLRequestContextGetter* new_context) | 106 net::URLRequestContextGetter* new_context) |
131 : auth_context_(auth_context), | 107 : auth_context_(auth_context), |
132 new_context_(new_context) {} | 108 new_context_(new_context) {} |
133 virtual ~TransferDefaultCookiesOnIOThreadTask() {} | 109 virtual ~TransferDefaultCookiesOnIOThreadTask() {} |
134 | 110 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 http_transaction_factory()->GetSession()->http_auth_cache()); | 158 http_transaction_factory()->GetSession()->http_auth_cache()); |
183 } | 159 } |
184 | 160 |
185 private: | 161 private: |
186 net::URLRequestContextGetter* auth_context_; | 162 net::URLRequestContextGetter* auth_context_; |
187 net::URLRequestContextGetter* new_context_; | 163 net::URLRequestContextGetter* new_context_; |
188 | 164 |
189 DISALLOW_COPY_AND_ASSIGN(TransferDefaultAuthCacheOnIOThreadTask); | 165 DISALLOW_COPY_AND_ASSIGN(TransferDefaultAuthCacheOnIOThreadTask); |
190 }; | 166 }; |
191 | 167 |
192 // Verifies OAuth1 access token by performing OAuthLogin. | 168 const int kMaxOAuthTokenVerificationAttemptCount = 5; |
193 class OAuthLoginVerifier : public GaiaOAuthConsumer { | 169 const int kOAuthVerificationRestartDelay = 5000; // ms |
xiyuan
2011/11/17 22:34:58
nit: two-spaces before line end comment
zel
2011/11/18 03:53:39
Done.
| |
170 | |
171 // Verifies OAuth1 access token by performing OAuthLogin. Fetches user cookies | |
172 // on successful OAuth authentication. | |
173 class OAuthLoginVerifier : public base::SupportsWeakPtr<OAuthLoginVerifier>, | |
174 public GaiaOAuthConsumer, | |
175 public GaiaAuthConsumer { | |
194 public: | 176 public: |
195 OAuthLoginVerifier(Profile* user_profile, | 177 class Delegate { |
178 public: | |
179 virtual ~Delegate() {} | |
180 virtual void OnOAuthVerificationSucceeded(const std::string& user_name, | |
181 const std::string& sid, | |
182 const std::string& lsid, | |
183 const std::string& auth) {} | |
184 virtual void OnOAuthVerificationFailed(const std::string& user_name) {} | |
185 virtual void OnUserCookiesFetchSucceeded(const std::string& user_name) {} | |
186 virtual void OnUserCookiesFetchFailed(const std::string& user_name) {} | |
187 }; | |
188 | |
189 OAuthLoginVerifier(OAuthLoginVerifier::Delegate* delegate, | |
190 Profile* user_profile, | |
196 const std::string& oauth1_token, | 191 const std::string& oauth1_token, |
197 const std::string& oauth1_secret, | 192 const std::string& oauth1_secret, |
198 const std::string& username) | 193 const std::string& username) |
199 : oauth_fetcher_(this, | 194 : delegate_(delegate), |
195 oauth_fetcher_(this, | |
200 user_profile->GetOffTheRecordProfile()->GetRequestContext(), | 196 user_profile->GetOffTheRecordProfile()->GetRequestContext(), |
201 user_profile->GetOffTheRecordProfile(), | 197 user_profile->GetOffTheRecordProfile(), |
202 kServiceScopeChromeOS), | 198 kServiceScopeChromeOS), |
199 gaia_fetcher_(this, | |
200 std::string(GaiaConstants::kChromeOSSource), | |
201 user_profile->GetRequestContext()), | |
203 oauth1_token_(oauth1_token), | 202 oauth1_token_(oauth1_token), |
204 oauth1_secret_(oauth1_secret), | 203 oauth1_secret_(oauth1_secret), |
205 username_(username) { | 204 username_(username), |
205 user_profile_(user_profile), | |
206 verification_count_(0), | |
207 step_(VERIFICATION_STEP_UNVERIFIED) { | |
206 } | 208 } |
207 virtual ~OAuthLoginVerifier() {} | 209 virtual ~OAuthLoginVerifier() {} |
208 | 210 |
209 void Start() { | 211 bool is_done() { |
212 return step_ == VERIFICATION_STEP_FAILED || | |
213 step_ == VERIFICATION_STEP_COOKIES_FETCHED; | |
214 } | |
215 | |
216 void StartOAuthVerification() { | |
210 if (oauth1_token_.empty() || oauth1_secret_.empty()) { | 217 if (oauth1_token_.empty() || oauth1_secret_.empty()) { |
211 // Empty OAuth1 access token or secret probably means that we are | 218 // Empty OAuth1 access token or secret probably means that we are |
212 // dealing with a legacy ChromeOS account. This should be treated as | 219 // dealing with a legacy ChromeOS account. This should be treated as |
213 // invalid/expired token. | 220 // invalid/expired token. |
214 OnOAuthLoginFailure(GoogleServiceAuthError( | 221 OnOAuthLoginFailure(GoogleServiceAuthError( |
215 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); | 222 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); |
216 } else { | 223 } else { |
217 oauth_fetcher_.StartOAuthLogin(GaiaConstants::kChromeOSSource, | 224 oauth_fetcher_.StartOAuthLogin(GaiaConstants::kChromeOSSource, |
218 GaiaConstants::kPicasaService, | 225 GaiaConstants::kPicasaService, |
219 oauth1_token_, | 226 oauth1_token_, |
220 oauth1_secret_); | 227 oauth1_secret_); |
221 } | 228 } |
222 } | 229 } |
223 | 230 |
231 void ContinueVerification() { | |
232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
233 // Check if we have finished with this one already. | |
234 if (is_done()) | |
235 return; | |
236 | |
237 if (user_profile_ != ProfileManager::GetDefaultProfile()) | |
238 return; | |
239 | |
240 if (CrosLibrary::Get()->EnsureLoaded()) { | |
241 // Delay the verification if the network is not connected or on a captive | |
242 // portal. | |
243 const Network* network = | |
244 CrosLibrary::Get()->GetNetworkLibrary()->active_network(); | |
245 if (!network || !network->connected() || network->restricted_pool()) { | |
246 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, | |
247 base::Bind(&OAuthLoginVerifier::ContinueVerification, AsWeakPtr()), | |
248 kOAuthVerificationRestartDelay); | |
249 return; | |
250 } | |
251 } | |
xiyuan
2011/11/17 22:34:58
Maybe we should check oauth_fetcher_->HasPendingFe
zel
2011/11/18 03:53:39
Good point. Done.
| |
252 | |
253 verification_count_++; | |
254 if (step_ == VERIFICATION_STEP_UNVERIFIED) { | |
255 DVLOG(10) << "Retrying to verify OAuth1 access tokens."; | |
256 StartOAuthVerification(); | |
257 } else { | |
258 DVLOG(10) << "Retrying to fetch user cookies."; | |
259 StartCookiesRetreival(); | |
260 } | |
261 } | |
262 | |
263 private: | |
264 typedef enum { | |
265 VERIFICATION_STEP_UNVERIFIED, | |
266 VERIFICATION_STEP_OAUTH_VERIFIED, | |
267 VERIFICATION_STEP_COOKIES_FETCHED, | |
268 VERIFICATION_STEP_FAILED, | |
269 } VerificationStep; | |
270 | |
271 // Kicks off GAIA session cookie retreival process. | |
272 void StartCookiesRetreival() { | |
273 DCHECK(!sid_.empty()); | |
274 DCHECK(!lsid_.empty()); | |
275 gaia_fetcher_.StartIssueAuthToken(sid_, lsid_, GaiaConstants::kGaiaService); | |
276 } | |
277 | |
278 // Decides how to proceed on GAIA response and other errors. It can schedule | |
279 // to rerun the verification process if detects transient network or service | |
280 // errors. | |
281 bool RetryOnError(const GoogleServiceAuthError& error) { | |
282 // If we can't connect to GAIA due to network or service related reasons, | |
283 // we should attempt OAuth token verification again. | |
284 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED || | |
285 error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE) { | |
286 if (verification_count_ < kMaxOAuthTokenVerificationAttemptCount) { | |
287 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, | |
288 base::Bind(&OAuthLoginVerifier::ContinueVerification, AsWeakPtr()), | |
289 kOAuthVerificationRestartDelay); | |
290 return true; | |
291 } | |
292 } | |
293 step_ = VERIFICATION_STEP_FAILED; | |
294 return false; | |
295 } | |
296 | |
224 // GaiaOAuthConsumer implementation: | 297 // GaiaOAuthConsumer implementation: |
225 virtual void OnOAuthLoginSuccess(const std::string& sid, | 298 virtual void OnOAuthLoginSuccess(const std::string& sid, |
226 const std::string& lsid, | 299 const std::string& lsid, |
227 const std::string& auth) OVERRIDE { | 300 const std::string& auth) OVERRIDE { |
228 GaiaAuthConsumer::ClientLoginResult credentials( | 301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
229 sid, lsid, auth, std::string()); | 302 // OnOAuthLoginFailure(GoogleServiceAuthError::FromConnectionError(400)); |
xiyuan
2011/11/17 22:34:58
nit: remove this?
zel
2011/11/18 03:53:39
Done.
| |
230 UserManager::Get()->set_offline_login(false); | 303 |
231 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 304 step_ = VERIFICATION_STEP_OAUTH_VERIFIED; |
232 new StartSyncOnUIThreadTask(credentials)); | 305 verification_count_ = 0; |
306 sid_ = sid; | |
307 lsid_ = lsid; | |
308 delegate_->OnOAuthVerificationSucceeded(username_, sid, lsid, auth); | |
309 StartCookiesRetreival(); | |
233 } | 310 } |
234 | 311 |
235 virtual void OnOAuthLoginFailure( | 312 virtual void OnOAuthLoginFailure( |
236 const GoogleServiceAuthError& error) OVERRIDE { | 313 const GoogleServiceAuthError& error) OVERRIDE { |
237 LOG(WARNING) << "Failed to verify OAuth1 access tokens, error: " | 314 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
238 << error.state(); | 315 LOG(WARNING) << "Failed to verify OAuth1 access tokens," |
239 | 316 << " error.state=" << error.state(); |
240 // Mark this account's OAuth token state as invalid if the failure is not | 317 if (!RetryOnError(error)) |
241 // caused by network error. | 318 delegate_->OnOAuthVerificationFailed(username_); |
242 if (error.state() != GoogleServiceAuthError::CONNECTION_FAILED) { | |
243 UserManager::Get()->SaveUserOAuthStatus(username_, | |
244 User::OAUTH_TOKEN_STATUS_INVALID); | |
245 } else { | |
246 UserManager::Get()->set_offline_login(true); | |
247 } | |
248 } | 319 } |
249 | 320 |
250 private: | 321 void OnCookueFetchFailed(const GoogleServiceAuthError& error) { |
251 GaiaOAuthFetcher oauth_fetcher_; | 322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
252 std::string oauth1_token_; | 323 if (!RetryOnError(error)) |
253 std::string oauth1_secret_; | 324 delegate_->OnUserCookiesFetchFailed(username_); |
254 std::string username_; | |
255 | |
256 DISALLOW_COPY_AND_ASSIGN(OAuthLoginVerifier); | |
257 }; | |
258 | |
259 // Verifies OAuth1 access token by performing OAuthLogin. | |
260 class UserSessionCookieFetcher : public GaiaAuthConsumer { | |
261 public: | |
262 explicit UserSessionCookieFetcher(Profile* user_profile) | |
263 : gaia_fetcher_(this, | |
264 std::string(GaiaConstants::kChromeOSSource), | |
265 user_profile->GetRequestContext()) { | |
266 } | |
267 virtual ~UserSessionCookieFetcher() {} | |
268 | |
269 void Start(const GaiaAuthConsumer::ClientLoginResult& credentials) { | |
270 gaia_fetcher_.StartIssueAuthToken(credentials.sid, credentials.lsid, | |
271 GaiaConstants::kGaiaService); | |
272 } | 325 } |
273 | 326 |
274 // GaiaAuthConsumer overrides. | 327 // GaiaAuthConsumer overrides. |
275 virtual void OnIssueAuthTokenSuccess(const std::string& service, | 328 virtual void OnIssueAuthTokenSuccess(const std::string& service, |
276 const std::string& auth_token) OVERRIDE { | 329 const std::string& auth_token) OVERRIDE { |
277 gaia_fetcher_.StartMergeSession(auth_token); | 330 gaia_fetcher_.StartMergeSession(auth_token); |
278 } | 331 } |
279 | 332 |
280 virtual void OnIssueAuthTokenFailure(const std::string& service, | 333 virtual void OnIssueAuthTokenFailure(const std::string& service, |
281 const GoogleServiceAuthError& error) OVERRIDE { | 334 const GoogleServiceAuthError& error) OVERRIDE { |
282 LOG(WARNING) << "Failed IssueAuthToken request, error: " << error.state(); | 335 DVLOG(10) << "Failed IssueAuthToken request," |
283 HandlerGaiaAuthError(error); | 336 << " error.state=" << error.state(); |
284 delete this; | 337 OnCookueFetchFailed(error); |
285 } | 338 } |
286 | 339 |
287 virtual void OnMergeSessionSuccess(const std::string& data) OVERRIDE { | 340 virtual void OnMergeSessionSuccess(const std::string& data) OVERRIDE { |
288 VLOG(1) << "MergeSession successful."; | 341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
289 delete this; | 342 DVLOG(10) << "MergeSession successful."; |
343 step_ = VERIFICATION_STEP_COOKIES_FETCHED; | |
344 delegate_->OnUserCookiesFetchSucceeded(username_); | |
290 } | 345 } |
291 | 346 |
292 virtual void OnMergeSessionFailure( | 347 virtual void OnMergeSessionFailure( |
293 const GoogleServiceAuthError& error) OVERRIDE { | 348 const GoogleServiceAuthError& error) OVERRIDE { |
294 LOG(WARNING) << "Failed MergeSession request, error: " << error.state(); | 349 DVLOG(10) << "Failed MergeSession request," |
295 HandlerGaiaAuthError(error); | 350 << " error.state=" << error.state(); |
296 delete this; | 351 OnCookueFetchFailed(error); |
297 } | 352 } |
298 | 353 |
299 private: | 354 OAuthLoginVerifier::Delegate* delegate_; |
300 void HandlerGaiaAuthError(const GoogleServiceAuthError& error) { | 355 GaiaOAuthFetcher oauth_fetcher_; |
301 // Mark this account's login state as offline if we encountered a network | 356 GaiaAuthFetcher gaia_fetcher_; |
302 // error. That will make us verify user OAuth token and try to fetch session | 357 std::string oauth1_token_; |
303 // cookies again once we detect that the machine comes online. | 358 std::string oauth1_secret_; |
304 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) | 359 std::string sid_; |
305 UserManager::Get()->set_offline_login(true); | 360 std::string lsid_; |
306 } | 361 std::string username_; |
362 Profile* user_profile_; | |
363 int verification_count_; | |
364 VerificationStep step_; | |
307 | 365 |
308 GaiaAuthFetcher gaia_fetcher_; | 366 DISALLOW_COPY_AND_ASSIGN(OAuthLoginVerifier); |
309 DISALLOW_COPY_AND_ASSIGN(UserSessionCookieFetcher); | |
310 }; | 367 }; |
311 | 368 |
312 // Fetches the oauth token for the device management service. Since Profile | 369 // Fetches the oauth token for the device management service. Since Profile |
313 // creation might be blocking on a user policy fetch, this fetcher must always | 370 // creation might be blocking on a user policy fetch, this fetcher must always |
314 // send a (possibly empty) token to the BrowserPolicyConnector, which will then | 371 // send a (possibly empty) token to the BrowserPolicyConnector, which will then |
315 // let the policy subsystem proceed and resume Profile creation. | 372 // let the policy subsystem proceed and resume Profile creation. |
316 // Sending the token even when no Profile is pending is also OK. | 373 // Sending the token even when no Profile is pending is also OK. |
317 class PolicyOAuthFetcher : public GaiaOAuthConsumer { | 374 class PolicyOAuthFetcher : public GaiaOAuthConsumer { |
318 public: | 375 public: |
319 // Fetches the device management service's oauth token using |oauth1_token| | 376 // Fetches the device management service's oauth token using |oauth1_token| |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 } | 411 } |
355 | 412 |
356 const std::string& oauth1_token() const { return oauth1_token_; } | 413 const std::string& oauth1_token() const { return oauth1_token_; } |
357 const std::string& oauth1_secret() const { return oauth1_secret_; } | 414 const std::string& oauth1_secret() const { return oauth1_secret_; } |
358 bool failed() const { | 415 bool failed() const { |
359 return !oauth_fetcher_.HasPendingFetch() && policy_token_.empty(); | 416 return !oauth_fetcher_.HasPendingFetch() && policy_token_.empty(); |
360 } | 417 } |
361 | 418 |
362 private: | 419 private: |
363 virtual void OnGetOAuthTokenSuccess(const std::string& oauth_token) OVERRIDE { | 420 virtual void OnGetOAuthTokenSuccess(const std::string& oauth_token) OVERRIDE { |
364 VLOG(1) << "Got OAuth request token"; | 421 VLOG(10) << "Got OAuth request token"; |
365 } | 422 } |
366 | 423 |
367 virtual void OnGetOAuthTokenFailure( | 424 virtual void OnGetOAuthTokenFailure( |
368 const GoogleServiceAuthError& error) OVERRIDE { | 425 const GoogleServiceAuthError& error) OVERRIDE { |
369 LOG(WARNING) << "Failed to get OAuth request token, error: " | 426 LOG(WARNING) << "Failed to get OAuth request token, error: " |
370 << error.state(); | 427 << error.state(); |
371 SetPolicyToken(""); | 428 SetPolicyToken(""); |
372 } | 429 } |
373 | 430 |
374 virtual void OnOAuthGetAccessTokenSuccess( | 431 virtual void OnOAuthGetAccessTokenSuccess( |
375 const std::string& token, | 432 const std::string& token, |
376 const std::string& secret) OVERRIDE { | 433 const std::string& secret) OVERRIDE { |
377 VLOG(1) << "Got OAuth access token"; | 434 VLOG(10) << "Got OAuth access token"; |
378 oauth1_token_ = token; | 435 oauth1_token_ = token; |
379 oauth1_secret_ = secret; | 436 oauth1_secret_ = secret; |
380 } | 437 } |
381 | 438 |
382 virtual void OnOAuthGetAccessTokenFailure( | 439 virtual void OnOAuthGetAccessTokenFailure( |
383 const GoogleServiceAuthError& error) OVERRIDE { | 440 const GoogleServiceAuthError& error) OVERRIDE { |
384 LOG(WARNING) << "Failed to get OAuth access token, error: " | 441 LOG(WARNING) << "Failed to get OAuth access token, error: " |
385 << error.state(); | 442 << error.state(); |
386 SetPolicyToken(""); | 443 SetPolicyToken(""); |
387 } | 444 } |
388 | 445 |
389 virtual void OnOAuthWrapBridgeSuccess( | 446 virtual void OnOAuthWrapBridgeSuccess( |
390 const std::string& service_name, | 447 const std::string& service_name, |
391 const std::string& token, | 448 const std::string& token, |
392 const std::string& expires_in) OVERRIDE { | 449 const std::string& expires_in) OVERRIDE { |
393 VLOG(1) << "Got OAuth access token for " << service_name; | 450 VLOG(10) << "Got OAuth access token for " << service_name; |
394 SetPolicyToken(token); | 451 SetPolicyToken(token); |
395 } | 452 } |
396 | 453 |
397 virtual void OnOAuthWrapBridgeFailure( | 454 virtual void OnOAuthWrapBridgeFailure( |
398 const std::string& service_name, | 455 const std::string& service_name, |
399 const GoogleServiceAuthError& error) OVERRIDE { | 456 const GoogleServiceAuthError& error) OVERRIDE { |
400 LOG(WARNING) << "Failed to get OAuth access token for " << service_name | 457 LOG(WARNING) << "Failed to get OAuth access token for " << service_name |
401 << ", error: " << error.state(); | 458 << ", error: " << error.state(); |
402 SetPolicyToken(""); | 459 SetPolicyToken(""); |
403 } | 460 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
458 | 515 |
459 int pid_; | 516 int pid_; |
460 std::string command_line_; | 517 std::string command_line_; |
461 PrefService* local_state_; | 518 PrefService* local_state_; |
462 base::OneShotTimer<JobRestartRequest> timer_; | 519 base::OneShotTimer<JobRestartRequest> timer_; |
463 }; | 520 }; |
464 | 521 |
465 class LoginUtilsImpl : public LoginUtils, | 522 class LoginUtilsImpl : public LoginUtils, |
466 public ProfileManagerObserver, | 523 public ProfileManagerObserver, |
467 public GaiaOAuthConsumer, | 524 public GaiaOAuthConsumer, |
525 public OAuthLoginVerifier::Delegate, | |
468 public net::NetworkChangeNotifier::OnlineStateObserver { | 526 public net::NetworkChangeNotifier::OnlineStateObserver { |
469 public: | 527 public: |
470 LoginUtilsImpl() | 528 LoginUtilsImpl() |
471 : background_view_(NULL), | 529 : background_view_(NULL), |
472 pending_requests_(false), | 530 pending_requests_(false), |
473 using_oauth_(false), | 531 using_oauth_(false), |
474 has_cookies_(false), | 532 has_cookies_(false), |
475 delegate_(NULL), | 533 delegate_(NULL), |
476 job_restart_request_(NULL) { | 534 job_restart_request_(NULL) { |
477 net::NetworkChangeNotifier::AddOnlineStateObserver(this); | 535 net::NetworkChangeNotifier::AddOnlineStateObserver(this); |
478 } | 536 } |
479 | 537 |
480 virtual ~LoginUtilsImpl() { | 538 virtual ~LoginUtilsImpl() { |
481 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); | 539 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); |
482 } | 540 } |
483 | 541 |
484 // LoginUtils implementation: | 542 // LoginUtils implementation: |
485 virtual void PrepareProfile( | 543 virtual void PrepareProfile( |
486 const std::string& username, | 544 const std::string& username, |
487 const std::string& password, | 545 const std::string& password, |
488 const GaiaAuthConsumer::ClientLoginResult& credentials, | 546 const GaiaAuthConsumer::ClientLoginResult& credentials, |
489 bool pending_requests, | 547 bool pending_requests, |
490 bool using_oauth, | 548 bool using_oauth, |
491 bool has_cookies, | 549 bool has_cookies, |
492 LoginUtils::Delegate* delegate) OVERRIDE; | 550 LoginUtils::Delegate* delegate) OVERRIDE; |
493 virtual void DelegateDeleted(Delegate* delegate) OVERRIDE; | 551 virtual void DelegateDeleted(LoginUtils::Delegate* delegate) OVERRIDE; |
494 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE; | 552 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE; |
495 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE; | 553 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE; |
496 virtual scoped_refptr<Authenticator> CreateAuthenticator( | 554 virtual scoped_refptr<Authenticator> CreateAuthenticator( |
497 LoginStatusConsumer* consumer) OVERRIDE; | 555 LoginStatusConsumer* consumer) OVERRIDE; |
498 virtual void PrewarmAuthentication() OVERRIDE; | 556 virtual void PrewarmAuthentication() OVERRIDE; |
499 virtual void RestoreAuthenticationSession(const std::string& user_name, | 557 virtual void RestoreAuthenticationSession(const std::string& user_name, |
500 Profile* profile) OVERRIDE; | 558 Profile* profile) OVERRIDE; |
501 virtual void FetchCookies( | |
502 Profile* profile, | |
503 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; | |
504 virtual void StartTokenServices(Profile* user_profile) OVERRIDE; | 559 virtual void StartTokenServices(Profile* user_profile) OVERRIDE; |
505 virtual void StartSync( | 560 virtual void StartSync( |
506 Profile* profile, | 561 Profile* profile, |
507 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; | 562 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; |
508 virtual void SetBackgroundView( | 563 virtual void SetBackgroundView( |
509 chromeos::BackgroundView* background_view) OVERRIDE; | 564 chromeos::BackgroundView* background_view) OVERRIDE; |
510 virtual chromeos::BackgroundView* GetBackgroundView() OVERRIDE; | 565 virtual chromeos::BackgroundView* GetBackgroundView() OVERRIDE; |
511 virtual void TransferDefaultCookies(Profile* default_profile, | 566 virtual void TransferDefaultCookies(Profile* default_profile, |
512 Profile* new_profile) OVERRIDE; | 567 Profile* new_profile) OVERRIDE; |
513 virtual void TransferDefaultAuthCache(Profile* default_profile, | 568 virtual void TransferDefaultAuthCache(Profile* default_profile, |
514 Profile* new_profile) OVERRIDE; | 569 Profile* new_profile) OVERRIDE; |
515 | 570 |
516 // ProfileManagerObserver implementation: | 571 // ProfileManagerObserver implementation: |
517 virtual void OnProfileCreated(Profile* profile, Status status) OVERRIDE; | 572 virtual void OnProfileCreated(Profile* profile, Status status) OVERRIDE; |
518 | 573 |
519 // GaiaOAuthConsumer overrides. | 574 // GaiaOAuthConsumer overrides. |
520 virtual void OnGetOAuthTokenSuccess(const std::string& oauth_token) OVERRIDE; | 575 virtual void OnGetOAuthTokenSuccess(const std::string& oauth_token) OVERRIDE; |
521 virtual void OnGetOAuthTokenFailure( | 576 virtual void OnGetOAuthTokenFailure( |
522 const GoogleServiceAuthError& error) OVERRIDE; | 577 const GoogleServiceAuthError& error) OVERRIDE; |
523 virtual void OnOAuthGetAccessTokenSuccess(const std::string& token, | 578 virtual void OnOAuthGetAccessTokenSuccess(const std::string& token, |
524 const std::string& secret) OVERRIDE; | 579 const std::string& secret) OVERRIDE; |
525 virtual void OnOAuthGetAccessTokenFailure( | 580 virtual void OnOAuthGetAccessTokenFailure( |
526 const GoogleServiceAuthError& error) OVERRIDE; | 581 const GoogleServiceAuthError& error) OVERRIDE; |
527 | 582 |
583 // OAuthLoginVerifier::Delegate overrides. | |
584 virtual void OnOAuthVerificationSucceeded(const std::string& user_name, | |
585 const std::string& sid, | |
586 const std::string& lsid, | |
587 const std::string& auth) OVERRIDE; | |
588 virtual void OnOAuthVerificationFailed(const std::string& user_name) OVERRIDE; | |
589 | |
528 // net::NetworkChangeNotifier::OnlineStateObserver overrides. | 590 // net::NetworkChangeNotifier::OnlineStateObserver overrides. |
529 virtual void OnOnlineStateChanged(bool online) OVERRIDE; | 591 virtual void OnOnlineStateChanged(bool online) OVERRIDE; |
530 | 592 |
531 // Given the authenticated credentials from the cookie jar, try to exchange | 593 // Given the authenticated credentials from the cookie jar, try to exchange |
532 // fetch OAuth request, v1 and v2 tokens. | 594 // fetch OAuth request, v1 and v2 tokens. |
533 void FetchOAuth1AccessToken(Profile* auth_profile); | 595 void FetchOAuth1AccessToken(Profile* auth_profile); |
534 | 596 |
535 protected: | 597 protected: |
536 virtual std::string GetOffTheRecordCommandLine( | 598 virtual std::string GetOffTheRecordCommandLine( |
537 const GURL& start_url, | 599 const GURL& start_url, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
631 void LoginUtilsImpl::PrepareProfile( | 693 void LoginUtilsImpl::PrepareProfile( |
632 const std::string& username, | 694 const std::string& username, |
633 const std::string& password, | 695 const std::string& password, |
634 const GaiaAuthConsumer::ClientLoginResult& credentials, | 696 const GaiaAuthConsumer::ClientLoginResult& credentials, |
635 bool pending_requests, | 697 bool pending_requests, |
636 bool using_oauth, | 698 bool using_oauth, |
637 bool has_cookies, | 699 bool has_cookies, |
638 LoginUtils::Delegate* delegate) { | 700 LoginUtils::Delegate* delegate) { |
639 BootTimesLoader* btl = BootTimesLoader::Get(); | 701 BootTimesLoader* btl = BootTimesLoader::Get(); |
640 | 702 |
641 VLOG(1) << "Completing login for " << username; | 703 VLOG(10) << "Completing login for " << username; |
642 | 704 |
643 if (CrosLibrary::Get()->EnsureLoaded()) { | 705 if (CrosLibrary::Get()->EnsureLoaded()) { |
644 btl->AddLoginTimeMarker("StartSession-Start", false); | 706 btl->AddLoginTimeMarker("StartSession-Start", false); |
645 DBusThreadManager::Get()->GetSessionManagerClient()->StartSession( | 707 DBusThreadManager::Get()->GetSessionManagerClient()->StartSession( |
646 username); | 708 username); |
647 btl->AddLoginTimeMarker("StartSession-End", false); | 709 btl->AddLoginTimeMarker("StartSession-End", false); |
648 } | 710 } |
649 | 711 |
650 btl->AddLoginTimeMarker("UserLoggedIn-Start", false); | 712 btl->AddLoginTimeMarker("UserLoggedIn-Start", false); |
651 UserManager::Get()->UserLoggedIn(username); | 713 UserManager::Get()->UserLoggedIn(username); |
(...skipping 26 matching lines...) Expand all Loading... | |
678 (connector->GetUserAffiliation(username) == | 740 (connector->GetUserAffiliation(username) == |
679 policy::CloudPolicyDataStore::USER_AFFILIATION_MANAGED); | 741 policy::CloudPolicyDataStore::USER_AFFILIATION_MANAGED); |
680 | 742 |
681 // Initialize user policy before the profile is created so the profile | 743 // Initialize user policy before the profile is created so the profile |
682 // initialization code sees the cached policy settings. | 744 // initialization code sees the cached policy settings. |
683 connector->InitializeUserPolicy(username, wait_for_policy_fetch); | 745 connector->InitializeUserPolicy(username, wait_for_policy_fetch); |
684 | 746 |
685 if (wait_for_policy_fetch) { | 747 if (wait_for_policy_fetch) { |
686 // Profile creation will block until user policy is fetched, which | 748 // Profile creation will block until user policy is fetched, which |
687 // requires the DeviceManagement token. Try to fetch it now. | 749 // requires the DeviceManagement token. Try to fetch it now. |
688 VLOG(1) << "Profile creation requires policy token, fetching now"; | 750 VLOG(10) << "Profile creation requires policy token, fetching now"; |
689 policy_oauth_fetcher_.reset( | 751 policy_oauth_fetcher_.reset( |
690 new PolicyOAuthFetcher(authenticator_->authentication_profile())); | 752 new PolicyOAuthFetcher(authenticator_->authentication_profile())); |
691 policy_oauth_fetcher_->Start(); | 753 policy_oauth_fetcher_->Start(); |
692 } | 754 } |
693 | 755 |
694 // The default profile will have been changed because the ProfileManager | 756 // The default profile will have been changed because the ProfileManager |
695 // will process the notification that the UserManager sends out. | 757 // will process the notification that the UserManager sends out. |
696 ProfileManager::CreateDefaultProfileAsync(this); | 758 ProfileManager::CreateDefaultProfileAsync(this); |
697 } | 759 } |
698 | 760 |
699 void LoginUtilsImpl::DelegateDeleted(Delegate* delegate) { | 761 void LoginUtilsImpl::DelegateDeleted(LoginUtils::Delegate* delegate) { |
700 if (delegate_ == delegate) | 762 if (delegate_ == delegate) |
701 delegate_ = NULL; | 763 delegate_ = NULL; |
702 } | 764 } |
703 | 765 |
704 void LoginUtilsImpl::OnProfileCreated(Profile* user_profile, Status status) { | 766 void LoginUtilsImpl::OnProfileCreated(Profile* user_profile, Status status) { |
705 CHECK(user_profile); | 767 CHECK(user_profile); |
706 switch (status) { | 768 switch (status) { |
707 case STATUS_INITIALIZED: | 769 case STATUS_INITIALIZED: |
708 break; | 770 break; |
709 case STATUS_CREATED: | 771 case STATUS_CREATED: |
710 if (UserManager::Get()->current_user_is_new()) | 772 if (UserManager::Get()->current_user_is_new()) |
711 SetFirstLoginPrefs(user_profile->GetPrefs()); | 773 SetFirstLoginPrefs(user_profile->GetPrefs()); |
712 RespectLocalePreference(user_profile); | 774 RespectLocalePreference(user_profile); |
713 return; | 775 return; |
714 case STATUS_FAIL: | 776 case STATUS_FAIL: |
715 default: | 777 default: |
716 NOTREACHED(); | 778 NOTREACHED(); |
717 return; | 779 return; |
718 } | 780 } |
719 | 781 |
720 // Initialize the user-policy backend. | |
721 if (!using_oauth_) { | |
722 g_browser_process->browser_policy_connector()-> | |
723 SetUserPolicyTokenService(user_profile->GetTokenService()); | |
724 } | |
725 | |
726 // We suck. This is a hack since we do not have the enterprise feature | |
727 // done yet to pull down policies from the domain admin. We'll take this | |
728 // out when we get that done properly. | |
729 // TODO(xiyuan): Remove this once enterprise feature is ready. | |
730 if (EndsWith(username_, "@google.com", true)) { | |
731 PrefService* pref_service = user_profile->GetPrefs(); | |
732 pref_service->SetBoolean(prefs::kEnableScreenLock, true); | |
733 } | |
734 | |
735 BootTimesLoader* btl = BootTimesLoader::Get(); | 782 BootTimesLoader* btl = BootTimesLoader::Get(); |
736 btl->AddLoginTimeMarker("UserProfileGotten", false); | 783 btl->AddLoginTimeMarker("UserProfileGotten", false); |
737 | 784 |
738 if (using_oauth_) { | 785 if (using_oauth_) { |
739 // Reuse the access token fetched by the PolicyOAuthFetcher, if it was | 786 // Reuse the access token fetched by the PolicyOAuthFetcher, if it was |
740 // used to fetch policies before Profile creation. | 787 // used to fetch policies before Profile creation. |
741 if (policy_oauth_fetcher_.get() && | 788 if (policy_oauth_fetcher_.get() && |
742 !policy_oauth_fetcher_->oauth1_token().empty()) { | 789 !policy_oauth_fetcher_->oauth1_token().empty()) { |
743 VLOG(1) << "Resuming profile creation after fetching policy token"; | 790 VLOG(10) << "Resuming profile creation after fetching policy token"; |
744 StoreOAuth1AccessToken(user_profile, | 791 StoreOAuth1AccessToken(user_profile, |
745 policy_oauth_fetcher_->oauth1_token(), | 792 policy_oauth_fetcher_->oauth1_token(), |
746 policy_oauth_fetcher_->oauth1_secret()); | 793 policy_oauth_fetcher_->oauth1_secret()); |
747 } | 794 } |
748 | 795 |
749 // Transfer cookies when user signs in using extension. | 796 // Transfer cookies when user signs in using extension. |
750 if (has_cookies_) { | 797 if (has_cookies_) { |
751 // Transfer cookies from the profile that was used for authentication. | 798 // Transfer cookies from the profile that was used for authentication. |
752 // This profile contains cookies that auth extension should have already | 799 // This profile contains cookies that auth extension should have already |
753 // put in place that will ensure that the newly created session is | 800 // put in place that will ensure that the newly created session is |
(...skipping 16 matching lines...) Expand all Loading... | |
770 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); | 817 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); |
771 } else { | 818 } else { |
772 // If we don't have it, fetch OAuth1 access token. | 819 // If we don't have it, fetch OAuth1 access token. |
773 // Use off-the-record profile that was used for this step. It should | 820 // Use off-the-record profile that was used for this step. It should |
774 // already contain all needed cookies that will let us skip GAIA's user | 821 // already contain all needed cookies that will let us skip GAIA's user |
775 // authentication UI. | 822 // authentication UI. |
776 // | 823 // |
777 // TODO(rickcam) We should use an isolated App here. | 824 // TODO(rickcam) We should use an isolated App here. |
778 FetchOAuth1AccessToken(authenticator_->authentication_profile()); | 825 FetchOAuth1AccessToken(authenticator_->authentication_profile()); |
779 } | 826 } |
780 } else { | |
781 // Since we're doing parallel authentication, only new user sign in | |
782 // would perform online auth before calling PrepareProfile. | |
783 // For existing users there's usually a pending online auth request. | |
784 // Cookies will be fetched after it's is succeeded. | |
785 if (!pending_requests_) { | |
786 FetchCookies(user_profile, credentials_); | |
787 } | |
788 } | |
789 | |
790 if (!using_oauth_) { | |
791 // We don't need authenticator instance anymore in LoginUtils. | |
792 // Release it so that ScreenLocker would create a separate instance. | |
793 // Note that for GAIA WebUI login authenticator instance is reset in | |
794 // OnOAuthGetAccessTokenSuccess(...). | |
795 authenticator_ = NULL; | |
796 } | |
797 | |
798 // Supply credentials for sync and others to use. Load tokens from disk. | |
799 if (!using_oauth_) { | |
800 // For existing users there's usually a pending online auth request. | |
801 // Tokens will be fetched after it's is succeeded. | |
802 if (!pending_requests_) | |
803 StartSync(user_profile, credentials_); | |
804 } | 827 } |
805 | 828 |
806 // Own TPM device if, for any reason, it has not been done in EULA | 829 // Own TPM device if, for any reason, it has not been done in EULA |
807 // wizard screen. | 830 // wizard screen. |
808 if (CrosLibrary::Get()->EnsureLoaded()) { | 831 if (CrosLibrary::Get()->EnsureLoaded()) { |
809 CryptohomeLibrary* cryptohome = CrosLibrary::Get()->GetCryptohomeLibrary(); | 832 CryptohomeLibrary* cryptohome = CrosLibrary::Get()->GetCryptohomeLibrary(); |
810 btl->AddLoginTimeMarker("TPMOwn-Start", false); | 833 btl->AddLoginTimeMarker("TPMOwn-Start", false); |
811 if (cryptohome->TpmIsEnabled() && !cryptohome->TpmIsBeingOwned()) { | 834 if (cryptohome->TpmIsEnabled() && !cryptohome->TpmIsBeingOwned()) { |
812 if (cryptohome->TpmIsOwned()) { | 835 if (cryptohome->TpmIsOwned()) { |
813 cryptohome->TpmClearStoredPassword(); | 836 cryptohome->TpmClearStoredPassword(); |
(...skipping 24 matching lines...) Expand all Loading... | |
838 auth_profile->GetRequestContext(), | 861 auth_profile->GetRequestContext(), |
839 auth_profile, | 862 auth_profile, |
840 kServiceScopeChromeOS)); | 863 kServiceScopeChromeOS)); |
841 // Let's first get the Oauth request token and OAuth1 token+secret. | 864 // Let's first get the Oauth request token and OAuth1 token+secret. |
842 // Once we get that, we will kick off individual requests for OAuth2 tokens | 865 // Once we get that, we will kick off individual requests for OAuth2 tokens |
843 // for all our services. | 866 // for all our services. |
844 oauth_fetcher_->SetAutoFetchLimit(GaiaOAuthFetcher::OAUTH1_ALL_ACCESS_TOKEN); | 867 oauth_fetcher_->SetAutoFetchLimit(GaiaOAuthFetcher::OAUTH1_ALL_ACCESS_TOKEN); |
845 oauth_fetcher_->StartGetOAuthTokenRequest(); | 868 oauth_fetcher_->StartGetOAuthTokenRequest(); |
846 } | 869 } |
847 | 870 |
848 void LoginUtilsImpl::FetchCookies(Profile* user_profile, | |
849 const GaiaAuthConsumer::ClientLoginResult& credentials) { | |
850 if (!using_oauth_) { | |
851 // Take the credentials passed in and try to exchange them for | |
852 // full-fledged Google authentication cookies. This is | |
853 // best-effort; it's possible that we'll fail due to network | |
854 // troubles or some such. | |
855 // CookieFetcher will delete itself once done. | |
856 CookieFetcher* cf = new CookieFetcher(user_profile); | |
857 cf->AttemptFetch(credentials.data); | |
858 } else { | |
859 UserSessionCookieFetcher* cf = | |
860 new UserSessionCookieFetcher(user_profile); | |
861 cf->Start(credentials); | |
862 } | |
863 } | |
864 | |
865 void LoginUtilsImpl::StartTokenServices(Profile* user_profile) { | 871 void LoginUtilsImpl::StartTokenServices(Profile* user_profile) { |
866 std::string oauth1_token; | 872 std::string oauth1_token; |
867 std::string oauth1_secret; | 873 std::string oauth1_secret; |
868 if (!ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) | 874 if (!ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) |
869 return; | 875 return; |
870 | 876 |
871 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), oauth1_token, | 877 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), oauth1_token, |
872 oauth1_secret); | 878 oauth1_secret); |
873 } | 879 } |
874 | 880 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
912 // Here we don't enable keyboard layouts. Input methods are set up when | 918 // Here we don't enable keyboard layouts. Input methods are set up when |
913 // the user first logs in. Then the user may customize the input methods. | 919 // the user first logs in. Then the user may customize the input methods. |
914 // Hence changing input methods here, just because the user's UI language | 920 // Hence changing input methods here, just because the user's UI language |
915 // is different from the login screen UI language, is not desirable. Note | 921 // is different from the login screen UI language, is not desirable. Note |
916 // that input method preferences are synced, so users can use their | 922 // that input method preferences are synced, so users can use their |
917 // farovite input methods as soon as the preferences are synced. | 923 // farovite input methods as soon as the preferences are synced. |
918 LanguageSwitchMenu::SwitchLanguage(pref_locale); | 924 LanguageSwitchMenu::SwitchLanguage(pref_locale); |
919 } | 925 } |
920 | 926 |
921 void LoginUtilsImpl::CompleteOffTheRecordLogin(const GURL& start_url) { | 927 void LoginUtilsImpl::CompleteOffTheRecordLogin(const GURL& start_url) { |
922 VLOG(1) << "Completing incognito login"; | 928 VLOG(10) << "Completing incognito login"; |
923 | 929 |
924 UserManager::Get()->GuestUserLoggedIn(); | 930 UserManager::Get()->GuestUserLoggedIn(); |
925 | 931 |
926 if (CrosLibrary::Get()->EnsureLoaded()) { | 932 if (CrosLibrary::Get()->EnsureLoaded()) { |
927 // Session Manager may kill the chrome anytime after this point. | 933 // Session Manager may kill the chrome anytime after this point. |
928 // Write exit_cleanly and other stuff to the disk here. | 934 // Write exit_cleanly and other stuff to the disk here. |
929 g_browser_process->EndSession(); | 935 g_browser_process->EndSession(); |
930 | 936 |
931 // For guest session we ask session manager to restart Chrome with --bwsi | 937 // For guest session we ask session manager to restart Chrome with --bwsi |
932 // flag. We keep only some of the arguments of this process. | 938 // flag. We keep only some of the arguments of this process. |
933 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 939 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
934 CommandLine command_line(browser_command_line.GetProgram()); | 940 CommandLine command_line(browser_command_line.GetProgram()); |
935 std::string cmd_line_str = | 941 std::string cmd_line_str = |
936 GetOffTheRecordCommandLine(start_url, | 942 GetOffTheRecordCommandLine(start_url, |
937 browser_command_line, | 943 browser_command_line, |
938 &command_line); | 944 &command_line); |
939 | 945 |
940 if (job_restart_request_) { | 946 if (job_restart_request_) { |
941 NOTREACHED(); | 947 NOTREACHED(); |
942 } | 948 } |
943 VLOG(1) << "Requesting a restart with PID " << getpid() | 949 VLOG(10) << "Requesting a restart with PID " << getpid() |
944 << " and command line: " << cmd_line_str; | 950 << " and command line: " << cmd_line_str; |
945 job_restart_request_ = new JobRestartRequest(getpid(), cmd_line_str); | 951 job_restart_request_ = new JobRestartRequest(getpid(), cmd_line_str); |
946 } | 952 } |
947 } | 953 } |
948 | 954 |
949 std::string LoginUtilsImpl::GetOffTheRecordCommandLine( | 955 std::string LoginUtilsImpl::GetOffTheRecordCommandLine( |
950 const GURL& start_url, | 956 const GURL& start_url, |
951 const CommandLine& base_command_line, | 957 const CommandLine& base_command_line, |
952 CommandLine* command_line) { | 958 CommandLine* command_line) { |
953 static const char* kForwardSwitches[] = { | 959 static const char* kForwardSwitches[] = { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1001 kSwitchFormatString, | 1007 kSwitchFormatString, |
1002 switches::kRegisterPepperPlugins, | 1008 switches::kRegisterPepperPlugins, |
1003 base_command_line.GetSwitchValueNative( | 1009 base_command_line.GetSwitchValueNative( |
1004 switches::kRegisterPepperPlugins).c_str()); | 1010 switches::kRegisterPepperPlugins).c_str()); |
1005 } | 1011 } |
1006 | 1012 |
1007 return cmd_line_str; | 1013 return cmd_line_str; |
1008 } | 1014 } |
1009 | 1015 |
1010 void LoginUtilsImpl::SetFirstLoginPrefs(PrefService* prefs) { | 1016 void LoginUtilsImpl::SetFirstLoginPrefs(PrefService* prefs) { |
1011 VLOG(1) << "Setting first login prefs"; | 1017 VLOG(10) << "Setting first login prefs"; |
1012 BootTimesLoader* btl = BootTimesLoader::Get(); | 1018 BootTimesLoader* btl = BootTimesLoader::Get(); |
1013 std::string locale = g_browser_process->GetApplicationLocale(); | 1019 std::string locale = g_browser_process->GetApplicationLocale(); |
1014 | 1020 |
1015 // First, we'll set kLanguagePreloadEngines. | 1021 // First, we'll set kLanguagePreloadEngines. |
1016 input_method::InputMethodManager* manager = | 1022 input_method::InputMethodManager* manager = |
1017 input_method::InputMethodManager::GetInstance(); | 1023 input_method::InputMethodManager::GetInstance(); |
1018 std::vector<std::string> input_method_ids; | 1024 std::vector<std::string> input_method_ids; |
1019 manager->GetInputMethodUtil()->GetFirstLoginInputMethodIds( | 1025 manager->GetInputMethodUtil()->GetFirstLoginInputMethodIds( |
1020 locale, manager->current_input_method(), &input_method_ids); | 1026 locale, manager->current_input_method(), &input_method_ids); |
1021 // Save the input methods in the user's preferences. | 1027 // Save the input methods in the user's preferences. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1147 | 1153 |
1148 void LoginUtilsImpl::TransferDefaultAuthCache(Profile* default_profile, | 1154 void LoginUtilsImpl::TransferDefaultAuthCache(Profile* default_profile, |
1149 Profile* profile) { | 1155 Profile* profile) { |
1150 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 1156 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
1151 new TransferDefaultAuthCacheOnIOThreadTask( | 1157 new TransferDefaultAuthCacheOnIOThreadTask( |
1152 default_profile->GetRequestContext(), | 1158 default_profile->GetRequestContext(), |
1153 profile->GetRequestContext())); | 1159 profile->GetRequestContext())); |
1154 } | 1160 } |
1155 | 1161 |
1156 void LoginUtilsImpl::OnGetOAuthTokenSuccess(const std::string& oauth_token) { | 1162 void LoginUtilsImpl::OnGetOAuthTokenSuccess(const std::string& oauth_token) { |
1157 VLOG(1) << "Got OAuth request token!"; | 1163 VLOG(10) << "Got OAuth request token!"; |
1158 } | 1164 } |
1159 | 1165 |
1160 void LoginUtilsImpl::OnGetOAuthTokenFailure( | 1166 void LoginUtilsImpl::OnGetOAuthTokenFailure( |
1161 const GoogleServiceAuthError& error) { | 1167 const GoogleServiceAuthError& error) { |
1162 // TODO(zelidrag): Pop up sync setup UI here? | 1168 // TODO(zelidrag): Pop up sync setup UI here? |
1163 LOG(WARNING) << "Failed fetching OAuth request token, error: " | 1169 LOG(WARNING) << "Failed fetching OAuth request token, error: " |
1164 << error.state(); | 1170 << error.state(); |
1165 } | 1171 } |
1166 | 1172 |
1167 void LoginUtilsImpl::OnOAuthGetAccessTokenSuccess(const std::string& token, | 1173 void LoginUtilsImpl::OnOAuthGetAccessTokenSuccess(const std::string& token, |
1168 const std::string& secret) { | 1174 const std::string& secret) { |
1169 VLOG(1) << "Got OAuth v1 token!"; | 1175 VLOG(10) << "Got OAuth v1 token!"; |
1170 Profile* user_profile = ProfileManager::GetDefaultProfile(); | 1176 Profile* user_profile = ProfileManager::GetDefaultProfile(); |
1171 StoreOAuth1AccessToken(user_profile, token, secret); | 1177 StoreOAuth1AccessToken(user_profile, token, secret); |
1172 | 1178 |
1173 // Verify OAuth1 token by doing OAuthLogin and fetching credentials. | 1179 // Verify OAuth1 token by doing OAuthLogin and fetching credentials. |
1174 VerifyOAuth1AccessToken(user_profile, token, secret); | 1180 VerifyOAuth1AccessToken(user_profile, token, secret); |
1175 } | 1181 } |
1176 | 1182 |
1177 void LoginUtilsImpl::OnOAuthGetAccessTokenFailure( | 1183 void LoginUtilsImpl::OnOAuthGetAccessTokenFailure( |
1178 const GoogleServiceAuthError& error) { | 1184 const GoogleServiceAuthError& error) { |
1179 // TODO(zelidrag): Pop up sync setup UI here? | 1185 // TODO(zelidrag): Pop up sync setup UI here? |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1237 // Kick off verification of OAuth1 access token (via OAuthLogin), this should | 1243 // Kick off verification of OAuth1 access token (via OAuthLogin), this should |
1238 // let us fetch credentials that will be used to initialize sync engine. | 1244 // let us fetch credentials that will be used to initialize sync engine. |
1239 FetchCredentials(user_profile, token, secret); | 1245 FetchCredentials(user_profile, token, secret); |
1240 | 1246 |
1241 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), token, secret); | 1247 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), token, secret); |
1242 } | 1248 } |
1243 | 1249 |
1244 void LoginUtilsImpl::FetchCredentials(Profile* user_profile, | 1250 void LoginUtilsImpl::FetchCredentials(Profile* user_profile, |
1245 const std::string& token, | 1251 const std::string& token, |
1246 const std::string& secret) { | 1252 const std::string& secret) { |
1247 oauth_login_verifier_.reset(new OAuthLoginVerifier(user_profile, | 1253 oauth_login_verifier_.reset(new OAuthLoginVerifier(this, |
1254 user_profile, | |
1248 token, | 1255 token, |
1249 secret, | 1256 secret, |
1250 username_)); | 1257 username_)); |
1251 oauth_login_verifier_->Start(); | 1258 oauth_login_verifier_->StartOAuthVerification(); |
1252 } | 1259 } |
1253 | 1260 |
1254 | 1261 |
1255 void LoginUtilsImpl::FetchPolicyToken(Profile* offrecord_profile, | 1262 void LoginUtilsImpl::FetchPolicyToken(Profile* offrecord_profile, |
1256 const std::string& token, | 1263 const std::string& token, |
1257 const std::string& secret) { | 1264 const std::string& secret) { |
1258 // Fetch dm service token now, if it hasn't been fetched yet. | 1265 // Fetch dm service token now, if it hasn't been fetched yet. |
1259 if (!policy_oauth_fetcher_.get() || policy_oauth_fetcher_->failed()) { | 1266 if (!policy_oauth_fetcher_.get() || policy_oauth_fetcher_->failed()) { |
1260 // Trigger oauth token fetch for user policy. | 1267 // Trigger oauth token fetch for user policy. |
1261 policy_oauth_fetcher_.reset(new PolicyOAuthFetcher(offrecord_profile, | 1268 policy_oauth_fetcher_.reset(new PolicyOAuthFetcher(offrecord_profile, |
1262 token, | 1269 token, |
1263 secret)); | 1270 secret)); |
1264 policy_oauth_fetcher_->Start(); | 1271 policy_oauth_fetcher_->Start(); |
1265 } | 1272 } |
1266 | 1273 |
1267 // TODO(zelidrag): We should add initialization of other services somewhere | 1274 // TODO(zelidrag): We should add initialization of other services somewhere |
1268 // here as well. This could be handled with TokenService class once it is | 1275 // here as well. This could be handled with TokenService class once it is |
1269 // ready to handle OAuth tokens. | 1276 // ready to handle OAuth tokens. |
1270 | 1277 |
1271 // We don't need authenticator instance any more, reset it so that | 1278 // We don't need authenticator instance any more, reset it so that |
1272 // ScreenLocker would create a separate instance. | 1279 // ScreenLocker would create a separate instance. |
1273 // TODO(nkostylev): There's a potential race if SL would be created before | 1280 // TODO(nkostylev): There's a potential race if SL would be created before |
1274 // OAuth tokens are fetched. It would use incorrect Authenticator instance. | 1281 // OAuth tokens are fetched. It would use incorrect Authenticator instance. |
1275 authenticator_ = NULL; | 1282 authenticator_ = NULL; |
1276 } | 1283 } |
1277 | 1284 |
1285 void LoginUtilsImpl::OnOAuthVerificationFailed(const std::string& user_name) { | |
1286 UserManager::Get()->SaveUserOAuthStatus(user_name, | |
1287 User::OAUTH_TOKEN_STATUS_INVALID); | |
1288 } | |
1289 | |
1290 void LoginUtilsImpl::OnOAuthVerificationSucceeded( | |
1291 const std::string& user_name, const std::string& sid, | |
1292 const std::string& lsid, const std::string& auth) { | |
1293 // Kick off sync engine. | |
1294 GaiaAuthConsumer::ClientLoginResult credentials(sid, lsid, auth, | |
1295 std::string()); | |
xiyuan
2011/11/17 22:34:58
nit: align with args above
zel
2011/11/18 03:53:39
Done.
| |
1296 StartSync(ProfileManager::GetDefaultProfile(), credentials); | |
1297 } | |
1298 | |
1299 | |
1278 void LoginUtilsImpl::OnOnlineStateChanged(bool online) { | 1300 void LoginUtilsImpl::OnOnlineStateChanged(bool online) { |
1279 // If we come online for the first time after successful offline login, | 1301 // If we come online for the first time after successful offline login, |
1280 // we need to kick of OAuth token verification process again. | 1302 // we need to kick of OAuth token verification process again. |
1281 if (UserManager::Get()->user_is_logged_in() && | 1303 if (online && UserManager::Get()->user_is_logged_in() && |
1282 UserManager::Get()->offline_login() && online) { | 1304 oauth_login_verifier_.get() && |
1283 KickStartAuthentication(ProfileManager::GetDefaultProfile()); | 1305 !oauth_login_verifier_->is_done()) { |
1306 oauth_login_verifier_->ContinueVerification(); | |
xiyuan
2011/11/17 22:34:58
What if we already have a pending OAuthLogin reque
zel
2011/11/18 03:53:39
ContinueVerification will now check for pending re
| |
1284 } | 1307 } |
1285 } | 1308 } |
1286 | 1309 |
1287 LoginUtils* LoginUtils::Get() { | 1310 LoginUtils* LoginUtils::Get() { |
1288 return LoginUtilsWrapper::GetInstance()->get(); | 1311 return LoginUtilsWrapper::GetInstance()->get(); |
1289 } | 1312 } |
1290 | 1313 |
1291 void LoginUtils::Set(LoginUtils* mock) { | 1314 void LoginUtils::Set(LoginUtils* mock) { |
1292 LoginUtilsWrapper::GetInstance()->reset(mock); | 1315 LoginUtilsWrapper::GetInstance()->reset(mock); |
1293 } | 1316 } |
1294 | 1317 |
1295 void LoginUtils::DoBrowserLaunch(Profile* profile, | 1318 void LoginUtils::DoBrowserLaunch(Profile* profile, |
1296 LoginDisplayHost* login_host) { | 1319 LoginDisplayHost* login_host) { |
1297 if (browser_shutdown::IsTryingToQuit()) | 1320 if (browser_shutdown::IsTryingToQuit()) |
1298 return; | 1321 return; |
1299 | 1322 |
1300 BootTimesLoader::Get()->AddLoginTimeMarker("BrowserLaunched", false); | 1323 BootTimesLoader::Get()->AddLoginTimeMarker("BrowserLaunched", false); |
1301 | 1324 |
1302 VLOG(1) << "Launching browser..."; | 1325 VLOG(10) << "Launching browser..."; |
1303 BrowserInit browser_init; | 1326 BrowserInit browser_init; |
1304 int return_code; | 1327 int return_code; |
1305 BrowserInit::IsFirstRun first_run = FirstRun::IsChromeFirstRun() ? | 1328 BrowserInit::IsFirstRun first_run = FirstRun::IsChromeFirstRun() ? |
1306 BrowserInit::IS_FIRST_RUN: BrowserInit::IS_NOT_FIRST_RUN; | 1329 BrowserInit::IS_FIRST_RUN: BrowserInit::IS_NOT_FIRST_RUN; |
1307 browser_init.LaunchBrowser(*CommandLine::ForCurrentProcess(), | 1330 browser_init.LaunchBrowser(*CommandLine::ForCurrentProcess(), |
1308 profile, | 1331 profile, |
1309 FilePath(), | 1332 FilePath(), |
1310 BrowserInit::IS_PROCESS_STARTUP, | 1333 BrowserInit::IS_PROCESS_STARTUP, |
1311 first_run, | 1334 first_run, |
1312 &return_code); | 1335 &return_code); |
1313 | 1336 |
1314 // Mark login host for deletion after browser starts. This | 1337 // Mark login host for deletion after browser starts. This |
1315 // guarantees that the message loop will be referenced by the | 1338 // guarantees that the message loop will be referenced by the |
1316 // browser before it is dereferenced by the login host. | 1339 // browser before it is dereferenced by the login host. |
1317 if (login_host) { | 1340 if (login_host) { |
1318 login_host->OnSessionStart(); | 1341 login_host->OnSessionStart(); |
1319 login_host = NULL; | 1342 login_host = NULL; |
1320 } | 1343 } |
1321 } | 1344 } |
1322 | 1345 |
1323 } // namespace chromeos | 1346 } // namespace chromeos |
OLD | NEW |